Skip to content

Flash Next on CUDA: a prompt pass holds 3,072 rows - #3726

Merged
ashhart merged 6 commits into
ashhart:mainfrom
BadAd84:flashnext-prompt-chunk3072-up
Nov 19, 2026
Merged

ashhart merged 6 commits into
ashhart:mainfrom
BadAd84:flashnext-prompt-chunk3072-up

Conversation

@BadAd84

@BadAd84 BadAd84 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Terms used below: "main" is upstream TensorFold at 077998f7d9b14adebec3a2acc2caa47ff7ae6ec7 (its tip of 2026-11-16T15:26:10Z, read with git fetch origin main at 17:44:40Z), and "the measured head" is 1fdbd5570b95c258862cc0dd9cb420c82f694de5, that main plus the change commit and the receipt commit, the commit the checks and the receipt below name as measured. The pull request's head is ad1f677976910157d4871385afbbf3be18a4a8c2 ("the head"): the maintainer rebased those two commits onto upstream main at 8cbef9777b9a05dfaff99d5aa9c2ce52fe2b00f8 (as fdc5ca23b34cba77e5080de6b05ca4697639c59b, the change, and 3b27d360938c85c2277be2c1f057a63c935db260, the receipt), and two commits of ours follow: eb9feecaa297df3093c492becc07eed1852c50af, which answers the review (the empty-setting test expects default_chunk and an explicit 1,536 case is kept; the environment table, its help line and the recipe name 3,072 as the default), and ad1f677976910157d4871385afbbf3be18a4a8c2, the Unreleased bullet naming this pull request. Where a check below says "this head", it means the measured head unless the bullet names the head.

What this changes

A Flash Next on CUDA prompt pass held 1,536 rows at most while another stream decoded (cuda_batch_state.zig's default_chunk), so a long prompt on a server with more than one stream ran in passes of 1,536 and each lane admitted 1,536 prompt rows a pass. It holds 3,072 now: a long prompt takes about half the passes (a 64k prompt is 22 instead of 43), each pass holds twice the rows, and each lane's prompt admission is the same 3,072. A server started at one stream is untouched: it takes 8,192-row passes through cuda_chunk.zig's solo rule, on both sides.

A row's bits do not depend on how many rows a pass holds, from the code:

  • splitK (zig/src/cuda/qmmf.zig) reads the weight's shape alone, and its own comment says so: "K slices for an (n, k) weight, from the shape alone so a row's bits never depend on the row count".
  • planSlices gives both sizes the same plan: fused at 256 rows and above whenever the split is wider than one slice, with the same slice order, and neither size falls into the row-bucketed form (16, 32 or 64 rows) that the sub-256 case takes.
  • Every other prompt kernel computes a row from its own inputs and its absolute position: the attention selections (staged att_rows at a time), the norms, the MoE routing and the n-gram gather.

So the change moves how many rows a launch covers, one pass's device scratch and each lane's admission. It moves no arithmetic. The scratch at the default grows with the rows, which is why the test that bounded it says what it now measures: Scratch.bytes(default_chunk, .{ .head_rows = default_chunk }) is 2,753,048,104 bytes at 3,072 rows on this head and 1,397,558,248 bytes at 1,536 rows on main, both printed by the lane's own probe of each tree (an exact expectation instead of a bound, so the test binary reports the figure), so the test that asserted "under two gigabytes" asserts "under three" and names the default it prices: at 1,536 rows the old ceiling held, and at 3,072 rows it does not. The cost is that device memory: each startup line shows 0.79 GiB more model and 0.8 to 0.9 GiB less left for streams, and every setting the receipt measured admits the same number of streams on both sides.

  • Issue: n/a. No issue asks for this, and it is not a new family, backend or arithmetic change; what it needs is the receipt below, which ran on one GB10. The chunk is not a new switch: the default itself is the change, TF_FLASHNEXT_CHUNK still overrides it as today, and 1,536 stays reachable.
  • Stacked on: upstream main at 8cbef9777b9a05dfaff99d5aa9c2ce52fe2b00f8. The branch is the maintainer's rebase of the measured head's two commits (the change fdc5ca23b, which was 052e72a9c, and the receipt 3b27d3609, which was 1fdbd5570, four files, no code), then eb9feecaa and ad1f67797 as named above.
  • atc overlap --json: run last, on the head ad1f677976910157d4871385afbbf3be18a4a8c2 with up/main at e63f26f0e6ae75f76fc2617c1f841af7adbde6e2, 00:11 to 00:12 UTC: incomplete (complete: false, with its own four limits, otherPullRequestsLimit, pullFilesUnavailable, pullRequestsLimit and timeLimit), 13 changed files and 38 overlap rows, of which 28 are working-tree rows (8 clean, 1 conflicts, 19 unknown) and 10 are the fork's trunk (PR 2044) listed against other pull requests, all unknown. The one conflicts entry is dsv41 metal: image prompts #1722, and the only file it shares with this change is CHANGELOG.md (checked against the files of both): the ordinary case of two pull requests inserting their Unreleased bullets in the same place.

Checks on this head

  • Head commit: 1fdbd5570b95c258862cc0dd9cb420c82f694de5 (tree 902ce69615f5e785c7637227877b8da29be82eec; 9 files, 352 insertions and 6 deletions against main), the receipt commit on the change commit 052e72a9c3eb6025b0f6a6095f06194fdc9a3313 (tree d542f131a8208b89462b204b56cb50881a2a4c73; 5 files, 7 insertions and 6 deletions against main); both signed (%G? is G), author and committer BadAd84 <BadAd84@users.noreply.github.com>. Every check below ran on 052e72a9c, whose code the head carries unchanged; git diff --check 077998f7d..1fdbd5570 is clean.
  • Lean checker, python tools/zig/lean_check.py, each tree scanned by its own copy from its own root (the three copies byte-identical, sha256 a08d2a424e01b16a): base 077998f7 6,575 files, 221 problems; this head 6,575 files, 221 problems; tools/zig/lean_new.py: lean: 221 problems, 221 on the base, 0 new. The two file counts are equal because the change adds no file and removes none; that they are two trees is shown by the base-versus-head diff above and by each run's own root.
  • python tools/pr_check.py --base 077998f7d9b14adebec3a2acc2caa47ff7ae6ec7: merge base 077998f7d9b14adebec3a2acc2caa47ff7ae6ec7; 5 changed files; lean 221 vs 221, 0 new, 0 error(s), 1 warning(s). On the head with the receipt commit: 9 changed files; lean 221 vs 221, 0 new, the same one advisory warning. The warning is the advisory --pr one: the branch has no pull request number yet, and the Unreleased bullet's #XXXX becomes it.
  • zig fmt --check build.zig zig: rc 0, no output, on the checked tree of this head.
  • Tests run, as the workflow runs them, on an aarch64 Ubuntu 24.04.5 machine (20 CPUs, Zig 0.17.0, -j4 --maxrss 6000000000, umask 022, no GPU visible), on a fresh git archive tree of this head checked blob by blob against its commit (11,832 entries, 0 mismatches): -Dfixed-cpu test-gradient-serving rc 0, 4/4 steps, 1/1 test; -Dfixed-cpu test-gradient-serving test-qwen-serving-host rc 0, 7/7 steps, 2/2 tests; compile-config-server -Dtarget=aarch64-linux-gnu rc 0, 7/7 steps; compile-cuda-tests -Dtarget=aarch64-linux-gnu rc 0, 10/10 steps; -Dfixed-cpu test-cuda-host -j4 rc 1, 408/410 steps and 6,916/6,950 tests passed, 33 skipped, 1 failed; -Dfixed-cpu test-environment-host -j4 rc 0, 3/3 steps, 25/25 tests; -Dfixed-cpu test-host --test-timeout 20m rc 1, 2,125/2,132 steps and 18,645/18,771 tests passed, 125 skipped, 1 failed. The one failure in both suites is listener.test.accepted IPv4 and IPv6 TCP streams disable Nagle for incremental responses, which fails on this machine for every tree because it boots with ipv6.disable=1; the sibling branch's head fails that same single test, and the two runs' totals differ only in how much of the suite the cache served (this run executed 522 of the 622 test steps and reused 100; the sibling executed 507 and reused 115), which is why the gate is scored on the failing names and not the counts.
  • New tests on a mutant: all three scored, each on a run that reached a Build Summary and each against this head's own unmutated test-cuda-host run (rc 1, 408/410 steps, 6,916/6,950 tests, one failing test, the machine's). b/default-1536 fails cuda_startup_test.test.CUDA startup: unset Flash Next chunk reports the default stored pass; b/default-4096 and b/bound-two each fail cuda_batch.test.a pass's scratch at the default chunk stays under three gigabytes. The scratch's own bytes at 3,072 rows are 2,753,048,104, over the two-gigabyte ceiling the test carried and under the three this change sets, which is what makes the ceiling move load-bearing rather than cosmetic; gates-B.md carries each run's rc, step and test counts.
  • Checks on the current head, after the maintainer's rebase and the review round (the bullets around this one are the measured head's own): python3 tools/pr_check.py --base 8cbef9777b9a05dfaff99d5aa9c2ce52fe2b00f8 --pr 3726: merge base 8cbef9777b9a05dfaff99d5aa9c2ce52fe2b00f8; 13 changed files; lean 221 vs 221, 0 new, 0 error(s), 0 warning(s). On a clean x86_64 Linux machine (16 threads, Zig 0.17.0, umask 022, no GPU), on a fresh git archive tree of the head before its changelog commit: zig fmt --check build.zig zig rc 0; -Dfixed-cpu test-environment-host rc 0, 3/3 steps, 26/26 tests; -Dfixed-cpu test-gradient-serving test-qwen-serving-host rc 0, 7/7 steps, 3/3 tests; compile-config-server -Dtarget=aarch64-linux-gnu rc 0, 7/7 steps; compile-cuda-tests -Dtarget=aarch64-linux-gnu rc 0, 10/10 steps; -Dfixed-cpu test-cuda-host -j4 rc 0, 418/418 steps, 7,092 of 7,125 tests passed, 33 skipped.
  • CI on ad1f677976910157d4871385afbbf3be18a4a8c2 (the head), run on this pull request: fmt, zig, zig-b, zig-windows, pytest, benchmark-clients (ubuntu and windows), release-paths and zig-macos-dev-tools all completed successfully; host-nightly-linux and host-nightly-macos are skipped by their own conditions.
  • Not run, and why: two ranks (the gate machine has no GPU, and the receipt below ran one GPU, one GB10), and the kernel-contract suites, because this change adds and changes no kernel.

Receipt

  • Main against branch: one GB10, one GPU window, the arms alternating M1 B1 B2 M2 with a fresh server each and nothing set on either arm, so the 3,072-row default is the only difference. Cold prompts 9 faster, 0 level, 0 slower; decode 0 faster, 12 level, 0 slower; the one-stream control 0 faster, 5 level, 0 slower.
  • Boxes it reaches: one GB10 runs it. Two ranks are not in the window; the chunk is a launch grouping there too, and a rank above one keeps the drain it has today.
  • New switch? No. default_chunk is the value the setting reads when it is unset, TF_FLASHNEXT_CHUNK still overrides it (1 to 16,384, refused otherwise), and TF_FLASHNEXT_CHUNK_SOLO still governs a one-stream server. No new environment row, so no profile row either.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: TensorFold 077998f7d9b1 (main) against 052e72a9c3eb (this head), both built from source with Zig 0.17.0 and nvcc 13.3 in the nvcr.io/nvidia/pytorch:26.07-py3 image; one GB10 (sm_121), driver 580.178.04; checkpoint nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6887e18c089fdea8509a33e63429a3300.
  • Paths and platforms the change reaches, which I ran and which I could not: the CPU checks above ran on an aarch64 Ubuntu machine with no GPU; one GPU ran in the window above (one GB10); two ranks did not run.
  • Exactness, from tools/bench_concurrent.py --alone --serial and token_sha against "draft": false: every contract equal on both arms, with the prompt cache on and off. Drafted output equals "draft": false (192 equal, 0 unequal, over both arms); a resumed prompt equals a fresh one (14 equal, 0 unequal); concurrent equals solo (338 equal, 0 unequal). Across the arms, 528 greedy decode replies and 12 cold-prompt replies (the same prompt bytes sent to every boot, 2k to 64k, idle and beside three decoders, and the one-stream control) carry identical token ids, so a different pass boundary changed no bit.
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): both arms ran in one GPU window on one GB10, alternating as above; the tables, the noise rule and every contract line are docs/receipts/flashnext-prompt-chunk3072/ (README.md, cells.csv, noise-rule.md, exactness.md) in this diff.
  • Decode speed before and after, from tools/bench_openai.py (one stream, both built-in prompts) and tools/bench_concurrent.py (1, 2, 4, 6 and 8 streams, both prompts, eight being the widest admitted at 32,768 tokens), greedy, two fresh boots an arm: 0 faster, 12 level, 0 slower, the per-cell changes running from -0.5% to -0.1%. The tokens a round are identical in every cell (2.51, 2.81, 4.49, 4.83, 5.22) and so is the server's own acceptance ratio (0.6242, 0.6884). Sampled (temperature 1.0) at 1 to 6 streams, measured once an arm in the exactness boots: -0.2% to +0.7%.
  • Prompt speed before and after: cold ttft_s at 2k, 8k, 32k and 64k, idle and beside three decoders, the prompt cache off, a 131,072-token window at four slots, two fresh boots an arm: 9 faster, 0 level, 0 slower. Time to the first token, branch against main: idle 2k -9.8%, 8k -8.4%, 32k -6.4%, 64k -7.4%; beside three decoders 2k -17.2%, 8k -14.1%, 32k -12.2%, 64k -12.9%; bench_cache's first cold request -7.2%. The 64k cells' ttft_s (M1, M2, B1, B2) are idle 33.058, 33.175, 30.665, 30.682 (-7.4%); beside three decoders 37.582, 37.718, 32.780, 32.786 (-12.9%). The one-stream control, where both arms take 8,192-row passes, is 0 faster, 5 level, 0 slower, which is what says the gain is the default chunk and nothing else.
  • Licence of any new weights or drafter, or "n/a": n/a, no weights and no drafter.
  • The window's arms, cells, settings, boots and length, as an exact command list: docs/receipts/flashnext-prompt-chunk3072/README.md carries it with every number; 20 boots, 0 arm retries, no arm failed.
  • The pass rows and the scratch: the probe's two figures (2,753,048,104 bytes at 3,072 rows on this head, 1,397,558,248 at 1,536 on main) and each arm's own startup line: 32768/8: main model 72.71 GiB, 8 streams at once, 1.29 GiB each, of 27.9 GiB left, 1536 rows a pass; branch model 73.50 GiB, 8 streams at once, 1.32 GiB each, of 27.1 GiB left, 3072 rows a pass; 131072/4: main model 72.73 GiB, 4 streams at once, 4.11 GiB each, of 27.9 GiB left, 1536 rows a pass; branch model 73.52 GiB, 4 streams at once, 4.14 GiB each, of 27.0 GiB left, 3072 rows a pass; 131072/1: main model 76.16 GiB, 1 stream at once, 4.23 GiB each, of 24.3 GiB left, 8192 rows a pass; branch model 76.16 GiB, 1 stream at once, 4.23 GiB each, of 24.4 GiB left, 8192 rows a pass; 131072/8: main refused --parallel 8 at start (needs 32.86 GiB for its streams, the budget leaves 27.85 GiB, it names 6 streams); branch refused --parallel 8 at start (needs 33.1 GiB for its streams, the budget leaves 27.01 GiB, it names 6 streams).

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • 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 in the diff or its commits. No AI attribution lines.
  • 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: measured on both arms with the prompt cache on and off, 544 contract comparisons equal and 0 unequal, 528 greedy pass-A replies and 12 cold cells identical across the arms.
  • No precision traded for speed. A row's K split is the shape's and the fused plan's, both of which this change does not touch.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled: greedy decode 0 faster, 12 level, 0 slower at 1 to 8 streams, sampled decode -0.2% to +0.7% at 1 to 6 streams (one run an arm), cold prompts 9 faster, 0 level, 0 slower, the one-stream control 0 faster, 5 level, 0 slower, drafts off level with identical token ids; this change touches no --drafter path.

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84. Please update cuda_chunk.zig:47: the empty-setting test still expects 1,536 after the default becomes 3,072. The environment help at environment.zig:208 also names the old default. Keep an explicit 1,536 override case and rerun the covering host checks. The supplied performance receipt records the larger memory cost and equal replies.

  • Synthena

BadAd84 added a commit to BadAd84/TensorFold that referenced this pull request Nov 19, 2026
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84. The empty-setting case now uses the resolved default, the explicit 1,536 override stays, and the help says 3,072. That answers both asks, and CI is green at this head, so it's ready to land; the host steps run again in the landing train. The description's checks still cite 052e72a, from before these corrections, if you'd like to refresh them.

  • Synthena

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @BadAd84. The empty-setting case now uses the resolved 3,072 default, the explicit 1,536 override stays, and the help names the new value. With CI green at this head, there is nothing further we need from you.

  • Synthena

ashhart and others added 6 commits November 19, 2026 22:49
The default pass held 1,536 rows while another stream decoded, so a long prompt ran in
passes of 1,536 and each lane admitted 1,536 rows a pass. It holds 3,072 now: a long prompt
takes about half the passes, and each one holds twice the rows.

A row's bits do not depend on how many rows a pass holds. splitK reads the weight's shape
alone, planSlices gives both sizes the fused plan with one K-slice order because the fused
floor is 256 rows, and every other prompt kernel computes a row from its own inputs and its
absolute position. The change moves launch grouping and the pass's device scratch, not the
arithmetic.

The scratch at the default grows with the rows, so the test that bounded it at two gigabytes
bounds it at three and names the default it prices. The startup line's default pass and the
serving pin file follow, and a server started at one stream keeps its 8,192-row passes, so
only a server with more than one stream changes.
…tests and docs

The empty-setting test expected 1536 and the environment table, its help and the recipe still named it as the default.
The test now expects default_chunk for an empty setting and keeps an explicit 1536 case.
@ashhart
ashhart force-pushed the flashnext-prompt-chunk3072-up branch from ad1f677 to 4eab582 Compare November 19, 2026 22:50
@ashhart
ashhart merged commit bc99bab into ashhart:main Nov 19, 2026
1 check failed
ashhart pushed a commit that referenced this pull request Nov 19, 2026
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @BadAd84. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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