Skip to content

Nemotron CUDA: a shared round's MTP heads draft every stream in one batch - #768

Merged
ashhart merged 2 commits into
ashhart:mainfrom
plotarmordev:perf/nemotron-batched-heads
Oct 13, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
plotarmordev:perf/nemotron-batched-heads

Conversation

@plotarmordev

Copy link
Copy Markdown
Contributor

What this changes

Nemotron on CUDA drafts every stream of a shared round in one batch: each MTP head level runs one forward with a row per stream still drafting, where each stream's head ran its levels one row at a time. A lone drafting stream keeps its captured levels.

  • cuda_mtp.zig: Head.chains. Each stream does attention over its own head caches and its own meta row; the dense layers, experts and draft head are shared. forward and sample take spans and explicit buffers, and the one-stream path issues the same calls as before.
  • cuda_lanes.zig: draftFn batches two or more drafting streams, and facts() sets draft_streams.

Receipt

  • Environment: DGX Spark (GB10), Nemotron 3.5 Lightning MLX-4bit @ d9d758fb, on 1.0.8 (0efbd447), --context 16384 --parallel 8, 400-token replies, a distinct prompt per stream.

  • Exactness: a check build ran each round's drafts both ways (one stream at a time, then batched) and compared the device outputs. Over 2,472 rounds and 25,051 draft levels, greedy and sampled at t=0.7, 0 draft ids and 0 confidences differed. Replies have the same token_sha as 1.0.8 at 2, 4 and 8 streams, greedy, and at 2 and 8 streams sampled with a seed.

  • Speed, makespan over 8 trials an arm:

    streams 1.0.8 this change
    2 4.101 s 3.954 s -3.6%, separated
    4 6.405 s 5.927 s -7.5%, separated
    8 11.196 s 10.392 s -7.2%, separated
    2, t=0.7 3.994 s 3.740 s -6.3%, separated
    8, t=0.7 11.381 s 10.631 s -6.6%

    On 1.0.7 the same gave -5.0%, -7.3% and -10.5%. On The Grill's concurrency ladder (1.0.7) the 4-stream cell ran -16.3%, separated, with its A2 control flat. Its ladder sends one prompt to every lane, so its 2- and 8-stream medians are mixtures of lanes in step and lanes out of step. Per mode, 8 streams ran -12% and -10%. A lone stream is unchanged.

  • 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 one problem fewer than 1.0.8.

  • Not run, and why: Metal (unchanged). GLM, the other draft_streams family, has its own head and is untouched. There is no permanent GPU test for batched against one-at-a-time drafts: the check build was diagnostic, and the repo's GPU tests do not open a model with an MTP head on a shared round.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. (Drafts equal to the bit; replies unchanged.)
  • Prompt processing is no slower than the last release.
  • The description says which platforms I ran: CUDA GB10 only.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (No new permanent test; see above.)
  • 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.

Each head level runs one forward with a row per stream still drafting (Head.chains), where each stream's
head ran its levels one row at a time; a lone drafting stream keeps its captured levels. Drafts and
confidences equal the one-at-a-time ones to the bit, greedy and sampled.
@ashhart
ashhart merged commit ccf2110 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
The contributor's pricing commit landed above with the same code, on top of ashhart#768's; this keeps the PR's head, which also holds ashhart#768's, in the history with no change to the tree.
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. Drafting a shared round's streams in one head batch is the largest multi-stream win in this set, and it holds up exactly. It landed in 1.0.9 under your name (aeaaa6385). One line differs from your change: #720 made the head's prompt buffers 4,096 rows, so the batched meta rows now start after 128 + state.pass_rows words of the pinned buffer rather than prefill_rows. Your head is merged after it with no change to the tree (ccf2110f0), so GitHub shows this PR as merged.

One gate failed, and the fix is in our commit after yours (c3a39ab8b). With a captured Triton set, every concurrent drafted request failed with MissingTritonVariant once a stream in a batched round had more than one kept row. In that case the head's tail norm ran one launch per stream, and stream k's group sums started k x 168 bytes into their buffer. For odd k that isn't 16-aligned, and the captured _add_rmsnorm only has a 16-aligned variant. Our kernels take any alignment, which is why your receipts and our own-kernel runs passed. Now each stream's last row is copied up to row k and one launch normalizes the streams' rows from aligned bases. A lone stream launches exactly as before. The norm works row by row, so the rows and the drafts are the same bits.

What we measured on a GB10 (sm_121):

  • Exact. Drafted == "draft": false in all 17 release cells and the same token SHAs as the build without it, on MLX 4-bit (our kernels and the captured set) and NVFP4. Concurrent == solo at 2, 4 and 8 streams, greedy and sampled, on all three, with the fix.
  • Your bit-for-bit claim, on the merged tree. A trace build drafted every batched stream again alone, from the same head position, and compared the two. Across 4,300 batched rounds and 34,460 levels (our kernels, the captured set and NVFP4), no draft id or confidence differed.
  • Speed. With lanes: a shared round prices drafts by their head steps, a batched head by the deepest stream's #769, Nemotron CUDA: a shared round's per-stream conv, scan and attention run as one launch each #770 and Nemotron CUDA: decode glue keeps its loads in flight, same values and order #771 on top (MLX 4-bit, 256-token replies, distinct prompts, four servers a build in a mirrored order, on shared and on each build's own window-cost tables), aggregate decode rose 4.4-5.5% at 2 streams, 9.4-11.6% at 4 and 11.8-14.7% at 8 (8 streams greedy: 223.5 -> 249.8 tok/s), and every stream equalled its solo reply. We didn't split that between the four PRs. In the 1.0.9 release gate on a GB10 (1.0.9 against 1.0.8, A B B A, 256-token replies, distinct prompts), aggregate decode was 3.5 to 6.0% higher at 2 streams, 10.2 to 10.8% at 4 and 15.1 to 16.0% at 8 on MLX 4-bit, and 11.4 to 14.3% at 8 on NVFP4, every stream equal to its solo reply.

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
…date

The contributor's commit landed above, its pinned head buffer sized from the candidate's 4,096-row prompt passes; 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
The contributor's pricing commit landed above with the same code, on top of ashhart#768's; this keeps the PR's head, which also holds ashhart#768's, in the history with no change to the tree.
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
…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