Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

feat(models): add a 1120 soft-token image profile for Gemma 4 31B on H100 (#633)

svonavad97dcf246174
diff --git a/packages/sie_server/models/google__gemma-4-31B-it.yaml b/packages/sie_server/models/google__gemma-4-31B-it.yaml
index 406cace8f..0b3f7d4ac 100644
--- a/packages/sie_server/models/google__gemma-4-31B-it.yaml
+++ b/packages/sie_server/models/google__gemma-4-31B-it.yaml
@@ -399,3 +399,76 @@ profiles:
min_new_tokens: 1
stop_tokens:
- "<end_of_turn>"
+ # Document-reading variant of ``h100-96k``: the same H100 launch with a
+ # larger per-image vision budget. SGLang passes ``--mm-process-config``
+ # ``image`` entries to the Hugging Face processor as ``images_kwargs``, and
+ # the Gemma 4 image processor accepts ``max_soft_tokens`` in
+ # {70, 140, 280, 560, 1120}. The checkpoint default of 280 encodes a dense
+ # full-page scan in about 260 visual tokens; 1120, the largest supported
+ # budget, reads it at roughly twice the linear resolution. 1120 stays below
+ # the worker's 1,280-token per-image reservation, so admission is unchanged.
+ # Answer-only (``enable_thinking: false``) with the bare 4,096-token output
+ # cap, like ``h100-96k``.
+ h100-96k-hires:
+ max_batch_tokens: 98304
+ compute_precision: bfloat16
+ adapter_path: sie_server.adapters.sglang.gemma:SGLangGemmaAdapter
+ grammar_profile: h100-96k-hires-no-spec
+ kv_budget_tokens: 98304
+ 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
+ reasoning_parser: gemma4
+ tool_call_parser: gemma4
+ speculative_needs_extra_buffer: false
+ speculative:
+ enabled: true
+ algorithm: nextn
+ num_steps: 3
+ eagle_topk: 1
+ num_draft_tokens: 4
+ draft_model: google/gemma-4-31B-it-assistant
+ draft_model_revision: 627c5ec1458b9086b841a91e0512fd31fd2fbbf1
+ extra_launch_args:
+ - "--quantization"
+ - "fp8"
+ - "--kv-cache-dtype"
+ - "fp8_e4m3"
+ - "--mm-process-config"
+ - '{"image":{"max_soft_tokens":1120}}'
+ runtime:
+ first_chunk_timeout_s: 900
+ inter_chunk_timeout_s: 30
+ overall_timeout_s: 1800
+ default_sampling:
+ temperature: 1.0
+ top_p: 0.95
+ top_k: 64
+ min_new_tokens: 1
+ stop_tokens:
+ - "<end_of_turn>"
+ h100-96k-hires-no-spec:
+ extends: h100-96k-hires
+ 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
+ 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}}'
diff --git a/packages/sie_server/tests/config/test_gemma4_31b_hires_profile.py b/packages/sie_server/tests/config/test_gemma4_31b_hires_profile.py
new file mode 100644
index 000000000..ba43c8151
--- /dev/null
+++ b/packages/sie_server/tests/config/test_gemma4_31b_hires_profile.py
@@ -0,0 +1,74 @@
+"""Gemma 4 31B document-reading profiles: ``h100-96k`` with a 1,120 soft-token image budget."""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+
+from sie_server.core.loader import expand_profile_variants, load_model_config
+from sie_server.processors.streaming import _VISION_TOKENS_PER_IMAGE_ESTIMATE
+
+MODELS_DIR = Path(__file__).resolve().parents[2] / "models"
+MODEL_FILE = MODELS_DIR / "google__gemma-4-31B-it.yaml"
+MODEL_ID = "google/gemma-4-31B-it"
+
+# Budgets accepted by the Gemma 4 image processor's ``max_soft_tokens``.
+_GEMMA4_SUPPORTED_SOFT_TOKENS = (70, 140, 280, 560, 1120)
+_HIRES_ARGS = ["--mm-process-config", '{"image":{"max_soft_tokens":1120}}']
+
+
+def _mm_process_config(extra_launch_args: list[str]) -> dict:
+ index = extra_launch_args.index("--mm-process-config")
+ return json.loads(extra_launch_args[index + 1])
+
+
+def test_hires_profiles_set_a_supported_image_budget_within_the_reservation() -> None:
+ config = load_model_config(MODEL_FILE)
+ for name in ("h100-96k-hires", "h100-96k-hires-no-spec"):
+ mm_config = _mm_process_config(config.resolve_profile(name).loadtime["extra_launch_args"])
+ assert mm_config == {"image": {"max_soft_tokens": 1120}}
+ budget = mm_config["image"]["max_soft_tokens"]
+ assert budget in _GEMMA4_SUPPORTED_SOFT_TOKENS
+ # Two boundary tokens wrap the soft tokens; the worker reserves at least
+ # the family-wide estimate per image, so admission needs no change.
+ assert budget + 2 <= _VISION_TOKENS_PER_IMAGE_ESTIMATE
+
+
+def test_hires_profiles_match_h100_96k_except_the_image_budget() -> None:
+ config = load_model_config(MODEL_FILE)
+ for hires_name, base_name in (("h100-96k-hires", "h100-96k"), ("h100-96k-hires-no-spec", "h100-96k-no-spec")):
+ hires = config.resolve_profile(hires_name)
+ base = config.resolve_profile(base_name)
+ assert hires.loadtime["extra_launch_args"] == [*base.loadtime["extra_launch_args"], *_HIRES_ARGS]
+ assert hires.loadtime | {"extra_launch_args": None} == base.loadtime | {"extra_launch_args": None}
+ assert hires.runtime == base.runtime
+ assert hires.adapter_path == base.adapter_path
+ assert hires.compute_precision == base.compute_precision
+ assert hires.max_batch_tokens == base.max_batch_tokens == 98304
+ assert hires.kv_budget_tokens == base.kv_budget_tokens == 98304
+ assert hires.chat_template_kwargs == base.chat_template_kwargs
+
+
+def test_hires_profiles_keep_answer_only_contract_and_output_cap() -> None:
+ configs = expand_profile_variants([load_model_config(MODEL_FILE)])
+ for suffix in ("h100-96k-hires", "h100-96k-hires-no-spec"):
+ config = configs[f"{MODEL_ID}:{suffix}"]
+ generate = config.tasks.generate
+ assert generate is not None
+ assert generate.max_output_tokens == 4096
+ assert generate.context_length == 98304
+ assert config.max_sequence_length == 98304
+ effective_mode = config.resolve_profile("default").chat_template_kwargs or generate.chat_template_kwargs
+ assert effective_mode == {"enable_thinking": False}
+ assert configs[f"{MODEL_ID}:h100-96k-hires"].tasks.generate == configs[f"{MODEL_ID}:h100-96k"].tasks.generate
+
+
+def test_hires_grammar_requests_route_to_the_non_speculative_sibling() -> None:
+ config = load_model_config(MODEL_FILE)
+ source = config.resolve_profile("h100-96k-hires")
+ fallback = config.resolve_profile("h100-96k-hires-no-spec")
+ assert source.grammar_profile == "h100-96k-hires-no-spec"
+ assert fallback.grammar_profile is None
+ assert source.loadtime["speculative"] == config.resolve_profile("h100-96k").loadtime["speculative"]
+ assert fallback.loadtime["speculative"] == {"enabled": False}
+ assert source.loadtime | {"speculative": None} == fallback.loadtime | {"speculative": None}