Skip to content

armgit / sie

Public Imported from GitHub
0

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

fix(models): keep json_schema out of the prompt on the Gemma 4 31B screenshot profiles (#706)

svonava7ec754a90228
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 d9ac579f5..344739962 100644
--- a/packages/sie_server/models/google__gemma-4-31B-it.yaml
+++ b/packages/sie_server/models/google__gemma-4-31B-it.yaml
@@ -535,6 +535,20 @@ profiles:
# With 32 image requests in flight at 0.90, SGLang hit CUDA OOM in the vision
# path and failed requests; at 0.88 the same burst completed cleanly. The KV
# pool shrinks from about 107.9K to 103.4K tokens.
+ # ``schema_in_prompt: false`` keeps a ``json_schema`` response format out of
+ # the prompt on the two screenshot profiles. The grammar still constrains the
+ # answer, and a request that sends ``schema_in_prompt: true`` gets the
+ # section back. On the 25 fixed public-app screenshot fixtures, whose prompts
+ # do not contain their schema, both profiles scored 23/25 screens fully right
+ # with the section: FF12 ``transaction_type`` came back as the form's helper
+ # sentence and FF15 ``attachments`` as null. With this switch, on the same
+ # code and GPU, the 512-token profile scored 25/25. The Screenshot DEV24
+ # prompts contain their schema, so the section is never added there.
+ # Evidence: Hugging Face dataset ``superlinked/sie-task-evidence``, under
+ # ``evaluations/2026-10-11/screenshot-dev24-gemma4-serving-v1/results/``,
+ # ``amendment-5-fixtures25`` and ``amendment-6-fixtures25-noschema``.
+ # The runtime block restates ``h100-96k-hires`` in full because, like the
+ # load-time block, a profile's runtime block replaces its parent's.
h100-96k-hires-thinking-no-spec:
extends: h100-96k-hires
max_output_tokens: 32768
@@ -561,6 +575,18 @@ profiles:
- "--mm-process-config"
- '{"image":{"max_soft_tokens":1120}}'
- "--constrained-json-disable-any-whitespace"
+ 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>"
+ schema_in_prompt: false
# ``h100-96k-hires-thinking-no-spec`` with private reasoning capped at 512
# tokens: the adapter closes the thought channel there and the json_schema
# grammar then constrains the answer. The launch is otherwise identical, so
@@ -568,6 +594,7 @@ profiles:
# (two passes per run, default sampling) two 512-token runs scored 32/48
# complete records at 96.9% of fields and 30/48 at 96.1%, against 32/48 at
# 96.9% uncapped, with about 45% fewer output tokens per screen.
+ # It keeps the schema out of the prompt for the reason given on that profile.
h100-96k-hires-thinking-budget512-no-spec:
extends: h100-96k-hires
max_output_tokens: 32768
@@ -595,3 +622,15 @@ profiles:
- "--mm-process-config"
- '{"image":{"max_soft_tokens":1120}}'
- "--constrained-json-disable-any-whitespace"
+ 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>"
+ schema_in_prompt: false
diff --git a/packages/sie_server/tests/config/test_gemma_screenshot_profile.py b/packages/sie_server/tests/config/test_gemma_screenshot_profile.py
index 42ae3f853..f4d07fc5e 100644
--- a/packages/sie_server/tests/config/test_gemma_screenshot_profile.py
+++ b/packages/sie_server/tests/config/test_gemma_screenshot_profile.py
@@ -3,12 +3,18 @@ from __future__ import annotations
import json
from pathlib import Path
+import pytest
from sie_server.adapters._generation_base import thinking_blocks_must_be_hidden, thinking_mode_is_enabled
+from sie_server.config.model import ModelConfig
+from sie_server.core.grammar_routing import resolve_grammar_serving_model
from sie_server.core.loader import expand_profile_variants, load_model_config
+from sie_server.processors.schema_prompt import profile_schema_in_prompt
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"
+BUDGET_PROFILE = "h100-96k-hires-thinking-budget512-no-spec"
+SCREENSHOT_PROFILES = (PROFILE, BUDGET_PROFILE)
def test_hires_thinking_profile_preserves_the_non_speculative_document_launch() -> None:
@@ -23,7 +29,11 @@ def test_hires_thinking_profile_preserves_the_non_speculative_document_launch()
assert thinking_launch.pop("mem_fraction_static") == 0.88
assert answer_only_launch.pop("mem_fraction_static") == 0.85
assert thinking_launch == answer_only_launch
- assert thinking.runtime == answer_only.runtime
+ # The screenshot profile restates the document runtime block and adds one
+ # key: it keeps a json_schema response format out of the prompt.
+ thinking_runtime = dict(thinking.runtime)
+ assert thinking_runtime.pop("schema_in_prompt") is False
+ assert thinking_runtime == dict(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
@@ -63,9 +73,6 @@ def test_hires_thinking_variant_keeps_stock_sampling_and_the_bare_contract() ->
assert bare_generate.chat_template_kwargs == {"enable_thinking": False}
-BUDGET_PROFILE = "h100-96k-hires-thinking-budget512-no-spec"
-
-
def test_budget_profile_is_the_thinking_launch_with_a_512_token_reasoning_cap() -> None:
config = load_model_config(MODEL_FILE)
budget = config.resolve_profile(BUDGET_PROFILE)
@@ -90,3 +97,37 @@ def test_budget_variant_materializes_the_thinking_generation_contract() -> None:
assert budget.tasks.generate == thinking.tasks.generate
assert thinking_mode_is_enabled(budget)
assert thinking_blocks_must_be_hidden(budget)
+
+
+class _Served:
+ """The model lookup grammar routing needs, over the expanded catalog."""
+
+ def __init__(self, configs: dict[str, ModelConfig]) -> None:
+ self._configs = configs
+
+ def has_model(self, name: str) -> bool:
+ return name in self._configs
+
+ def get_config(self, name: str) -> ModelConfig:
+ return self._configs[name]
+
+
[email protected]("profile", SCREENSHOT_PROFILES)
+def test_screenshot_variants_keep_a_json_schema_out_of_the_prompt(profile: str) -> None:
+ configs = expand_profile_variants([load_model_config(MODEL_FILE)])
+ served = f"{MODEL_ID}:{profile}"
+
+ # A json_schema request stays on the profile it names, so the switch the
+ # worker reads is this profile's own.
+ assert resolve_grammar_serving_model(_Served(configs), served) == served
+ assert configs[served].resolve_profile("default").runtime["schema_in_prompt"] is False
+ assert not profile_schema_in_prompt(configs[served])
+
+
+def test_only_the_screenshot_profiles_turn_the_schema_section_off() -> None:
+ configs = expand_profile_variants([load_model_config(MODEL_FILE)])
+ off = {model_id for model_id, config in configs.items() if not profile_schema_in_prompt(config)}
+ assert off == {f"{MODEL_ID}:{profile}" for profile in SCREENSHOT_PROFILES}
+ # The answer-only document profiles and the bare model keep showing it.
+ assert profile_schema_in_prompt(configs[MODEL_ID])
+ assert profile_schema_in_prompt(configs[f"{MODEL_ID}:h100-96k-hires-no-spec"])
diff --git a/packages/sie_server/tests/processors/test_schema_prompt.py b/packages/sie_server/tests/processors/test_schema_prompt.py
index 58b6874b8..bcc6fba1b 100644
--- a/packages/sie_server/tests/processors/test_schema_prompt.py
+++ b/packages/sie_server/tests/processors/test_schema_prompt.py
@@ -3,11 +3,13 @@
from __future__ import annotations
import json
+from pathlib import Path
from types import MappingProxyType
from typing import Any
from unittest.mock import AsyncMock, MagicMock
import pytest
+from sie_server.core.loader import expand_profile_variants, load_model_config
from sie_server.processors import streaming as streaming_mod
from sie_server.processors.schema_prompt import (
json_schema_response_format,
@@ -39,6 +41,7 @@ SCHEMA: dict[str, Any] = {
"additionalProperties": False,
}
GRAMMAR = GrammarSpec(kind="json_schema", value=SCHEMA, label="cvss", strict=True)
+GEMMA_31B_FILE = Path(__file__).resolve().parents[2] / "models" / "google__gemma-4-31B-it.yaml"
_SECTION = response_format_section(GRAMMAR)
assert _SECTION is not None
SECTION: str = _SECTION
@@ -300,6 +303,27 @@ async def test_profile_opt_out_and_request_override(monkeypatch: pytest.MonkeyPa
assert _system_texts(tok) == ["Score the report.\n\n" + SECTION]
+ "profile",
+ ["h100-96k-hires-thinking-no-spec", "h100-96k-hires-thinking-budget512-no-spec"],
+)
+async def test_gemma_screenshot_profiles_opt_out_and_request_override(
+ monkeypatch: pytest.MonkeyPatch, profile: str
+) -> None:
+ """The served Gemma 4 31B screenshot profiles leave the prompt as sent unless the request asks for the schema."""
+ variant = expand_profile_variants([load_model_config(GEMMA_31B_FILE)])[f"google/gemma-4-31B-it:{profile}"]
+ runtime = dict(variant.resolve_profile("default").runtime)
+
+ tok, adapter, _ = await _run(monkeypatch, _request(), profile_runtime=runtime)
+ assert _system_texts(tok) == ["Score the report."]
+ assert adapter.dispatched_parameters is not None
+ assert adapter.dispatched_parameters["grammar"] == GRAMMAR
+
+ tok, _, _ = await _run(monkeypatch, _request(schema_in_prompt=True), profile_runtime=runtime)
+ assert _system_texts(tok) == ["Score the report.\n\n" + SECTION]
+
+
@pytest.mark.asyncio
async def test_schema_the_caller_already_sent_is_not_repeated(monkeypatch: pytest.MonkeyPatch) -> None:
system = "Score the report.\n\nJSON schema:\n" + json.dumps(SCHEMA, indent=2)