Skip to content

Nemotron CUDA: decode-sized router, topk and add_moe_norm keep their loads in flight, the same bits - #833

Merged
ashhart merged 2 commits into
ashhart:mainfrom
jschmied:nemotron-route-glue
Oct 16, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
jschmied:nemotron-route-glue

Conversation

@jschmied

@jschmied jschmied commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Nemotron's router, topk and add_moe_norm on CUDA keep their loads in flight at decode sizes, and every sum keeps its order, so all outputs are byte-equal to main. This addresses the part of #627 agreed there: one-row decode on GB10 was 0.35 ms a step behind the captured Triton glue, mostly on the MoE side chain that the main stream waits for.

  • tf_nemo_router_rows (nemotron_route.cu) runs decode windows of 16 rows or fewer. A block of 16 experts and one K slice stages its rows with every 16-byte load issued at once. Thread (row, expert) then runs tf_nemo_router's fma chain from shared memory, loading the next pair ahead of each step. Prompt chunks keep tf_nemo_router.
  • tf_nemo_topk loads every slice partial and bias before its sums. routerShape's slice count is now checked against the kernel's 8.
  • tf_nemo_add_moe_norm loads and adds a row on 1,024 threads, every load in flight. Its first 256 threads sum the squares in row_ss's order: the same chains, butterflies and warp order.

Receipt

  • Environment: main at 1e76a70e, plus this commit. One DGX Spark (GB10, sm_121, CUDA 13). TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit (MLX 4-bit).
  • Exactness:
    • tensorfold run reply shas equal main's for code and prose prompts (36 and 38 tokens, 256 greedy tokens), plain and drafted, in every round. Prompts of 2,048 and 8,192 tokens also give the same shas.
    • Teacher-forced over 512 tokens of real text, one token at a time (the decode path), all 512 logit rows and tokens are byte-identical to main.
    • tf-cuda-test glue: 1,245 of 1,245 comparisons byte-equal, several streams at once included.
  • Mutations:
    • Swapping the low and high halves in the router's chain fails glue.
    • Perturbing topk's slice sum fails glue.
    • Reversing add_moe_norm's square-sum chain passed glue as it was. With uniform inputs the order almost never shows after the square root and the division, even at 2 × 4,096 rows. The second commit adds 2,048 rows of log-uniform magnitudes (2^-8 to 2^8), where it shows. The mutation now fails glue at 10 stored outputs and 10 group sums, and the test passes on main's kernels and on this branch. The teacher-forced check also catches it, at 508 of 512 rows.
  • Decode speed before and after: tensorfold run, ms a token, median of 3 interleaved rounds. "Triton" is main with --kernels set to 1.0.2's captured sm121 glue, for reference.
main this PR Triton
code, --no-drafts 9.544 9.293 −2.6 % 9.218
prose, --no-drafts 9.544 9.376 −1.8 % 9.229
code, drafted 5.623 5.589 −0.6 % 5.641
prose, drafted 6.806 6.695 −1.6 % 6.647

In every cell, every round of this PR is faster than every round of main. The engine's measured round costs at 1/2/4/8/16 rows go from 9.18/11.78/15.38/21.40/30.46 ms to 8.99/11.51/15.16/21.23/30.35 ms.

Per launch, from nsys with --cuda-graph-trace=node:

kernel main this PR Triton
router (one row) 16.4 µs 9.0 µs 7.2 µs
topk 7.0 µs 4.3 µs 3.1 µs
add_moe_norm 8.9 µs 5.5 µs 3.7 µs

The main stream's wait on the side chain drops from 1,489 to 730 µs a step (Triton: 561).

  • Prompt speed: cold prefill of 2,048 tokens takes 0.2708 s on main and 0.2704 s here; 8,192 tokens take 1.0406 s and 1.0418 s, a median of 3 each.
  • Tests run:
    • zig build test-cuda-host: 27 of 27 steps, 451 of 451 tests.
    • zig build test passes.
    • tf-cuda-test glue and norm-rows pass.
    • zig fmt --check is clean, and lean_check.py reports 527 findings, as on main.
  • Not run:
    • Metal: unchanged.
    • Other CUDA cards: this is a GB10 measurement only.
    • tools/bench_openai.py through the server: tensorfold run drives the same lane rounds.

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 bits change.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (None change.)
  • Prompt processing is no slower than the last release.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (The new glue case fails on a reordered sum of squares and passes on main's kernels and on this branch.)
  • 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.

…loads in flight, the same bits

The router's decode windows (16 rows or fewer) run tf_nemo_router_rows: a block of 16 experts and one K slice
stages its rows with every 16-byte load issued at once, then thread (row, expert) runs tf_nemo_router's fma
chain from shared memory, the next pair's loads ahead of each step. tf_nemo_topk loads every slice and bias
before its sums. tf_nemo_add_moe_norm takes a row's loads and adds on 1024 threads, and its first 256 sum the
squares in row_ss's order. Every sum keeps its order: tf-cuda-test glue stays byte-equal to the host references.
…gnitudes too, where the sum of squares' order shows in the stored outputs
@ashhart
ashhart merged commit 1d4736a into ashhart:main Oct 16, 2026
4 checks passed
ashhart added a commit that referenced this pull request Oct 16, 2026
ashhart added a commit that referenced this pull request Oct 16, 2026
Recall (off unless asked for), model discovery's reasoning efforts (#819), the NVFP4 prompt entries' skip (#764) and Nemotron's CUDA decode router, top-k and add_moe_norm (#833), gated on the candidate before Living Weights' key, snapshot and rollback. Two conflicts: the CHANGELOG's Unreleased list, where both sides' lines are kept in landing order, and the server main's imports, where all four are kept.
ashhart added a commit that referenced this pull request Oct 16, 2026
#833's top-k loads every slice and bias before it sums them, and nvcc now gives it 95 registers on sm_86 and sm_89
and 91 on sm_120 and sm_121, where the record kept 63, 59, 58 and 58 from before that change. On a GB10
`tf-cuda-test kernel-contract` failed its live limit check on this launch alone (91 registers loaded, 58 recorded),
and `kernel-contract-limits` called the record stale on all four SMs. The new values are the ones it printed from
fatbins built for all four; 32 threads at 95 registers fit every SM.
@ashhart

ashhart commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Thank you, @jschmied. Closing most of the gap to the captured Triton glue while keeping every byte is the change we want.

Both commits ship in TensorFold 1.0.12 under your name (db7364e63, 37b106d81), and your head is merged after them with no change to the tree, so this pull request shows as merged. Ours follow: 15b62974c wraps the new lines (the sm_121 fatbins stay byte for byte yours), 7283603b5 tests the router at 1 to 16 rows beside the 300-row chunk and add_moe_norm at one row, and 52e87d433 starts a 4-row window 4 bytes into its buffer, which must keep tf_nemo_router.

On a GB10 the router with top-k and add_moe_norm matched the host references at every row count from 1 to 64 and at 17 more up to 4,096. tf-cuda-test glue passes 1,293 of 1,293. Drafted equals "draft": false in all 17 cells with the same token SHAs on MLX 4-bit and NVFP4, chats equal the cache-off server's, and 2, 4 and 8 streams equal solo.

On the same window-cost table one stream decodes about 0.9% faster drafted and 1.5% faster with "draft": false; shared rounds and cold prompts of 2k to 64k stayed within 1%.

Posted by Ash's AI Assistant Synthena

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 two commits landed above with the same code; 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
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…date

Recall (off unless asked for), model discovery's reasoning efforts (ashhart#819), the NVFP4 prompt entries' skip (ashhart#764) and Nemotron's CUDA decode router, top-k and add_moe_norm (ashhart#833), gated on the candidate before Living Weights' key, snapshot and rollback. Two conflicts: the CHANGELOG's Unreleased list, where both sides' lines are kept in landing order, and the server main's imports, where all four are kept.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
ashhart#833's top-k loads every slice and bias before it sums them, and nvcc now gives it 95 registers on sm_86 and sm_89
and 91 on sm_120 and sm_121, where the record kept 63, 59, 58 and 58 from before that change. On a GB10
`tf-cuda-test kernel-contract` failed its live limit check on this launch alone (91 registers loaded, 58 recorded),
and `kernel-contract-limits` called the record stale on all four SMs. The new values are the ones it printed from
fatbins built for all four; 32 threads at 95 registers fit every SM.
@jschmied
jschmied deleted the nemotron-route-glue branch October 23, 2026 21:02
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