Skip to content

Nemotron CUDA: prompt passes of up to 4,096 rows between kept points - #720

Merged
ashhart merged 3 commits into
ashhart:mainfrom
plotarmordev:perf/nemotron-merged-passes
Oct 13, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
plotarmordev:perf/nemotron-merged-passes

Conversation

@plotarmordev

@plotarmordev plotarmordev commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Nemotron on CUDA runs a prompt in passes of up to 4,096 rows instead of 2,048: a serial pass joins grid chunks between the points the prompt cache keeps states at, so each pass reads the routed experts' weights once for twice the rows. Resume points, kept states and every reply's bits are unchanged.

  • cuda_engine.zig serialChunks: grid chunks join up to state.pass_rows (2 x prefill_rows), cutting only at a keep (kept). No joining under --dump, attached lessons or a decision row; staggered segments keep the 2,048-row grid.
  • cuda_state.zig: pass_rows, and the prompt scratch sized for it; cuda_mtp.zig and the pinned prompt ids follow.
  • Engine.last_row replaces (len - 1) % prefill_rows where the last chunk's hidden row is read (cuda_lanes.zig, cuda_decode.zig, cli/cuda_segments.zig, tests/cuda/tree_accept.zig).

Receipt

  • Environment: two DGX Sparks (GB10, sm_121, driver 580.173.02, CUDA 13), TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit @ d9d758fb, this branch on e7c523eb built with zig build native -Dnvcc=… -Dsm=121, built-in kernels, --context 16384 --parallel 4.

  • Exactness:

    • Against e7c523eb: 6 replies (a short prompt, a code prompt and an ~11,500-token prompt, each drafted and "draft": false, 96 tokens) in each of four sessions (two per build): token_sha and the 20-alternative logprob rows identical.
    • Against 1.0.6 on the same change: 13 replies in each of four sessions identical; per-turn cached_tokens identical (the second turn resumed 4,096 tokens in both); concurrent equals solo; tensorfold segments digests (state, head, logits, hidden) equal across 1 to 4 segments and equal to stock; tf-cuda-test tree-accept JSON byte-identical to stock.
  • Prompt speed (tok/s, medians of 3 prompts in each of two sessions per build, sessions ordered A B B A):

    cold prompt (random words) e7c523eb this branch
    ~725 tokens 5,040 5,043 +0.1%
    ~1,420 6,459 6,436 -0.4%
    ~2,780 6,479 7,344 +13.3%, separated
    ~5,570 6,856 7,206 +5.1%, separated
    ~11,500 6,691 7,040 +5.2%, separated

    On 1.0.6, The Grill 0.6.0's prefill-prose-portable-selection-v1 (baseline, change, unchanged control; --context 65536 --parallel 2): makespan -8.1% at 4k, -3.9% at 8k, -5.4% at 16k, -5.1% at 32k, each separated from both baselines, control flat. Prompts of repository text on the second Spark: +6.5% to +16.4%. The Grill's sparkdash-prefill (a repeated unit, few experts routed): no change.

  • Decode speed: unchanged (The Grill's portable-v1, order swapped: no effect).

  • Memory: the prompt workspace takes 0.47 GiB more (18.46 GiB against 17.99 at startup).

  • Tests run: zig build test 39/39 steps, 451/451 tests; zig build test-cuda-host 24/24 steps; the server tests 127/127 and 104/104 (zig/tests/server/zig_test.sh); the frozen server goldens 309 of 319 equal, 0 unexpected differences, as on main; zig fmt --check clean on the changed files; lean_check.py 534 problems, as on main. GPU: tf-cuda-test glue 100/100, sample 2880/2880, symbols, and tree-accept byte-identical to stock (on 1.0.6, same change).

  • Not run, and why: Metal (unchanged). The NVFP4 checkpoint, RTX cards (no hardware here).

This touches serialChunks as the prompt-cache pull requests (#721 to #723) do; whichever lands second needs a small merge there.

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. If the bits change, the description says which sums change and why. (No bits change: a row's arithmetic does not depend on where its chunk is cut.)
  • 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. (CUDA GB10 only.)
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (No new test; the existing GPU checks 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.

…prompt states

1.0.8 moved the prompt pass into cuda_prompt.zig, cuts chunks from where a pass starts and keeps states inside
chunks; the wider chunk is now that pass's step outside lessons, dumps and crowded marks. 1.0.8's last_chunk
replaces this branch's last_row.
@plotarmordev

Copy link
Copy Markdown
Contributor Author

Brought up to date with 1.0.8 (0efbd447) by a merge, with no force-push (head 350e0703). 1.0.8 moved the prompt pass into cuda_prompt.zig, cuts chunks from where a pass starts, and keeps states inside chunks (#670). On that pass, this PR's change is now one line of the chunk step: up to 4,096 rows, and 2,048 under lessons, --dump, or when more keep marks would fall in the chunk than it can take. 1.0.8's last_chunk replaces this branch's last_row. Staggered segments are unchanged.

Re-checked at this head on a GB10 (Nemotron 3.5 Lightning MLX-4bit), against a 1.0.8 build:

  • tf-cuda-test glue: 100/100 byte-equal.
  • tf-cuda-test resume on a 9,000-token prompt: 8 marks, each resumed equal to the fresh pass.
  • tf-cuda-test marks with five patterns (rows 100/4100/8191, 2048/4096/6144, 4095/4097, 1/8999, 3000/3001/3002/7000): every kept state byte-equal to the cut pass, and both passes equal to a plain one.
  • Served, cache off, A B A B: replies at 14k, 28k and 56k tokens have the same token_sha as 1.0.8. First token 2.06 → 1.99 s, 4.45 → 4.25 s and 10.21 → 9.84 s. Decode unchanged.
  • The Grill, prose prefill, A/B/A2 with 8 acquisitions each: 4k −7.7%, 8k −7.9%, 16k −5.2%, 32k −6.1%. Every cell separated, and the A2 control moved at most 0.3%.
  • zig build test 616/621 (5 skipped), server tests 155/155 and 96/96, goldens 309/319 with 0 unexpected differences. All as on 1.0.8, and zig fmt and lean_check match 1.0.8.

The CHANGELOG entry now carries these numbers.

@ashhart
ashhart merged commit de38e5f into ashhart:main Oct 13, 2026
2 checks passed
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
…o 4,096 rows (ashhart#720)

The startup line said prompts ran in 2048-row chunks; serial passes now run up to 4,096 rows, and 2,048-row chunks stay for staggered segments, dumps and lessons. Comments only otherwise.
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, carried onto 1.0.8's prompt code; this keeps the PR's head 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
…akes runs 2,048 rows

A 4,096-row pass can hold more prompt-cache marks than the scan arms at
once (marks.max, 16), and a keep past that was refused as TooManyMarks,
so its state was never kept. A pass now runs 4,096 rows only while
fewer than marks.max marks fall strictly inside it; otherwise it runs
2,048, as ashhart#720's head resolves it on 1.0.8.

Co-authored-by: plotarmordev <[email protected]>
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
@ashhart

ashhart commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Thank you, @plotarmordev. Passes of up to 4,096 rows are a clean win for long prompts, and because a row's bits don't depend on where a pass is cut, the change was easy to check. It landed in 1.0.9 under your name (6d63e7da6), carried onto 1.0.8 by us; our follow-up (ec9234000) only updates the startup line, the row count it prints and the comments that still said 2,048-row chunks.

Your merged head brought one thing ours lacked: a pass runs 4,096 rows only while fewer than 16 keep marks fall inside it, and 2,048 otherwise. Without it, a 17th mark inside a wide pass was refused (TooManyMarks) and its state not kept. We ported that guard as 21ee9a445, with you as co-author, and checked it on a GB10: 17 marks inside one 4,096-row window fail on the build without it and pass with it, every pattern's states byte-equal. Your current head is merged into the history with no change to the tree (de38e5f5d), so GitHub shows this PR as merged.

What we measured on a GB10 (sm_121):

  • Prefill. Cold prompts of 8k, 16k, 32k and 64k tokens prefill 7.2%, 6.8%, 6.3% and 5.4% faster, and 2k as before (Nemotron 3.5 Lightning, MLX 4-bit, four servers of each build in a mirrored order, two runs each). In the 1.0.9 release gate (1.0.9 against 1.0.8 on a GB10, A B B A), cold prompts of 8k, 16k and 32k tokens read 7.3%, 7.0% and 6.4% faster on MLX 4-bit and 6.0 to 6.7% faster on NVFP4, 2k level, and a 64k prompt answered.
  • Same replies. The same reply drafted and with "draft": false in all 17 release cells, and the same token SHAs as the build without it, on MLX 4-bit (our own kernels and the captured GB10 set) and on NVFP4. tf-cuda-test prompt-cuts passes at 3,073, 4,096, 4,097 and 8,193 tokens on both checkpoints, so a prompt cut anywhere, across two of your 4,096-row passes included, gives the uncut pass's states, caches and first token.
  • Decode. With both builds on the same window-cost table, every decode cell (code and prose, greedy and seeded sampled) is within 0.9% of the build without it, so the larger prompt buffers cost decode nothing.

ashhart added a commit that referenced this pull request Oct 16, 2026
…s wrap at 120 columns

The prompt-cache change brought back the startup line's older "prompts in {d}-row chunks" over 1.0.9's "prompts
in passes of up to {d} rows" (#720); this restores 1.0.9's text. The rest wraps the lines the change wrote, with
the same values: Nemotron's cache rules, budget and warm turns are as before.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…o 4,096 rows (ashhart#720)

The startup line said prompts ran in 2048-row chunks; serial passes now run up to 4,096 rows, and 2,048-row chunks stay for staggered segments, dumps and lessons. Comments only otherwise.
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, carried onto 1.0.8's prompt 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
…akes runs 2,048 rows

A 4,096-row pass can hold more prompt-cache marks than the scan arms at
once (marks.max, 16), and a keep past that was refused as TooManyMarks,
so its state was never kept. A pass now runs 4,096 rows only while
fewer than marks.max marks fall strictly inside it; otherwise it runs
2,048, as ashhart#720's head resolves it on 1.0.8.

Co-authored-by: plotarmordev <[email protected]>
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
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…s wrap at 120 columns

The prompt-cache change brought back the startup line's older "prompts in {d}-row chunks" over 1.0.9's "prompts
in passes of up to {d} rows" (ashhart#720); this restores 1.0.9's text. The rest wraps the lines the change wrote, with
the same values: Nemotron's cache rules, budget and warm turns are as before.
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