Skip to content

armgit / sie

Public Imported from GitHub
0

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

perf(models): compile compact, digit-bounded JSON grammars on the Gemma 4 31B hi-res profiles (#641)

svonavaa8eb93d9d7ee
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 287fef379..ddeaa784f 100644
--- a/packages/sie_server/models/google__gemma-4-31B-it.yaml
+++ b/packages/sie_server/models/google__gemma-4-31B-it.yaml
@@ -409,6 +409,15 @@ profiles:
# 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``.
+ # The hi-res family also compiles JSON-schema grammars without free
+ # whitespace (``--constrained-json-disable-any-whitespace``) and bounds each
+ # JSON number to 19 integer and 19 fractional digits
+ # (``json_number_max_digits``), as the Qwen3.8 and Qwen3.6-35B profiles do.
+ # With free whitespace a third of greedy page extractions carried newlines or
+ # stray spaces, and a speculative decode filled one reply's 8,192-token cap
+ # with whitespace. Compact replies stay valid under the same schema; on 222
+ # page extractions the score was unchanged within run-to-run noise while
+ # output tokens fell 9% and GPU-seconds per request up to 11%.
h100-96k-hires:
max_batch_tokens: 98304
compute_precision: bfloat16
@@ -422,6 +431,7 @@ profiles:
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
@@ -440,6 +450,7 @@ profiles:
- "fp8_e4m3"
- "--mm-process-config"
- '{"image":{"max_soft_tokens":1120}}'
+ - "--constrained-json-disable-any-whitespace"
runtime:
first_chunk_timeout_s: 900
inter_chunk_timeout_s: 30
@@ -460,6 +471,7 @@ profiles:
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
@@ -472,6 +484,7 @@ profiles:
- "fp8_e4m3"
- "--mm-process-config"
- '{"image":{"max_soft_tokens":1120}}'
+ - "--constrained-json-disable-any-whitespace"
# ``h100-96k-hires`` with a longer answer budget. The profile-level
# ``max_output_tokens`` raises the bare 4,096-token cap to 8,192, because
# extracting every row of a dense multi-column page can need more than 4,096
@@ -493,6 +506,7 @@ profiles:
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
@@ -505,3 +519,4 @@ profiles:
- "fp8_e4m3"
- "--mm-process-config"
- '{"image":{"max_soft_tokens":1120}}'
+ - "--constrained-json-disable-any-whitespace"
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
index 2027c4843..01dcbcd61 100644
--- a/packages/sie_server/tests/config/test_gemma4_31b_hires_profile.py
+++ b/packages/sie_server/tests/config/test_gemma4_31b_hires_profile.py
@@ -14,7 +14,17 @@ 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}}']
+_HIRES_ARGS = [
+ "--mm-process-config",
+ '{"image":{"max_soft_tokens":1120}}',
+ "--constrained-json-disable-any-whitespace",
+]
+_HIRES_PROFILES = (
+ "h100-96k-hires",
+ "h100-96k-hires-no-spec",
+ "h100-96k-hires-out8k",
+ "h100-96k-hires-out8k-no-spec",
+)
def _mm_process_config(extra_launch_args: list[str]) -> dict:
@@ -34,13 +44,17 @@ def test_hires_profiles_set_a_supported_image_budget_within_the_reservation() ->
assert budget + 2 <= _VISION_TOKENS_PER_IMAGE_ESTIMATE
-def test_hires_profiles_match_h100_96k_except_the_image_budget() -> None:
+def test_hires_profiles_match_h100_96k_except_the_image_budget_and_compact_json() -> 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 "json_number_max_digits" not in base.loadtime
+ assert hires.loadtime | {"extra_launch_args": None, "json_number_max_digits": None} == base.loadtime | {
+ "extra_launch_args": None,
+ "json_number_max_digits": None,
+ }
assert hires.runtime == base.runtime
assert hires.adapter_path == base.adapter_path
assert hires.compute_precision == base.compute_precision
@@ -120,3 +134,16 @@ def test_hires_out8k_grammar_requests_route_to_the_non_speculative_sibling() ->
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}
+
+
+def test_hires_profiles_compile_compact_bounded_json_grammars() -> None:
+ # With free whitespace, greedy page extractions carried newlines and stray
+ # spaces, and a speculative decode filled one reply's output cap with
+ # whitespace. Every hi-res launch, including each grammar twin, compiles
+ # compact JSON-schema grammars and bounds JSON number digits on xgrammar.
+ config = load_model_config(MODEL_FILE)
+ for name in _HIRES_PROFILES:
+ loadtime = config.resolve_profile(name).loadtime
+ assert loadtime["grammar_backend"] == "xgrammar", name
+ assert loadtime["json_number_max_digits"] == 19, name
+ assert loadtime["extra_launch_args"].count("--constrained-json-disable-any-whitespace") == 1, name