Skip to content

Nemotron CUDA: a shared round's per-stream conv, scan and attention run as one launch each - #770

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

ashhart merged 2 commits into
ashhart:mainfrom
plotarmordev:perf/nemotron-segs-glue

Conversation

@plotarmordev

@plotarmordev plotarmordev commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Nemotron on CUDA runs a shared round's per-stream steps for all its streams at once. Each Mamba layer's conv and scan, and each attention layer's key write, chunks and merge, take one launch for every stream instead of one per stream, with each stream on its own state, caches and position.

  • nemotron_mamba.cu, nemotron_attention.cu: tf_nemo_{conv,scan,kv_write,attn_chunk,attn_merge}_segs take every stream's pointers by value. They are copies of the one-stream kernels, which stay byte-identical. A first version that shared one body between them changed the one-stream kernels' code and slowed a lone stream by 1.6-1.9%.
  • cuda_glue.zig: mambaSegs and attentionSegs. A lone window, a Triton set, or more than 8 streams take the one-stream kernels as before.
  • cuda_forward.zig: windowRows calls them.
  • tf-cuda-test glue: two new cases, three streams at once against the host references (conv xc/raw/base, scan dt/state/y, key/value writes, attention out and xs).

Receipt

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

  • Exactness: tf-cuda-test glue 124/124 byte-equal. Replies have the same token_sha as 1.0.8 at 1, 2, 4 and 8 streams.

  • Speed, makespan over 8 trials an arm:

    streams 1.0.8 this change
    1 2.323 s 2.281 s unchanged: a lone window runs the same kernels; the -1.8% is the spread of the window-cost table each build measures and caches at its first start (±1.5% across builds and starts of one tree)
    2 4.128 s 4.111 s -0.4%
    4 6.397 s 6.163 s -3.7%, separated
    8 11.106 s 10.374 s -6.6%, separated (280 → 297 tok/s)

    On 1.0.7, 8 streams ran -5.5% to -7.8% across five sessions and 4 streams -3.4% to -4.3%. The Grill's concurrency ladder there gave -3.3% at 4 streams, separated, and +0.01% at 1.

  • 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: decode glue keeps its loads in flight, same values and order #771 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. (Every stream's sums keep their order.)
  • 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.
  • 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.

…tion run as one launch each

Glue.mambaSegs and Glue.attentionSegs pass every stream's buffers by value (conv/scan: blockIdx.y/z a stream;
attention: blockIdx.x a shared row), each stream computed as the one-stream kernels compute it; the _segs
kernels are copies, so a lone window keeps the one-stream kernels' code. tf-cuda-test glue checks three
streams at once against the host references.
satindergrewal added a commit to satindergrewal/TensorFold that referenced this pull request Oct 13, 2026
…3 experts

Checked ash hart PRs open+closed (read-only). Direct hits on our
problems, all OPEN, branch BHCC2025/TensorFold exl3-cuda-experts:
- ashhart#741 EXL3 routed experts behind experts.Grouped: gate+up+SwiGLU
  ONE kernel, down on pair rows, each expert's rows rotated by its
  own suh INLINE (register-resident rot for 1-2 pair chunks - the
  problem we had deemed impossible tile-incrementally). Rides on
  grouped.zig's Plan (in our tree). 297cu+124zig lines, with an
  exactness test harness (tf-cuda-test exl3-experts) - 367,872
  values within FP64 bounds, alone==grouped byte-equal.
- ashhart#740 EXL3 projections behind qlinear (the stacked base).
- ashhart#718 branch-free trellis window extraction (perf).
- ashhart#729 share decoded weights across prefill rows (perf).
- ashhart#728 MiMo-V2.6 CUDA EXL3 two-GPU (another full CUDA EXL3 family).
- ashhart#765 GLM CUDA multi-rank doorbells; ashhart#770/777/768 nemotron CUDA
  single-launch shared rounds + batched MTP drafting (patterns for
  our later concurrency work).
PLAN: vendored exl3_experts.cu/.zig + exl3.cuh into our tree (this
commit, unwired). Next: build wiring (fatbin + mod), port moeBlock
to Grouped.decode with the router->plan plumbing from grouped.zig,
run their exl3-experts test on our checkpoint, parity, bench. Our
own grouped kernels (stage-1 parity) stay as fallback.
@ashhart
ashhart merged commit e957524 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 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.
@ashhart

ashhart commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Thank you, @plotarmordev. One launch per mixer step for all of a shared window's streams is a clean way to cut a shared round's launch count, and every stream still runs on its own state. It landed in 1.0.9 under your name (da676b0d1), with the same code as your merge with 1.0.8. #771 appends to the same attention file, so its kernel lands after your _segs kernels. Your head is merged after it with no change to the tree (e95752425), so GitHub shows this PR as merged.

What we measured on a GB10 (sm_121):

On the copies: we checked whether one _segs kernel could serve a lone window as a one-segment call. On your tree (before #771), a lone stream decoded at the same speed either way over eight prompts and the qual cells (+0.4%, inside noise), with the same replies. So unlike a shared body, a one-segment call costs nothing. We kept the copies for now because #771 changed the one-stream scan and attention kernels, and a lone window would lose that gain until those changes are carried into the _segs kernels. We'll do that on our side and then remove the duplicates. Until then, the glue cases above hold the two copies to the same bytes.

@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; 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 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