Skip to content

nemotron cuda: every stream's MTP and target draws in a fixed number of launches - #3124

Merged
ashhart merged 7 commits into
mainfrom
lead/nemotron-cuda-batched-draws
Nov 14, 2026
Merged

ashhart merged 7 commits into
mainfrom
lead/nemotron-cuda-batched-draws

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Fixes #2910.

With several streams on CUDA, Nemotron 3.5 drew each stream's MTP draft tokens and the target's tokens with launches a stream at a time (about 112 draw-side launches a level at 8 greedy streams). When every live part shares a draw mode and head, all rows of a level now draw in a fixed number of launches: greedy as one convert, one top-k and one lookup over all rows; sampled as one launch that calls the same per-row draw with that row's rule, seed and position. One scatter writes each row's token and probability back, and the target's draws get the same treatment with one download. Mixed modes, the captured Triton set and grammar masks keep today's path. Each row's draw is the same function with the same inputs, so tokens are unchanged.

Review fixes on top of the original patch: the pinned rules and positions now upload before the "uploads done" event (the next window could overwrite them first), each stream's offset lives in its own array instead of a meta row's spare word written after that row's upload was queued, the batch is built only for several streams, a mode mismatch errors instead of reading an unwritten slab, and the device test checks before it prints PASS.

Tests: test-nemotron-draw-host 15/15 (with batching forced off: "expected 15, found 112"); full test-cuda-host passes; compile-cuda-tests passes for aarch64 and x86_64; the first commit builds alone.

Device check pending (GB10): tf-cuda-test nemotron-draws with 0 diffs and tf-cuda-test glue passing; kernel-contract-limits to fill the 4 pending records; served bench_concurrent.py --levels 1,2,4,8 --alone --serial, chat and code at temperature 0 and 1, every equal_alone true; A/B base-new-new-base.

@ashhart

ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

GB10 results on this head: the served A/B (Nemotron 3.5, pp, sweep and chat, temperatures 0 and 1) has every token hash equal to main, with speed level (8 streams +0.2% to +1.7%, 2 streams within noise). tf-cuda-test glue passes 1473/1473. tf-cuda-test nemotron-draws passes four of its checks (72 batched rows equal the per-row draw, 36 greedy, 36 target and 36 argmax rows equal), then fails one: "1 row kernels differ". We're finding out what that check compares and why one row differs before this lands.

  • Synthena (Ash's Agent)

@ashhart
ashhart force-pushed the lead/nemotron-cuda-batched-draws branch from 209228e to 988a341 Compare November 14, 2026 03:31
@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

CUDA kernel contract on a GB10 (sm_121 device contract, plus launch limits at sm_80/86/89/120/121), main against this branch: clean. The only line not in main's output is the summary count, which grows because this PR registers the new launches (1569 registered, the same 178 limit problems as main). No new FAIL line in the contract, and none in the limits. It's in the landing queue.

  • Synthena (Ash's Agent)

Head.chains drew each stream's draft a level at a time: a greedy level took
fourteen launches a stream, and a sampled one took a draw a stream. When every
live part shares a draw mode and head, the level now runs as one pass over all
its rows: greedy as one toF32, one topk, one lookup and one keyed draw, sampled
as one tf_draw_ids_rows launch with each row's rule and position. One scatter
writes every row's token and probability back to its stream.

The level's rows come in through one gather, and a level's tokens through one
copy of the previous level's slab; the tail's last rows move down in one ordered
gather. attentionSegs takes the spans in chunks of eight. Mixed modes, one part
and the Triton captured set keep today's per-stream path.

The new kernels are recorded as pending until a GPU measures their register usage.

Refs #2910.
A shared window drew each stream's target token a stream at a time and
downloaded each one. With every stream in the same mode, the rows now draw in
one pass: one argmax over all rows, or one tf_draw_rows launch with each row's
rule and position, then one scatter to each sequence's sampled buffer and one
download of the slab. Grammar masks still run a stream at a time before the
draw. Mixed modes and a single window keep today's path.

The batch is built only for several streams and refused when their modes
differ; each row carries its own rule and position, so a multi-row stream's
rows do not share one rule. Its rules and positions go up with the window's
other pinned words, before the event that lets the next window rewrite them,
and each part's place in the drawn-token slab is kept on the engine rather than
in the meta row the kernels read. The forward refuses a batch whose mode does
not match its streams' instead of reading an unwritten slab.

A device case (tf-cuda-test nemotron-draws) runs the batched draws, the
target's rows draw and argmax, and the row kernels against the per-row path,
byte for byte.

Refs #2910.
…e gather

rowKernels' last check read dst_a[1] for the scattered token, but the
scatter it set up writes the token at tok_at = 2 (prob_at = 1, as the
engine's level j writes j and j - 1, cuda_mtp.zig:415-416), so word 1
still held the last-row gather's ha[17] and one check failed: "1 row
kernels differ". The kernels are right; the check now compares both
destinations whole against the expected rows, the token at tok_at and
the probability at prob_at.

The gather's output was never read: the last-row gather overwrote both
rows before the download. The test now reads it after the gather and
checks part k's row at dst row k.
… the full kernel contract (sm_80/86/89/120/121)
@ashhart
ashhart force-pushed the lead/nemotron-cuda-batched-draws branch from 988a341 to 89c7a2b Compare November 14, 2026 14:20
@ashhart
ashhart merged commit e54bd72 into main Nov 14, 2026
2 of 10 checks passed
@ashhart
ashhart deleted the lead/nemotron-cuda-batched-draws branch November 14, 2026 14:20
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.

nemotron CUDA: draw every stream's draft and target tokens in a fixed number of launches

1 participant