Repository navigation
gemma4 cuda: structured output (grammar masks in first_masked and verify) - #1386
Conversation
|
Thanks @ThomasHalwax, and thanks for checking it with drafts on and off and under four streams. We read it through: One small point: Next we'll run it on a GB10 with the 31B: |
|
Thanks. On the greedy structured cell, a pre-measurement on one GB10 (31B 4-bit, Google's assistant, production flags, one stream, 12-item
Undrafted, the host pick costs nothing measurable. Drafted, greedy and sampled under the grammar decode at the same rate, so the gap to the unconstrained reply comes with the grammar and its different text, not from the logits read back. |
Sampled rows under a grammar get their disallowed tokens at -inf through sample.cu's tf_grammar_mask before the draw. Greedy rows are picked on the host among their allowed tokens by the argmax kernel's rule (first largest, a non-finite logit is an error), because tf_round_bf16_argmax reports a masked -inf as non-finite. verify checks the masks' lengths before the forward. Host test for the pick.
94c4f7b to
746c2a7
Compare
|
Thank you @ThomasHalwax. This is in TensorFold 1.2.0, released today: https://github.com/ashhart/TensorFold/releases/tag/v1.2.0 It landed with your commits under your own name, so you're listed as a TensorFold contributor, and it's credited to you in the release notes and the changelog. |
Fixes #1384.
first_maskedin the Gemma 4 CUDA backend's vtable;verifytakes the window's masks and checks their lengths before the forward.-infwithsample.cu's existingtf_grammar_maskbefore the draw (no new kernel).tf_round_bf16_argmax's rule (first largest; a non-finite logit is an error), because that kernel reports a masked-infas non-finite. Unit test for the pick (pickAllowed).Receipts (same machine and checkpoint as #1385, with the 31B assistant):
json_schema(nested object, enum, array),json_object,tool_choice: "required"and"auto", each at temperature 0 and 0.3: 8/8 valid. Without drafter 8/8 and identical to drafted. 4 concurrent copies 8/8 each and identical to solo.--hardmode --trials 3: score 84 → 88 (146/174 → 154/176); TC-45 (tool_choice: required) is now scored instead of excluded.json_schemawith thinking on: the grammar applies after the thinking part.40c6406b: all of the above identical (structured 8/8 equal, prose 16/16 equal, 4 concurrent 16/16 equal solo).Host:
test-gemma4-cuda-host30/30,test-cuda-hostas onmain, lean check adds no findings. Independent of PR A (applies alone onmain); measured together with it.Changelog suggestion: Gemma 4 on CUDA serves structured output:
response_format(json_schema,json_object) andtool_choice: "required"or a named function (#1384). Greedy rows pick among the grammar's tokens on the host; drafted, undrafted and concurrent replies are identical.