Skip to content

perf(nemotron cuda): the lone driver takes structured output - #779

Merged
ashhart merged 6 commits into
ashhart:mainfrom
plotarmordev:perf/nemotron-lone-structured
Oct 13, 2026
Merged

ashhart merged 6 commits into
ashhart:mainfrom
plotarmordev:perf/nemotron-lone-structured

Conversation

@plotarmordev

@plotarmordev plotarmordev commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

On top of #778 (its commits come first here; this pull request adds the last one). Nemotron CUDA's lone driver takes a lone structured-output request (response_format, or tool_choice required). A grammar stream opens with its masked first draw. Each round, Constraint.window keeps the planned chain's rows the grammar allows and grows it with the grammar's own drafts, as windows.constrain does for a lone stream. The window is then verified masked with Engine.verifyMasked, so replies are unchanged.

  • cuda_drafts.zig: Rounds.verify takes a Gate: the chain as host ids, cut and grown, its rows masked.
  • cuda_lone.zig: the masked opening, and the gate over the stream's grammar; Cuda.putBits is public.
  • engine_api.zig Lone.structures, lane_host_lone.zig fits, native/cuda.zig.

Receipt

  • Environment: DGX Spark (GB10), Nemotron 3.5 Lightning MLX-4bit @ d9d758fb, on 1.0.8 (0efbd447), --context 16384 --parallel 4. Every server start measured its own window-cost table (a fresh cache), arms alternated. libtfgrammar built by zig build grammar from xgrammar v0.2.8.

  • Exactness: json_object, json_schema, a strict enum schema, a required tool call, a schema with thinking on and a seeded temperature: 0.8 schema reply have the same token_sha as 1.0.8 (3 each, 2 starts). 20 pairs of mixed structured, sampled and free requests, the second arriving 0, 0.3, 0.9 or 1.6 s later, all match. Drafted output equals "draft": false for each structured kind.

  • Speed, medians over 2 starts:

    request 1.0.8 this change
    free JSON, 500 tokens 2.94 s 2.93 s
    json_object, same tokens 3.23 s 2.96 s -8.3%
    json_schema, same tokens 3.25 s 2.83 s -12.9%
    strict schema, 68 tokens 0.587 s 0.531 s -9.5%
    required tool call, 68 tokens 0.355 s 0.303 s -14.6%
    schema with thinking, 900 tokens 5.85-5.93 s 5.27 s -10%
    seeded sampled schema, 500 tokens 3.13-3.16 s 2.81 s -10.5%

    The schema reply now beats the free one through the grammar's own drafts.

  • Tests run: zig build test 616/621 (5 skipped); test-cuda-host 25/25 steps; server tests 155/155 and 96/96; goldens 309/319 with 0 unexpected differences; zig fmt; lean_check as on 1.0.8.

  • Not run, and why: Metal (unchanged). The NVFP4 checkpoint and RTX cards (no hardware here). logprobs with response_format is refused on 1.0.8 as here. Requests gated by CallGate (engines without structures) stay in the lane rounds.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (The lone driver is main's existing path for a lone drafted stream; this widens which requests take it. Arrivals still hand the stream to the lane rounds as before.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. (Same kernels and draws; only which loop drives the stream changes.)
  • Prompt processing is no slower than the last release. (The prompt pass is unchanged.)
  • The description says which platforms I ran: CUDA GB10 only.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (No new test: the masks come from the grammar tests' Constraint.window, and the masked window needs a GPU.)

It commits each round's kept rows as the lane core's windows read them (logprobRows on the window's logits)
and opens the stream with the prompt's last row, so a lone logprobs request decodes on the lone driver's
graphs and confidence depth rule.
…guards

A stream with a budget past the driver's minimum or a loop guard decodes on the lone driver until a loop
guard's close is pending or the budget's cut falls within the next round, then goes to the lane core, which
forces the close as before.
A grammar stream opens with its masked first draw; each round the grammar keeps the planned chain's rows it
allows, adds its own drafts after them and masks every row (Constraint.window, as windows.constrain does for a
lone stream), and the window is verified masked.
@ashhart
ashhart merged commit e44dee3 into ashhart:main Oct 13, 2026
2 checks passed
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
…date

The contributor's two commits landed above, on top of ashhart#779's. On the candidate a shared round's heads draft in one batch (ashhart#768), so the kept rows are recorded after the one-stream h.chain as in the PR and for a batched head in our commit after it; and only a lone driver that resumes a stream is given one back, in another of ours, since the Mac's drivers open every stream they are given. This keeps the PR's head in the history with no change to the tree.
@ashhart

ashhart commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Thank you, @plotarmordev. Running the grammar the lane core already runs, through the same Constraint.window and masked verify, is the clean way to bring structured output onto the lone driver. It landed in 1.0.9 under your name (280a12f65) with the same code. Your head is merged after it with no change to the tree (e44dee39c), so GitHub shows this PR as merged.

What we measured on a GB10 (sm_121), against the build without it:

  • Exact. A JSON object, two JSON schemas, a regex, a choice, and required and named tool calls, greedy and seeded sampled: every reply valid, drafted == "draft": false, and equal token for token to the lane core's, on MLX 4-bit (our kernels and the captured set) and NVFP4. We also ran a schema and a required tool call after thinking with a 300-token budget, the budget and the grammar in one request, and those matched too.
  • Speed. Four servers a build in a mirrored order, MLX 4-bit: a 370-token json_object reply finished 4% to 7% sooner and a required tool call (35 tokens) 15% sooner. In the 1.0.9 release gate, the structured-output suite's 26 cases were valid and drafted equal to "draft": false, with its three refusals, on a GB10 (MLX 4-bit and NVFP4), an M5 Max and an M3 Ultra.

@ashhart ashhart mentioned this pull request Oct 14, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The contributor's commit landed above with the same code, on top of ashhart#778's; this keeps the PR's head in the history with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…date

The contributor's two commits landed above, on top of ashhart#779's. On the candidate a shared round's heads draft in one batch (ashhart#768), so the kept rows are recorded after the one-stream h.chain as in the PR and for a batched head in our commit after it; and only a lone driver that resumes a stream is given one back, in another of ours, since the Mac's drivers open every stream they are given. This keeps the PR's head in the history with no change to the tree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants