Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
feat: add high-resolution Gemma thinking profile (#677)
svonavae619232d4594
diff --git a/packages/sie_gateway/src/state/model_registry.rs b/packages/sie_gateway/src/state/model_registry.rsindex 47f1ec790..15384547f 100644--- a/packages/sie_gateway/src/state/model_registry.rs+++ b/packages/sie_gateway/src/state/model_registry.rs@@ -1352,6 +1352,8 @@ impl ModelRegistry {/// that preserves its context/hardware/thinking launch shape while/// disabling speculation. A compatible default profile, or a safe variant/// that directly inherits the model-wide grammar profile, remains selected.+ /// A non-speculative derivative compatible with its parent's declared+ /// grammar-safe sibling also keeps its own launch and generation settings.////// The routing target is resolved off the request's *base* model, so the/// rewrite applies to incompatible defaults and explicit variants:@@ -1430,6 +1432,17 @@ impl ModelRegistry {if let Some(scoped) = scoped {return Some((base.to_string(), scoped));}+ let parent_grammar_profile = base_entry+ .info_extras+ .profile_parents+ .get(source_profile)+ .and_then(|parent| base_entry.profile_configs.get(parent))+ .and_then(|parent| parent.grammar_profile.as_deref());+ if parent_grammar_profile.is_some_and(|parent_grammar_profile| {+ Self::profile_is_grammar_compatible(base_entry, source_profile, parent_grammar_profile)+ }) {+ return Some((base.to_string(), source_profile.to_string()));+ }let gp = base_entry.info_extras.grammar_profile.clone()?;let target_profile = if base_entry.info_extras@@ -3782,6 +3795,233 @@ mod tests {);}+ #[test]+ fn test_gemma_catalog_grammar_routes_preserve_existing_profiles_and_thinking() {+ let (_dir, registry) = gemma_grammar_fixture(gemma_grammar_config());+ for (profile, serving) in [+ ("", "no-spec"),+ ("no-spec", "no-spec"),+ ("h100-fp8", "no-spec"),+ ("thinking", "h100-96k-thinking-no-spec"),+ ("long-context", "long-context-no-spec"),+ ("long-context-no-spec", "long-context-no-spec"),+ ("long-context-thinking", "long-context-thinking-no-spec"),+ (+ "long-context-thinking-no-spec",+ "long-context-thinking-no-spec",+ ),+ ("h200-256k", "long-context-no-spec"),+ ("h200-256k-thinking", "long-context-thinking-no-spec"),+ ("h100-96k", "h100-96k-no-spec"),+ ("h100-96k-no-spec", "h100-96k-no-spec"),+ ("h100-96k-thinking", "h100-96k-thinking-no-spec"),+ ("h100-96k-thinking-no-spec", "h100-96k-thinking-no-spec"),+ ("h100-96k-hires", "h100-96k-hires-no-spec"),+ ("h100-96k-hires-no-spec", "h100-96k-hires-no-spec"),+ ("h100-96k-hires-out8k", "h100-96k-hires-out8k-no-spec"),+ (+ "h100-96k-hires-out8k-no-spec",+ "h100-96k-hires-out8k-no-spec",+ ),+ (+ "h100-96k-hires-thinking-no-spec",+ "h100-96k-hires-thinking-no-spec",+ ),+ ] {+ let requested = if profile.is_empty() {+ "google/gemma-4-31B-it".to_string()+ } else {+ format!("google/gemma-4-31B-it:{profile}")+ };+ let expected = if profile == serving {+ GrammarRoute::Keep+ } else {+ GrammarRoute::Rewrite(format!("google/gemma-4-31B-it:{serving}"))+ };+ assert_eq!(+ registry.grammar_route_variant(&requested),+ expected,+ "{profile}"+ );+ }+ let thinking = registry+ .get_model_info("google/gemma-4-31B-it:h100-96k-hires-thinking-no-spec")+ .unwrap();+ assert_eq!(thinking.effective_max_output_tokens(), Some(32768));+ assert_eq!(thinking.info_extras.max_sequence_length, Some(98304));+ assert_eq!(+ thinking.profile_configs["default"].chat_template_kwargs,+ Some(serde_json::json!({"enable_thinking": true}))+ );+ assert_eq!(+ registry.grammar_route_variant("GOOGLE/GEMMA-4-31B-IT:H100-96K-HIRES-THINKING-NO-SPEC"),+ GrammarRoute::Keep+ );+ }++ fn gemma_grammar_config() -> ModelConfig {+ serde_yaml::from_str(include_str!(+ "../../../sie_server/models/google__gemma-4-31B-it.yaml"+ ))+ .unwrap()+ }++ fn gemma_grammar_fixture(config: ModelConfig) -> (TempDir, ModelRegistry) {+ let (dir, bundles_dir, models_dir) = create_test_dirs();+ fs::write(+ bundles_dir.join("default.yaml"),+ "name: default\npriority: 10\nadapters:\n - sie_server.adapters.sglang.gemma\n - sie_server.adapters.fake.adapter\n",+ )+ .unwrap();+ let registry = ModelRegistry::new(&bundles_dir, &models_dir, true);+ registry.add_model_config(config).unwrap();+ (dir, registry)+ }++ fn remove_grammar_model(registry: &ModelRegistry, model: &str) {+ let mut snapshot = (*registry.snapshot.load_full()).clone();+ snapshot.models.remove(model);+ snapshot.model_names_lower.remove(&model.to_lowercase());+ registry.snapshot.store(Arc::new(snapshot));+ }++ #[test]+ fn test_gemma_hires_thinking_keeps_its_route_without_served_siblings_or_base() {+ let (_dir, registry) = gemma_grammar_fixture(gemma_grammar_config());+ let requested = "google/gemma-4-31B-it:h100-96k-hires-thinking-no-spec";+ for model in registry.list_models() {+ if model != "google/gemma-4-31B-it" && model != requested {+ remove_grammar_model(®istry, &model);+ }+ }+ assert_eq!(+ registry.grammar_route_variant(requested),+ GrammarRoute::Keep+ );+ remove_grammar_model(®istry, "google/gemma-4-31B-it");+ assert_eq!(+ registry.grammar_route_variant(requested),+ GrammarRoute::Keep+ );+ }++ #[test]+ fn test_parent_grammar_hint_rejects_incompatible_gemma_children() {+ let config = gemma_grammar_config();+ let profile_name = "h100-96k-hires-thinking-no-spec";+ let profile = config.profiles[profile_name].clone();+ let mut cases = Vec::new();+ let mut different_adapter = profile.clone();+ different_adapter.adapter_path =+ Some("sie_server.adapters.fake.adapter:FakeAdapter".to_string());+ cases.push(("adapter-mismatch", different_adapter));+ for (name, field, value) in [+ (+ "backend-mismatch",+ "grammar_backend",+ serde_json::json!("outlines"),+ ),+ (+ "speculation-enabled",+ "speculative",+ serde_json::json!({"enabled": true}),+ ),+ (+ "speculation-malformed",+ "speculative",+ serde_json::json!({"enabled": "false"}),+ ),+ ("speculation-absent", "speculative", serde_json::Value::Null),+ ] {+ let mut profile = profile.clone();+ let loadtime = profile.adapter_options.as_mut().unwrap()["loadtime"]+ .as_object_mut()+ .unwrap();+ if value.is_null() {+ loadtime.remove(field);+ } else {+ loadtime.insert(field.to_string(), value);+ }+ cases.push((name, profile));+ }+ for (name, args) in [+ (+ "raw-speculation",+ serde_json::json!(["--speculative-algo", "NEXTN"]),+ ),+ (+ "raw-speculation-equals",+ serde_json::json!(["--speculative-algo=NEXTN"]),+ ),+ (+ "raw-eagle",+ serde_json::json!(["--enable-multi-layer-eagle"]),+ ),+ (+ "raw-config",+ serde_json::json!(["--config", "overrides.json"]),+ ),+ (+ "raw-backend",+ serde_json::json!(["--grammar-backend", "outlines"]),+ ),+ (+ "extra-launch-mismatch",+ serde_json::json!(["--log-level", "debug"]),+ ),+ ] {+ let mut profile = profile.clone();+ profile.adapter_options.as_mut().unwrap()["loadtime"]["extra_launch_args"]+ .as_array_mut()+ .unwrap()+ .extend(args.as_array().unwrap().iter().cloned());+ cases.push((name, profile));+ }+ for (name, profile) in cases {+ let mut config = config.clone();+ config.profiles.insert(profile_name.to_string(), profile);+ let (_dir, registry) = gemma_grammar_fixture(config);+ let requested = format!("google/gemma-4-31B-it:{profile_name}");+ assert_eq!(+ registry.grammar_route_variant(&requested),+ GrammarRoute::Rewrite("google/gemma-4-31B-it:no-spec".to_string()),+ "{name}"+ );+ remove_grammar_model(®istry, "google/gemma-4-31B-it:no-spec");+ assert_eq!(+ registry.grammar_route_variant(&requested),+ GrammarRoute::MissingVariant("no-spec".to_string()),+ "{name}: missing fallback"+ );+ }+ }++ #[test]+ fn test_explicit_gemma_child_grammar_fallback_precedes_parent_hint() {+ let mut config = gemma_grammar_config();+ let profile_name = "h100-96k-hires-thinking-no-spec";+ let fallback_name = "hires-thinking-scoped-safe";+ let fallback = config.profiles[profile_name].clone();+ config.profiles.insert(fallback_name.to_string(), fallback);+ config+ .profiles+ .get_mut(profile_name)+ .unwrap()+ .grammar_profile = Some(fallback_name.to_string());+ let (_dir, registry) = gemma_grammar_fixture(config);+ let requested = format!("google/gemma-4-31B-it:{profile_name}");+ let fallback = format!("google/gemma-4-31B-it:{fallback_name}");+ assert_eq!(+ registry.grammar_route_variant(&requested),+ GrammarRoute::Rewrite(fallback.clone())+ );+ remove_grammar_model(®istry, &fallback);+ assert_eq!(+ registry.grammar_route_variant(&requested),+ GrammarRoute::MissingVariant(fallback_name.to_string())+ );+ }+#[test]fn test_grammar_route_variant_default_profile() {let config: ModelConfig = serde_yaml::from_str(diff --git a/packages/sie_server/models/google__gemma-4-31B-it.yaml b/packages/sie_server/models/google__gemma-4-31B-it.yamlindex ddeaa784f..1d9e73c18 100644--- a/packages/sie_server/models/google__gemma-4-31B-it.yaml+++ b/packages/sie_server/models/google__gemma-4-31B-it.yaml@@ -520,3 +520,31 @@ profiles:- "--mm-process-config"- '{"image":{"max_soft_tokens":1120}}'- "--constrained-json-disable-any-whitespace"+ # Repeat the full non-speculative launch because load-time overrides+ # replace the parent's block rather than merging it.+ h100-96k-hires-thinking-no-spec:+ extends: h100-96k-hires+ max_output_tokens: 32768+ chat_template_kwargs:+ enable_thinking: true+ adapter_options:+ loadtime:+ max_seq_length: 98304+ mem_fraction_static: 0.90+ served_model_name: google/gemma-4-31B-it+ attention_backend: triton+ grammar_backend: xgrammar+ json_number_max_digits: 19+ reasoning_parser: gemma4+ tool_call_parser: gemma4+ speculative_needs_extra_buffer: false+ speculative:+ enabled: false+ extra_launch_args:+ - "--quantization"+ - "fp8"+ - "--kv-cache-dtype"+ - "fp8_e4m3"+ - "--mm-process-config"+ - '{"image":{"max_soft_tokens":1120}}'+ - "--constrained-json-disable-any-whitespace"diff --git a/packages/sie_server/src/sie_server/core/grammar_routing.py b/packages/sie_server/src/sie_server/core/grammar_routing.pyindex e2087b1b8..56b199719 100644--- a/packages/sie_server/src/sie_server/core/grammar_routing.py+++ b/packages/sie_server/src/sie_server/core/grammar_routing.py@@ -15,6 +15,8 @@ The rules mirror the gateway's ``ModelRegistry::grammar_route_variant``:- a request that names the grammar-safe variant keeps its id;- a variant that directly extends the grammar profile and is grammarcompatible keeps its id;+- a non-speculative variant compatible with its parent's declared grammar+ profile keeps its id;- otherwise the request moves to ``{base}:{grammar_profile}``, and fails with``unsupported_field`` when that variant is not served."""@@ -92,6 +94,12 @@ def _grammar_target(registry: ModelConfigSource, model_id: str) -> tuple[str, streturn Noneif source_config.grammar_profile is not None:return base_id, source_config.grammar_profile+ parent = profiles.get(source_config.extends)+ parent_grammar_profile = None if parent is None else parent.grammar_profile+ if parent_grammar_profile is not None and _profile_is_grammar_compatible(+ base, source_profile, parent_grammar_profile+ ):+ return base_id, source_profilegrammar_profile = _model_grammar_profile(base)if grammar_profile is None:return Nonediff --git a/packages/sie_server/tests/config/test_gemma_screenshot_profile.py b/packages/sie_server/tests/config/test_gemma_screenshot_profile.pynew file mode 100644index 000000000..d0eeb30c9--- /dev/null+++ b/packages/sie_server/tests/config/test_gemma_screenshot_profile.py@@ -0,0 +1,57 @@+from __future__ import annotations++import json+from pathlib import Path++from sie_server.adapters._generation_base import thinking_blocks_must_be_hidden, thinking_mode_is_enabled+from sie_server.core.loader import expand_profile_variants, load_model_config++MODEL_FILE = Path(__file__).resolve().parents[2] / "models" / "google__gemma-4-31B-it.yaml"+MODEL_ID = "google/gemma-4-31B-it"+PROFILE = "h100-96k-hires-thinking-no-spec"+++def test_hires_thinking_profile_preserves_the_non_speculative_document_launch() -> None:+ config = load_model_config(MODEL_FILE)+ thinking = config.resolve_profile(PROFILE)+ answer_only = config.resolve_profile("h100-96k-hires-no-spec")++ assert thinking.loadtime == answer_only.loadtime+ assert thinking.runtime == answer_only.runtime+ assert thinking.adapter_path == answer_only.adapter_path+ assert thinking.compute_precision == answer_only.compute_precision == "bfloat16"+ assert thinking.max_batch_tokens == thinking.kv_budget_tokens == 98304+ assert thinking.loadtime["speculative"] == {"enabled": False}+ assert thinking.loadtime["grammar_backend"] == "xgrammar"+ assert thinking.loadtime["json_number_max_digits"] == 19+ args = thinking.loadtime["extra_launch_args"]+ assert args[args.index("--quantization") + 1] == "fp8"+ assert args[args.index("--kv-cache-dtype") + 1] == "fp8_e4m3"+ assert json.loads(args[args.index("--mm-process-config") + 1]) == {"image": {"max_soft_tokens": 1120}}+ assert args.count("--constrained-json-disable-any-whitespace") == 1+++def test_hires_thinking_variant_materializes_the_full_generation_contract() -> None:+ configs = expand_profile_variants([load_model_config(MODEL_FILE)])+ variant = configs[f"{MODEL_ID}:{PROFILE}"]+ generate = variant.tasks.generate+ assert generate is not None++ assert variant.hf_revision == "842da3794eaa0b77d5f08bae87a17459d91ff475"+ assert variant.max_sequence_length == generate.context_length == 98304+ assert generate.max_output_tokens == 32768+ assert generate.chat_template_kwargs == {"enable_thinking": True}+ assert thinking_mode_is_enabled(variant)+ assert thinking_blocks_must_be_hidden(variant)+ assert variant.resolve_profile("default").chat_template_kwargs == {"enable_thinking": True}+++def test_hires_thinking_variant_keeps_stock_sampling_and_the_bare_contract() -> None:+ configs = expand_profile_variants([load_model_config(MODEL_FILE)])+ sampling = configs[f"{MODEL_ID}:{PROFILE}"].resolve_profile("default").runtime["default_sampling"]+ assert sampling == {"temperature": 1.0, "top_p": 0.95, "top_k": 64, "min_new_tokens": 1}+ bare_generate = configs[MODEL_ID].tasks.generate+ assert bare_generate is not None+ assert bare_generate.max_output_tokens == 4096+ assert bare_generate.context_length == 8192+ assert bare_generate.chat_template_kwargs == {"enable_thinking": False}diff --git a/packages/sie_server/tests/config/test_generation_mode_profiles.py b/packages/sie_server/tests/config/test_generation_mode_profiles.pyindex 9edb6e175..fce1dc7e7 100644--- a/packages/sie_server/tests/config/test_generation_mode_profiles.py+++ b/packages/sie_server/tests/config/test_generation_mode_profiles.py@@ -49,6 +49,7 @@ _HARDWARE_THINKING_PROFILES = {"h200-256k-thinking","long-context-thinking-no-spec","h100-96k-thinking-no-spec",+ "h100-96k-hires-thinking-no-spec",),}diff --git a/packages/sie_server/tests/core/test_grammar_routing.py b/packages/sie_server/tests/core/test_grammar_routing.pyindex 672819a7a..6b79dc7f1 100644--- a/packages/sie_server/tests/core/test_grammar_routing.py+++ b/packages/sie_server/tests/core/test_grammar_routing.py@@ -3,15 +3,21 @@from __future__ import annotationsimport shutil+from copy import deepcopyfrom pathlib import Path+from typing import Anyimport pytest+import yamlfrom sie_server.adapters._generation_base import GenerationUnsupportedFieldErrorfrom sie_server.core.grammar_routing import resolve_grammar_serving_modelfrom sie_server.core.registry import ModelRegistry_MODELS_DIR = Path(__file__).resolve().parents[2] / "models"_CATALOG = ("Qwen__Qwen3.5-4B.yaml", "Qwen__Qwen3.6-27B.yaml", "sie-fake.yaml")+_GEMMA_FILE = _MODELS_DIR / "google__gemma-4-31B-it.yaml"+_GEMMA_ID = "google/gemma-4-31B-it"+_GEMMA_THINKING = "h100-96k-hires-thinking-no-spec"def _registry(tmp_path: Path, model_filter: list[str] | None = None) -> ModelRegistry:@@ -20,6 +26,17 @@ def _registry(tmp_path: Path, model_filter: list[str] | None = None) -> ModelRegreturn ModelRegistry(models_dir=tmp_path, model_filter=model_filter, enable_hot_reload=False)+def _gemma_registry(+ tmp_path: Path, *, config: dict[str, Any] | None = None, model_filter: list[str] | None = None+) -> ModelRegistry:+ destination = tmp_path / _GEMMA_FILE.name+ if config is None:+ shutil.copy(_GEMMA_FILE, destination)+ else:+ destination.write_text(yaml.safe_dump(config), encoding="utf-8")+ return ModelRegistry(models_dir=tmp_path, model_filter=model_filter, enable_hot_reload=False)++@pytest.mark.parametrize(("requested", "serving"),[@@ -68,3 +85,113 @@ def test_speculative_variant_served_without_its_base_needs_its_grammar_profile(tassert (resolve_grammar_serving_model(both, "Qwen/Qwen3.6-27B:long-context") == "Qwen/Qwen3.6-27B:long-context-no-spec")+++ "model_filter",+ [None, [_GEMMA_ID, f"{_GEMMA_ID}:{_GEMMA_THINKING}"], [f"{_GEMMA_ID}:{_GEMMA_THINKING}"]],+)+def test_hires_thinking_grammar_requests_keep_the_requested_generation_contract(+ tmp_path: Path, model_filter: list[str] | None+) -> None:+ registry = _gemma_registry(tmp_path, model_filter=model_filter)+ requested = f"{_GEMMA_ID}:{_GEMMA_THINKING}"++ serving = resolve_grammar_serving_model(registry, requested)++ assert serving == requested+ generate = registry.get_config(serving).tasks.generate+ assert generate is not None+ assert generate.max_output_tokens == 32768+ assert generate.context_length == 98304+ assert generate.chat_template_kwargs == {"enable_thinking": True}+++def test_all_existing_gemma_grammar_routes_are_preserved(tmp_path: Path) -> None:+ registry = _gemma_registry(tmp_path)+ expected = {+ "": "no-spec",+ "no-spec": "no-spec",+ "h100-fp8": "no-spec",+ "thinking": "h100-96k-thinking-no-spec",+ "long-context": "long-context-no-spec",+ "long-context-no-spec": "long-context-no-spec",+ "long-context-thinking": "long-context-thinking-no-spec",+ "long-context-thinking-no-spec": "long-context-thinking-no-spec",+ "h200-256k": "long-context-no-spec",+ "h200-256k-thinking": "long-context-thinking-no-spec",+ "h100-96k": "h100-96k-no-spec",+ "h100-96k-no-spec": "h100-96k-no-spec",+ "h100-96k-thinking": "h100-96k-thinking-no-spec",+ "h100-96k-thinking-no-spec": "h100-96k-thinking-no-spec",+ "h100-96k-hires": "h100-96k-hires-no-spec",+ "h100-96k-hires-no-spec": "h100-96k-hires-no-spec",+ "h100-96k-hires-out8k": "h100-96k-hires-out8k-no-spec",+ "h100-96k-hires-out8k-no-spec": "h100-96k-hires-out8k-no-spec",+ }+ for profile, serving_profile in expected.items():+ requested = _GEMMA_ID if not profile else f"{_GEMMA_ID}:{profile}"+ assert resolve_grammar_serving_model(registry, requested) == f"{_GEMMA_ID}:{serving_profile}", profile++[email protected]("serve_fallback", [True, False])+ ("profile_updates", "loadtime_updates", "extra_args"),+ [+ ({"adapter_path": "sie_server.adapters.fake.adapter:FakeAdapter"}, {}, []),+ ({}, {"grammar_backend": "outlines"}, []),+ ({}, {"speculative": {"enabled": True}}, []),+ ({}, {"speculative": {"enabled": "false"}}, []),+ ({}, {"speculative": {}}, []),+ ({}, {}, ["--speculative-algo", "NEXTN"]),+ ({}, {}, ["--speculative-algo=NEXTN"]),+ ({}, {}, ["--enable-multi-layer-eagle"]),+ ({}, {}, ["--config", "overrides.json"]),+ ({}, {}, ["--grammar-backend", "outlines"]),+ ({}, {}, ["--log-level", "debug"]),+ ],+)+def test_parent_grammar_hint_does_not_admit_an_incompatible_child(+ tmp_path: Path,+ profile_updates: dict[str, Any],+ loadtime_updates: dict[str, Any],+ extra_args: list[str],+ serve_fallback: bool,+) -> None:+ config = yaml.safe_load(_GEMMA_FILE.read_text(encoding="utf-8"))+ profile = config["profiles"][_GEMMA_THINKING]+ profile.update(profile_updates)+ loadtime = profile["adapter_options"]["loadtime"]+ loadtime.update(loadtime_updates)+ loadtime["extra_launch_args"].extend(extra_args)+ requested = f"{_GEMMA_ID}:{_GEMMA_THINKING}"+ model_filter = [_GEMMA_ID, requested]+ if serve_fallback:+ model_filter.append(f"{_GEMMA_ID}:no-spec")+ registry = _gemma_registry(tmp_path, config=config, model_filter=model_filter)++ if serve_fallback:+ assert resolve_grammar_serving_model(registry, requested) == f"{_GEMMA_ID}:no-spec"+ else:+ with pytest.raises(GenerationUnsupportedFieldError, match="'no-spec'"):+ resolve_grammar_serving_model(registry, requested)++[email protected]("serve_fallback", [True, False])+def test_explicit_child_grammar_fallback_precedes_the_parent_hint(tmp_path: Path, serve_fallback: bool) -> None:+ config = yaml.safe_load(_GEMMA_FILE.read_text(encoding="utf-8"))+ profile = config["profiles"][_GEMMA_THINKING]+ fallback = "hires-thinking-scoped-safe"+ config["profiles"][fallback] = deepcopy(profile)+ profile["grammar_profile"] = fallback+ requested = f"{_GEMMA_ID}:{_GEMMA_THINKING}"+ model_filter = [_GEMMA_ID, requested]+ if serve_fallback:+ model_filter.append(f"{_GEMMA_ID}:{fallback}")+ registry = _gemma_registry(tmp_path, config=config, model_filter=model_filter)++ if serve_fallback:+ assert resolve_grammar_serving_model(registry, requested) == f"{_GEMMA_ID}:{fallback}"+ else:+ with pytest.raises(GenerationUnsupportedFieldError, match=f"'{fallback}'"):+ resolve_grammar_serving_model(registry, requested)