Skip to content

Nemotron CUDA: decode glue keeps its loads in flight, same values and order - #771

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

ashhart merged 2 commits into
ashhart:mainfrom
plotarmordev:perf/nemotron-decode-latency

Conversation

@plotarmordev

@plotarmordev plotarmordev commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Nemotron on CUDA keeps more of each decode step's loads in flight, with the same values and the same order of every sum:

  • tf_nemo_add_moe_norm loads a row's slot weights and values before summing them. It used to load one slot at a time inside the sum, so 18.3 µs became 7.8 µs on a 5-row window.
  • tf_nemo_scan loads every step's B, C, x, gate and dt into shared memory before its serial steps (24.4 → 17.9 µs).
  • A window of two or more rows runs tf_nemo_attn_chunk_pf, which loads its next key tile into registers while it computes this one: -7% to -12% at 112k tokens of context. A single row keeps tf_nemo_attn_chunk, where prefetching gained nothing.
  • cuda_glue.zig guards the kernels' bounds (8 slots, 16-row windows).

Receipt

  • Environment: DGX Spark (GB10), Nemotron 3.5 Lightning MLX-4bit @ d9d758fb, on 1.0.8 (0efbd447), 400-token replies.

  • Exactness: tf-cuda-test glue 100/100 byte-equal to the host references. Its attention cases at 16, 16, 3 and 2 rows run the new kernel. Replies have the same token_sha as 1.0.8 at 1 and 8 streams and at 56k and 112k tokens of context.

  • Speed:

    1.0.8 this change
    one stream, makespan (8 trials) 2.276 s 2.239 s -1.6%, separated
    8 streams 11.171 s 11.232 s +0.6%, overlapping
    56k context, decode (two prompts) 119.8 / 135.2 tok/s 122.7 / 139.4 +2.5% / +3.1%, separated
    112k context, decode 94.3 / 102.6 tok/s 98.9 / 107.7 +4.8% / +5.0%, separated

    On 1.0.7, two sessions gave one stream -2.1% and -2.0%, 56k +2.9 to +3.3%, 112k +4.5 to +5.3%. The Grill's one-stream cell ran -1.21%, separated, with its A2 control at -0.10%; that control stopped at 5 of 8 acquisitions.

  • 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). Note: this and Nemotron CUDA: a shared round's per-stream conv, scan and attention run as one launch each #770 both append to nemotron_attention.cu, so whichever lands second takes a trivial merge.

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. (Same values, same order of every sum.)
  • 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. (The existing glue tests cover the changed kernels.)
  • 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.

…es and order

tf_nemo_add_moe_norm loads a row's slot weights and values before summing them; tf_nemo_scan loads every
step's B, C, x, gate and dt into shared memory before its serial steps; an attention window of several rows
runs tf_nemo_attn_chunk_pf, which loads its next key tile into registers while it computes the current one.
Every sum keeps its order: tf-cuda-test glue stays byte-equal to the host references.
@ashhart

ashhart commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Thank you, @plotarmordev. Keeping the loads in flight while every sum keeps its order is the kind of win that's easy to trust, and it shows up on a lone stream, where most people decode. It landed in 1.0.9 under your name (37da3ce81), with the same code as your merge with 1.0.8. #770 appends to the same attention file, so your prefetching kernel lands after its _segs kernels. Your head is merged after it with no change to the tree (bf74e12c2), so GitHub shows this PR as merged.

What we measured on a GB10 (sm_121), MLX 4-bit, base and tip four servers each in a mirrored order:

  • Exact. tf-cuda-test glue passes. Drafted == "draft": false in all 17 release cells with the same token SHAs as the base, on our kernels, the captured set and NVFP4. Every reply was equal across the eight timing servers.
  • One stream. 1.9-2.4% faster over eight prompts, greedy and sampled, on a shared window-cost table and on each build's own (greedy 156.8 -> 160.5 tok/s). The qual cells were 1.1-3.5% faster. The tip's fresh table also prices every window width 1.4-3.5% lower. In the 1.0.9 release gate on a GB10, one stream decoded 1.7 to 2.3% faster than 1.0.8 on MLX 4-bit and 0.6 to 4.5% on NVFP4, with 1.0.8's tokens.
  • Prefill. Cold prompts of 2k to 64k tokens were within 0.7% of the base.

One addition on our side: after your change, a one-row window was the only user of tf_nemo_attn_chunk, and no glue case ran one row. The glue test now does, against the host reference and against the shared-window kernels (6214804a9). We didn't re-run your long-context decode cells; your 56k and 112k numbers are in the CHANGELOG line.

@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, its attention kernel appended after ashhart#770's; 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