Repository navigation
Fail untyped TML model headers at EOS and align TMLv0 content-header and strict-tool grammars with TmlOutput - #457
Closed
brandonmmusic-max wants to merge 4 commits into
Conversation
…out a content kind Why: When a TMLv0 model emits a reasoning frame followed by <|message_model|> and non-empty header text (such as a tool name and partial arguments where <|content_invoke_tool_json|> was dropped) and then closes the frame on <|end_message|> or <|content_model_end_sampling|>, TmlOutput discarded the header text and returned Ok on Termination::Eos. Before this change, /v1/responses emitted response.output_item.done(reasoning) followed by response.completed(output=[reasoning]) with status completed and no error. What changed: - Add AnswerState (Empty, HeaderWithoutContent, Emitted) to TmlOutput in helios/src/output/tml.rs. - Record HeaderWithoutContent when a non-empty model header closes on <|end_message|> or <|content_model_end_sampling|> before any visible content or tool call has been emitted. - Mark answer as Emitted whenever non-thinking visible content or a non-empty tool invocation body is emitted. - Return an error from TmlOutput::finish() on Termination::Eos when answer is HeaderWithoutContent while preserving existing behavior for empty model headers, non-model role frames, external terminations, and turns that emit visible text or a tool call. - Add unit tests in helios/src/output/tml.rs and a real tokenizer snapshot regression test in helios/src/server/request/tml_tests.rs. Claimed result: Malformed TMLv0 turns whose non-empty model header closes without a content kind and without any visible output or tool call fail at EOS and surface response.failed on /v1/responses instead of completing with reasoning only. Supporting evidence: - output::tml::tests and server::request::tml_tests (with FLARE_INKLING2_TEST_SNAPSHOT) pass on upstream main ee49d85. - Limitation: non-model role frames (<|message_tool|>, <|message_user|>, <|message_system|>) remain ignored per tml-renderers semantics. Design-Signed-Off-By: Brandon M. Music; design-review=1af4 Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
…Lv0 grammars
Why:
Two mismatches existed between TmlOutput (helios/src/output/tml.rs) and
GrammarCompiler::compile_content_headers (helios/src/grammar.rs):
1. TmlOutput treats the tool name in a <|message_model|> header before
<|content_invoke_tool_json|> as optional, and Inkling 2 models natively
emit <|message_model|><|content_invoke_tool_json|> with no header name.
Before this change, compile_content_headers required self.marker(name)
before <|content_invoke_tool_json|>, masking out
<|content_invoke_tool_json|> after <|message_model|> and preventing
grammar-constrained runs from invoking tools natively.
2. Before this change, compile_content_headers compiled tool-enabled
envelopes as (answer | tools), rejecting a visible text preamble
followed by tool calls even though TmlOutput parses that sequence.
What changed:
- Add a factored tool_unnamed rule (<|content_invoke_tool_json|>
@payload_any <|end_message|>) using a single JSON schema enum over
registered tool names, avoiding N-way Earley ambiguity across large tool
sets while keeping named headers paired with matching @payload_i schemas.
- Change the tool-enabled ending from (answer | tools) to
(answer ({restart} thinking* tool)* | tools), matching XTML's
wrapped_answer (ws tool)* framing while keeping at most one @answer frame.
- Add content_headers_grammar_allows_preamble_before_tools in
helios/src/grammar.rs and inkling_stress_* snapshot regression tests in
helios/src/server/request/tml_tests.rs.
Claimed result:
TMLv0 grammar-constrained requests with declared tools accept unnamed and
named tool headers as well as a visible preamble frame followed by tool
calls, while still rejecting unregistered tools, mismatched header names,
invalid tool arguments, duplicate @answer frames, and reasoning-only
terminations.
Supporting evidence:
- grammar::tests, output::tml::tests, frontend::tml::tests, and all 8
FLARE_INKLING2_TEST_SNAPSHOT tests in server::request::tml_tests pass on
upstream main ee49d85.
- Live SM120 GPU verification against TML-d24-varloop-research with
grammar start: /(?s:.+)/ and 178 tools moved from 0/5 to 5/5 tool calls
and 6/6 preamble-plus-tool responses.
- Limitation: non-TMLv0 model families were verified through unit tests
only, not live GPU serving.
Design-Signed-Off-By: Brandon M. Music; design-review=1af4
Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
Why: PR NVIDIA#418 (0b09434) merged into main after NVIDIA#457 opened, adding strict function-tool wire grammars in helios/src/grammar/strict.rs including compile_strict_tml for TMLv0 models. What changed: - Merged NVIDIA/hyperflare-inference main (b9cac83) into tml-untyped-headers-and-content-grammar with no conflicts. Claimed result: The branch incorporates main (b9cac83) cleanly so compile_strict_tml can receive the same unnamed-header and preamble-before-tool alignment as compile_content_headers. Supporting evidence: - Clean automatic merge with zero conflicts; full Helios unit and Inkling 2 tokenizer snapshot suites run on the follow-up commit. - Limitation: non-TMLv0 model families are covered by unit tests only. Design-Signed-Off-By: Brandon M. Music; design-review=1af4 Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
…strict TMLv0 grammars Why: PR NVIDIA#418 (0b09434) added GrammarCompiler::compile_strict_tml in helios/src/grammar/strict.rs with the same two constraints stricter than TmlOutput that compile_content_headers had before this branch: 1. Each tool rule required self.marker(&tool.name) before <|content_invoke_tool_json|>, even though Inkling 2 natively emits unnamed <|message_model|><|content_invoke_tool_json|> tool headers and TmlOutput treats the header name as optional. 2. Non-required tool envelopes compiled as (answer | tools), rejecting a visible text preamble followed by tool calls even though TmlOutput parses that frame sequence directly. What changed: - Added a factored tool_unnamed rule (<|content_invoke_tool_json|> (@payload_0 | ... | @payload_k) <|end_message|>) in compile_strict_tml so unnamed tool headers validate against each active tool's strict or default wrapper schema while named headers keep per-tool pairing. - Updated the non-required ending in compile_strict_tml from (answer | tools) to (answer ({restart} thinking* tool)? | tools) when single_call is set and (answer ({restart} thinking* tool)* | tools) otherwise. - Added a TML_unnamed case to strict_tool_wire_grammars_enforce_constraints and a new strict_tml_grammar_allows_unnamed_headers_and_preamble_before_tools unit test covering multi-tool unnamed headers, schema and undeclared-tool rejection, named header mismatch rejection, and preamble-then-tool framing with both parallel and single_call limits. Claimed result: Strict function-tool requests ("strict": true) on TMLv0 models accept both unnamed and named tool headers as well as a visible text preamble followed by tool calls while enforcing each tool's strict JSON schema. Supporting evidence: - output::tml::tests, frontend::tml::tests, grammar::tests, grammar::strict::tests, server::protocol::tests, and server::output::tests pass (124 passed, 0 failed) and all 8 real Inkling 2 tokenizer snapshot tests in server::request::tml_tests pass on NVIDIA/hyperflare-inference main (b9cac83). - Live SM120 GPU verification on RTX PRO 6000 Blackwell with a strict get_weather function tool ("strict": true) returned HTTP 200 and a valid schema-conforming function_call on /v1/responses. - Limitation: non-TMLv0 strict tool families (Qwen, GLM, DSML) were verified through existing grammar::strict::tests only, not live GPU serving. Design-Signed-Off-By: Brandon M. Music; design-review=1af4 Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
Collaborator
|
A case file has been opened for 457 To opt out, include #autobot:ignore in the PR or any comment. |
Collaborator
Changes RequestedBlockers:
Should fix:
Nits:
To opt out of future reviews, put #autobot:ignore in your response. |
This was referenced Nov 29, 2026
helios: support thinking_token_budget for ContentHeaders and trim incomplete UTF-8 tails on cut
#615
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Two Helios TMLv0 handling defects affect Responses and Chat Completions serving with Inkling 2 models (introduced in #304 and hardened in #405, with strict function tools added in #418 and Inkling 2 Mini merged in #433):
<|message_model|>and non-empty header text (for example a tool name and partial JSON arguments where<|content_invoke_tool_json|>was dropped) and then closes with<|end_message|>or<|content_model_end_sampling|>,TmlOutput(helios/src/output/tml.rs) discarded the header text and returnedOkonTermination::Eos. Before this change,/v1/responsesemittedresponse.output_item.done(reasoning)followed byresponse.completed(output=[reasoning])withstatus: "completed"and no error, causing agent clients to treat a broken tool turn as a finished reply.TmlOutput. BothGrammarCompiler::compile_content_headers(helios/src/grammar.rs) andGrammarCompiler::compile_strict_tml(helios/src/grammar/strict.rs, added in Add strict function-tool schemas for DSML, Qwen, GLM and TML parsers #418) enforced two rules stricter thanTmlOutput:self.marker(name)before<|content_invoke_tool_json|>, even thoughTmlOutputtreats the header name as optional and Inkling 2 natively emits<|message_model|><|content_invoke_tool_json|>without a header name. Before this change, activating a custom grammar (such asstart: /(?s:.+)/alongside declared tools) or"strict": trueon a function tool masked out<|content_invoke_tool_json|>right after<|message_model|>, causing models either to print raw tool JSON inside<|content_text|>or to loop in thinking frames.(answer | tools), allowing text alone, tools alone, or tools followed by text, while rejecting a visible text preamble followed by tool calls even thoughTmlOutputparses that frame sequence directly.What Changed
helios/src/output/tml.rsandhelios/src/server/request/tml_tests.rs:AnswerState(Empty,HeaderWithoutContent,Emitted) toTmlOutput.HeaderWithoutContentwhen a non-empty model header (model && at > 0) closes on<|end_message|>or<|content_model_end_sampling|>whileanswer == Empty.answer = Emittedwhenever non-thinking visible content or a non-empty tool invocation body is emitted.TmlOutput::finish()onTermination::Eoswhenanswer == HeaderWithoutContent, preserving existing behavior for empty model headers, non-model role frames, external terminations (OutputLimit,UserStop,Cancelled,ExecutionError), and turns that emit visible text or a tool call before or after an untyped header.<|end_message|>and<|content_model_end_sampling|>closure and real Inkling 2 tokenizer snapshot regression tests replaying captured malformed header tokens throughDecoderandEncoder.helios/src/grammar.rsandhelios/src/server/request/tml_tests.rs:tool_unnamedrule (<|content_invoke_tool_json|> @payload_any <|end_message|>) backed by a single JSON schemaenumover registered tool names, avoiding N-way Earley ambiguity across large tool sets while keeping named headers (tool_{index}) paired with per-toolconstschemas.(answer | tools)to(answer ({restart} thinking* tool)* | tools), matching XTML'swrapped_answer (ws tool)*framing while keeping at most one@answerframe.content_headers_grammar_allows_preamble_before_toolsinhelios/src/grammar.rsandinkling_stress_untyped_closed_header_must_surface_failureandinkling_stress_custom_grammar_preamble_then_toolinhelios/src/server/request/tml_tests.rs.helios/src/grammar/strict.rs(after mergingmainb9cac839including Add strict function-tool schemas for DSML, Qwen, GLM and TML parsers #418):tool_unnamedrule (<|content_invoke_tool_json|> (@payload_0 | ... | @payload_k) <|end_message|>) incompile_strict_tmlso unnamed tool headers validate against each active tool's strict or default wrapper schema while named headers retain per-tool pairing.compile_strict_tmlfrom(answer | tools)to(answer ({restart} thinking* tool)? | tools)whensingle_callis set and(answer ({restart} thinking* tool)* | tools)otherwise.TML_unnamedcase tostrict_tool_wire_grammars_enforce_constraintsand addedstrict_tml_grammar_allows_unnamed_headers_and_preamble_before_toolscovering multi-tool unnamed headers, schema and undeclared-tool rejection, named header mismatch rejection, and preamble-then-tool framing with both parallel andsingle_calllimits.Claimed Result
response.failed(server_error) on/v1/responsesinstead of completing withoutput=[reasoning].compile_content_headersandcompile_strict_tmlfor"strict": truefunction tools) accept both unnamed and named tool headers as well as a visible text preamble followed by tool calls, while continuing to reject unregistered tools, mismatched header names, schema-violating or non-object tool arguments, duplicate@answerframes, and reasoning-only terminations.Supporting Evidence
NVIDIA/hyperflare-inferencemainatb9cac839.cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server):output::tml::tests::,frontend::tml::tests::,grammar::tests::,grammar::strict::tests::,server::protocol::tests::, andserver::output::tests::: 124 passed, 0 failed (includingcontent_headers_grammar_allows_preamble_before_tools,strict_tool_wire_grammars_enforce_constraintswithTML_unnamed,strict_tml_grammar_allows_unnamed_headers_and_preamble_before_tools, and both untyped-header EOS unit tests).FLARE_INKLING2_TEST_SNAPSHOT=... --ignored --test-threads=1 server::request::tml_tests::): 8 passed, 0 failed (includinga_model_frame_without_a_content_kind_reports_a_failed_response,inkling_stress_untyped_closed_header_must_surface_failure,inkling_stress_custom_grammar_preamble_then_tool,structured_output_grammars_constrain_frames, andoutputs_match_reference_parses).TML-d24-varloop-researchon RTX PRO 6000 Blackwell):tool_unnamedincompile_content_headers,/v1/chat/completionsand/v1/responseswith 178 declared tools andgrammar: "start: /(?s:.+)/"returned0/5tool calls (printing raw tool JSON as text or looping in thinking frames).tool_unnamedand preamble-then-tool support acrosscompile_content_headersandcompile_strict_tml,/v1/responseswithgrammar: "start: /(?s:.+)/"returns5/5tool calls on the 178-tool prompt and5/5tool calls (4/5['reasoning', 'message', 'function_call']) on preamble-plus-tool prompts,/v1/responseswith"strict": trueonget_weatherreturns HTTP 200 with a schema-conformingfunction_call, and multi-turn Chat/Responses tool round-trip suites (agentic_suite.py) passSUITE: PASS(3/3tool calls on every tool case,0failed trials,0server errors).Unrun Checks and Limitations
grammar::testsandgrammar::strict::testsonly, not live GPU serving.TmlOutputcontinues to ignore non-model role frames (<|message_tool|>,<|message_user|>,<|message_system|>) pertml-rendererssemantics.Attribution
madaron Local Inference Lab Discord) for the initial untyped TML model-header patch, the captured malformed terminal-header token sequence, and both TMLv0 stress regression tests (inkling_stress_untyped_closed_header_must_surface_failureandinkling_stress_custom_grammar_preamble_then_tool).Discord: no username provided