Skip to content

Flash Next CUDA: TF_FLASHNEXT_READOUT_FUSED, a prompt pass's BF16 read-out on two fused tiles - #3413

Merged
ashhart merged 30 commits into
ashhart:mainfrom
BadAd84:flashnext-readout-fused
Nov 20, 2026
Merged

ashhart merged 30 commits into
ashhart:mainfrom
BadAd84:flashnext-readout-fused

Conversation

@BadAd84

@BadAd84 BadAd84 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Off by default. With TF_FLASHNEXT_READOUT_FUSED=1, a CUDA prompt pass of 768 rows or more runs the BF16 hyper-connection read-out in three launches instead of five: the down projection forms the normed rows in shared memory, fn_hc_reduce_act is unchanged, and the up projection forms them again in its epilogue and mixes the four streams there, with every output byte the five launches give. On a GB10 with the NVFP4 checkpoint, cold prompts of 8k to 64k tokens are 2.8% to 3.5% faster; 2k is level and decode is unchanged.

Checks

  • Head commit: 02a2b6544, the maintainer's merge of main on top of ea6ca150d5 (the last commit pushed from here).
  • Lean checker, python3 tools/zig/lean_check.py, each tree's own copy, the head's checker byte-identical to main's: main cf4555373 has 6,514 files and 341 problems; ea6ca150d5 has 6,520 files and 341 problems; lean_new.py prints lean: 341 problems, 341 on the base, 0 new. python3 tools/pr_check.py --base cf4555373 --pr 3413: 36 changed files, lean 341 vs 341, 0 new, 0 errors, 0 warnings.
  • Tests run on ea6ca150d5, on the GB10 host (aarch64 Ubuntu 24.04.5, Zig 0.17.0, CPU only, umask 022, -j8 except -j4 for the two test-host runs), on fresh git archive trees:
    • zig build -Dfixed-cpu test-gradient-serving test-qwen-serving-host: exit 0, 7 of 7 steps, 3 of 3 tests. The merge changes no pinned source this branch edits: 169 pinned files, 0 changed, so no re-pin.
    • zig build compile-config-server -Dtarget=aarch64-linux-gnu: exit 0, 7 of 7 steps; zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu: exit 0, 10 of 10 steps.
    • zig build -Dfixed-cpu test-flashnext-readout-fused-host test-disk-identity-host test-environment-host test-flashnext-batch-host test-kernel-contract: exit 0, 47 of 47 steps, 339 of 339 tests (23, 34, 23, 17 and 172 a step).
    • zig build -Dfixed-cpu test-host --test-timeout 20m: exit 1 on ea6ca150d5, 2,090 of 2,095 steps and 20,808 of 20,948 tests passed, 139 skipped, 1 failed; exit 1 on main cf4555373, 2,087 of 2,092 steps and 21,412 of 21,558 tests passed, 145 skipped, 1 failed. The one failure is the same on both, listener.zig's IPv4 and IPv6 Nagle test, because this machine boots with ipv6.disable=1.
    • zig fmt --check build.zig zig and git diff --check against main: exit 0, no output.
    • On 3d2a267747, before the last merge: zig build test on Windows, exit 0. The merge touches none of the files the two mutants below change.
    • Two mutants: the kept-state key without the setting fails test-disk-identity-host (33 of 34), and the refusal without its error fails test-flashnext-readout-fused-host (22 of 23).
    • On a GB10, in an image of ee13555c8e (ea6ca150d5's code): tf-cuda-test kernel-contract fn_hcn, exit 0, and tf-cuda-test flashnext-readout-fused, 16 of 16 row counts byte-equal, exit 0.
    • The readout kernels' fatbins, built with the build's own nvcc arguments for sm_121 (nvcc 13.3.73 in nvcr.io/nvidia/pytorch:26.07-py3), once from ee13555c8e's kernel sources and once from ea6ca150d5's: flashnext_hcn.cu (234,576 bytes, sha256 d231b42dfeae3fa8) and qmmf.cu (2,360,296 bytes, sha256 f1395659bd31d839) are byte-identical both times, although main's common/fp_pairs.cuh, which both include through common/qmm_frag.cuh, gained 6 lines meanwhile.
  • CI on 02a2b6544 (this 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: Metal and HIP, with no such hardware; the GB10 device tests above ran on ee13555c8e's image and were not repeated on 02a2b6544; the maintainer's device check on it is on this pull request.

Receipt

  • Main against branch: docs/receipts/flashnext-readout-fused/README.md (with cells.csv, noise-rule.md and exactness.md), on main 41a72fd257. A discarded warm-up boot of main, then six arms alternated (main, unset, 1, main, 1, blank), one fresh server each, --prompt-cache-gib 0. Cold prompt, seconds to the first token, main's two runs against 1's two:

    prompt main 1 change
    2k 1.046, 1.078 1.054, 1.031 -1.8%, level
    8k 4.009, 3.992 3.865, 3.854 -3.5%, faster
    32k 15.903, 16.062 15.512, 15.542 -2.8%, faster
    64k 32.795, 33.108 31.866, 32.024 -3.1%, faster
    bench_cache.py --require-cold, 2,571 tokens 1.233, 1.223 1.183, 1.185 -3.6%, faster

    Noise rule (slower when both branch runs are past both main runs and the mean gap is over 1%): 0 of 19 cells slower, unset and 1 alike; with 1, four faster and the other 15 level. No cell needed a rerun.

  • Why the receipt still describes this head: between 41a72fd257 and cf4555373 main changed 119 files; this branch shares 4 with them (CHANGELOG.md, docs/environment.md, docs/recipes/flash-next-cuda.md and zig/tests/cuda/main.zig), and the merge was clean outside CHANGELOG.md. On a Flash Next CUDA request's path main changed common/fp_pairs.cuh (the byte-identical fatbins above) and zig/src/core/lane_host.zig and lane_host_end.zig (two added calls into the load ledger for a cancelled request); the rest are other families, HIP, tests, tools and docs.

  • Boxes it reaches: CUDA prompt passes of 768 rows or more whose read-out is BF16. Decode and verify rounds, shorter passes, MLX affine read-outs, Metal and HIP are unchanged.

  • New switch? TF_FLASHNEXT_READOUT_FUSED: 0 or 1, default 0; unset or blank is off; anything else stops the start (TF_FLASHNEXT_READOUT_FUSED="2": expected 0 or 1 (default 0)). Rows in docs/environment.md and docs/recipes/flash-next-cuda.md. With 1, Metal, HIP and an MLX affine read-out on CUDA stop the start by name, and the kept-state key reads the setting (bit 1 of the TF_FLASHNEXT_HC_FUSE slot), so unset leaves main's key.

  • Environment: TensorFold 41a72fd257 and this change on it (ee13555c8e), each image built the same way from its commit, Zig 0.17.0, CUDA 13.3, one NVIDIA GB10 (sm_121), nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6887e18c089fdea8509a33e63429a3300, --parallel 4, a 131,072-token context, bf16 KV.

  • Paths and platforms the change reaches, which I ran and which I could not: CUDA on a GB10, ran. Other CUDA GPUs pick their down tile from their SM count; not run. Metal and HIP only refuse the setting; not run.

  • Exactness: docs/receipts/flashnext-readout-fused/exactness.md. Drafted equals "draft": false, resumed equals fresh and concurrent equals solo on main, unset and 1, with the prompt cache on and off; replies equal main's in every comparison, including three long prompts (about 1.5k, 5k and 15k tokens) at 1 and 4 streams and prompt passes of 2,048 and 3,072 rows. Passes of 1,000 rows fail every request on main itself (CudaFailed after cuMemsetD8Async: CUDA_ERROR_INVALID_VALUE), and the branch fails the same way, unset or set.

  • Main against this branch, same machine and checkpoint: as above, before asking for a run.

  • Decode speed before and after, from tools/bench_openai.py (greedy, 3 reps): code 72.6, 72.0 against 72.1, 72.1 tok/s, chat 46.6, 46.4 against 46.4, 46.4 (both -0.2%, level), 5.224 and 2.813 tokens a round in every arm. With tools/bench_concurrent.py --alone --serial, greedy and at temperature 1.0 with seed 1234, 1, 2 and 4 streams: all 12 cells level (within 0.3%), tokens a round equal, and server acceptance equal in every arm.

  • Prompt speed before and after: tools/bench_cache.py --require-cold (2,571 tokens, 0 cached): 1.233, 1.223 s on main, 1.183, 1.185 s with 1 (-3.6%).

  • Licence of any new weights or drafter: n/a, no weights.

Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces (zig/tests/cuda/contract_flashnext_hcn.zig): fn_hcn_down2, fn_hcn_down3 and fn_hcn_down4 replace fn_hc_normalize then the qmmf lane's fp32 down; fn_hcn_up3 replaces the qmmf lane's bf16 up then fn_hc_dense_mix. The replaced launches run on the engine's lane, with qmmf's BF16 prompt tiles loaded as TF_FLASHNEXT_PROMPT_BF16 leaves them. Each kernel must give every output byte of what it replaces at 768, 769, 1,000, 1,536, 2,053 and 3,072 rows and on planted non-finite rows. Their records (flashnext_tile_records.zig) are nvcc 13.3's for sm_80 to sm_121, from ptxas; on sm_121 they equal the driver's own counts (152, 189, 206 and 127 registers, no static shared memory). nvcc 13.0 and 13.2 were not available to compile them.
  • A planted control for each new kernel, and each one fails as planted (contract_hcn_controls.cuh, gate 3): tf_ctl_hcn_down3_rz rounds the normed rows toward zero and differs from byte 0; tf_ctl_hcn_up3_raw gates the up rows before their bf16 rounding and differs from byte 2.
  • Each backend's SUMMARY line and exit status: CUDA, tf-cuda-test kernel-contract fn_hcn on a GB10, exit 0: (filtered) SUMMARY 4 kernels: 4 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed; 0 limit problems; gates 2066 ms, limits 0 ms. Gate 4 does not apply (the kernels declare no sums of their own). Metal and HIP: n/a, the kernels are CUDA only and those backends refuse the setting.
  • Chips I could not run: every chip but sm_121.

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. (The two mutants above each fail their host test; the contract's two planted controls fail as planted.)
  • 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.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted (four streams here), greedy and sampled, with the MTP head drafting; this change does not touch drafting.

BadAd84 added a commit to BadAd84/TensorFold that referenced this pull request Nov 15, 2026

@auditbenchaibot auditbenchaibot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open in Audit Bench Ai

🤖 Automated review by Audit Bench Ai, not a personal review. It was posted through the GitHub account connected to Audit Bench Ai. Install the Audit Bench Ai GitHub App to have reviews posted by a separate bot account.

No actionable comments were generated in this review. 🎉

Merge readiness: 🟡 Ready to merge, with notes

Pre-merge checks: ✅ 3 · ⚠️ 2

⚠️ Checks to review: 2 warnings

Check name Status Explanation Resolution
CI checks ⚠️ 7 of 10 still running. -
PR size ⚠️ 1,312 lines changed, which is hard to review well. Split it into smaller pull requests if you can.
✅ Passed checks: 3 passed
Check name Status Explanation
Merge conflicts ✅ Merges cleanly into main.
Secrets ✅ No keys, passwords or tokens in the changed code.
Blocking issues ✅ No critical or high-severity issues in the changed lines.
ℹ️ Review info
  • Commit: 3d2a267
  • Verdict: ✅ Pass
  • Findings: none
  • Review: local checks plus AI review of the changed lines
  • Scope: Reviewed 0/0 selected files (of 0 total): 0 reviewed by AI, 0 from cache, 0 passed local checks with nothing risky enough to send to AI. Found 0 finding(s), No secrets found.

💬 Reply to any inline comment and Audit Bench Ai will recheck that code and answer in the thread. Mention @auditbench in the conversation to ask about the whole PR.

🛠️ Open the full report and fix with AI

Thanks for using Audit Bench Ai! Free pull request reviews for open source: paste any public PR at auditbenchai.com/scan.

Reviewed by Audit Bench Ai · Build fast. Check what ships. · Review any public PR free

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84. The authored fusion changes retain the explicit rounding points, prompt/BF16 guards and disk-key separation. The focused host checks pass, and the 19-cell receipt reproduces four faster cells and none slower under its stated rule.

The supplied CI status is not green at 3d2a267747: Actions are described as disabled, and the earlier check report is still incomplete. Please enable the checks or arrange runs of zig, zig-windows, pytest and fmt at that head. We are holding this until those pass and the final merged source is checked.

  • Synthena (Ash's Agent)

@BadAd84

BadAd84 commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. The checks have run at 3d2a267747, on this pull request: fmt, zig, zig-windows, pytest, benchmark-clients (ubuntu and windows), release-paths and zig-macos-dev-tools all completed successfully, and the two nightly jobs were skipped by their own conditions. My body said "CI: not run (the fork has Actions disabled)", which was wrong for the pull request (those are your repository's runs, and the fork's own Actions stay off); I have corrected that line.

Main has moved on since this head (it was 41a72fd257 when the receipt was taken). If you want the final merged source checked, I will merge current main into the branch, re-run the host checks on it and post the new head and its results here.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@BadAd84, we applied the series to main and read it end to end: the setting is off by default, the kept-state
key is unchanged when unset, and the fused path only arms on the environment row. We ran the read-out and
disk-identity host suites and both are green, and the series carries the kernel contract
with its two planted controls. Your GB10 receipts - the kernel contract run and the sixteen row counts byte
equal - cover the hardware side of the exactness claim, and your served comparison shows 2k level and 8k to
64k faster with replies equal to main's throughout.

Nothing to change from us. Two notes for the record: main has gained rows in the two environment tables since
your branch's view, and the hunks land beside them cleanly, but a merge or rebase will meet those neighbours;
and your description cites two different head ids for the tip - please pin the reviewed code to one head so
the landing queue carries an unambiguous commit.

On our side we will run the same pair of device commands on our GB10 - the kernel contract and the fused
read-out's sixteen row counts - and then the served cold-prompt comparison at 2k, 8k, 32k and 64k, main against
the setting on, each arm on a fresh server; we expect the replies to match main's token for token and the
first-token times to sit with your posted cells.

  • Synthena (Ash's Agent)

@BadAd84

BadAd84 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. The tip to review is ea6ca150d5, the merge of main cf4555373 into the branch (one conflict, CHANGELOG.md, both sides kept). The description now names that one head and the CI that ran on it.

ee13555c8e, which the description still mentions, is not a second tip. It is the commit the GB10 device commands ran on, an image of that commit's code. flashnext_hcn.cu and qmmf.cu build to byte-identical sm_121 fatbins from ee13555c8e and from ea6ca150d5, so those two device results hold for the tip, and the description says so.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@BadAd84, both device checks we promised are done on a GB10 at ea6ca15, Flash Next NVFP4, main against this head with a fresh server each arm.

With the setting unset, nothing changes: 0 of 20 prompt rows differ and cold-prompt speed is level with main. With TF_FLASHNEXT_READOUT_FUSED=1 on the new arm only, replies are still exact (0 of 20 rows differ) and cold prompts get faster at every size: +1.7% to +2.7% at 2k, +3.1% to +3.4% at 8k and 16k, +3.0% to +3.3% at 32k and +3.1% at 64k, with the two arms' runs never overlapping above 2k.

CI is green, so it's queued to land as an opt-in. Since it's exact and faster at every size we measured, making it the default looks worth a follow-up PR, with a decode and multi-stream check alongside.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@BadAd84, a heads-up: #2837 landed and also changes cuda_launch.zig, so your branch's serving pin conflicted with main. I merged main into your branch (02a2b65, your commits untouched) and pinned the merged file; the pins, environment and CUDA host tests pass and the Linux CUDA build compiles. If you push again, please pull that merge first.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @BadAd84. The single tip is clear now, and the byte-identical fatbins explain why the earlier device results carry over.

Our GB10 checks are done: with the setting unset the replies and cold speed match main, and with TF_FLASHNEXT_READOUT_FUSED=1 the replies stay exact and cold prompts are faster at every size we measured. This is ready to land as an opt-in; we will rebase it onto current main first, since main has moved. A default switch would be a separate change with decode and multi-stream checks.

  • Synthena

ashhart pushed a commit to BadAd84/TensorFold that referenced this pull request Nov 19, 2026
@ashhart
ashhart force-pushed the flashnext-readout-fused branch from c8f586e to 10c8424 Compare November 19, 2026 04:25
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84. To get this moving, we rebased it onto current main ourselves, keeping every one of your commits as it was (author and message) and fitting it to the code main has gained since; no behaviour changes. It is in the landing queue now, and if anything else is needed from you we will say so here.

  • Synthena

laudney and others added 13 commits November 20, 2026 11:10
The tower's tensors load as plain BF16 [n, k] matrices for cuBLASLt:
fc1 and fc3 stacked into one gate|up projection, and the patch weight
flattened to 588 columns and zero-padded to 592 so its rows meet the
library's alignment. Every vision_tower tensor is consumed, the device
bytes count the padding, and a failed load drains its uploads before
any buffer is freed.
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
The drain test called settle directly, so dropping the errdefer in
load, or registering it before the tower's own errdefer, would stay
green. A host test now runs load on a sparse checkpoint against a
fake device whose first upload's wait fails: the buffers must go only
after the context proved the copies done. The sparse checkpoint
helper moves to its own test file so the tower's tests can share it.
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
The recipe now declares the tower, so the dense engine's tower
variant serves dots.mocr: --vision opens it, the host reads its
limits, marks and words, and its weight and open bytes join the
vision bytes. The tower counts its encodes, and the dots module
exports its config for the GB10 runner, whose new dots-invariants
serves the engine with --vision and runs a small image, the full
image (the oracle's prompt ids when given) and two images, each
under cuts that the run proves landed off the 1,024-row grid,
against the uncut run: the KV rows, the last-row logits, the greedy
ids and one encode an image must all be equal. Host tests pin the
recipe's tower, the vision decls and bytes, and the engine's words.
--
2.43.0
ashhart#2732's runner gains dots-text, so a decoder drift fails without the
Python oracle: three chat-templated prompts of our own (18, 578 and
2,537 ids, committed as fixtures/own-prompts.json) each generate up
to 64 greedy reply ids through the served dense engine (EOS can end
one sooner), and the sha256 of those ids as little-endian u32 must
equal its pinned constant. The constants wait for the GB10 run, so
the command prints each measured hash and fails until they are
filled in. A host test pins the fixture's prompt lengths, its
vocabulary range and its turn marks.
--
2.43.0
The description claims the text path with and without --vision, but
dots-text served the engine only with --vision. It now serves the
three own prompts twice, with --vision and without it, against the
same pins, and like dots-image it names another SM instead of
comparing GB10 pins there.
--
2.43.0
The fixture's ids could not be regenerated from the tree. The
fixtures README now names their source text, our own ownprompts.py,
and how each prompt became ids: one user turn rendered with the
checkpoint's chat template and tokenized by the pinned oracle.
--
2.43.0
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
…-out on two fused tiles

Off by default. With TF_FLASHNEXT_READOUT_FUSED=1, a CUDA prompt pass of 768 rows or more runs the BF16
hyper-connection read-out in three launches instead of five. The down projection forms the normed rows in shared
memory (flashnext_hcn.cu, fn_hcn_down2/3/4), reduce_act is unchanged, and the up projection forms them again in its
epilogue and mixes the four streams there (fn_hcn_up3). The writeback before such a read-out skips its normalize.

Both kernels keep the chain's mma order, K-slice fold and rounding points, so every output byte equals the five
launches'. tf-cuda-test flashnext-readout-fused compares them at 64 to 3,072 rows over every down tile and times
both paths.

Metal, HIP and a CUDA checkpoint whose read-out is MLX affine stop the start by name with the setting on.
BadAd84 and others added 17 commits November 20, 2026 11:10
fn_hcn_down2, fn_hcn_down3, fn_hcn_down4 and fn_hcn_up3 register as replacements: every output byte must equal
fn_hc_normalize followed by the qmmf lane's fp32 down, or the qmmf lane's bf16 up followed by fn_hc_dense_mix, at six
served row counts from 768 to 3,072 and on planted non-finite rows. Two planted controls must fail gate 3:
fn_hcn_down3 rounding its normed rows toward zero, and fn_hcn_up3 gating its up rows before their bf16 rounding.

The kernel bodies move to flashnext_hcn.cuh so the controls build from them; the engine's instances keep both control
flags off. The four launches join the records whose compiler usage is pending, so device limits still check them.

test-flashnext-readout-fused-host runs the down tile choice and the refusals by name without a GPU, and the CHANGELOG
line carries the issue number's placeholder.
…e SMs, and the disk key reads the setting

The tile kernels take the SM count at load, where the lane had it only with TF_FLASHNEXT_PROMPT_BF16 on; any
tile gives the same bytes. TF_FLASHNEXT_READOUT_FUSED joins the kept-state key as bit 1 of the hc_fuse slot, so
with it unset the key is unchanged. The device comparisons now run the five launches on the engine's lane, with
qmmf's BF16 prompt tiles loaded, and check that lane against the plain one.
@ashhart
ashhart force-pushed the flashnext-readout-fused branch from 72968e8 to f78dc21 Compare November 20, 2026 11:10
@ashhart
ashhart merged commit 9748adc into ashhart:main Nov 20, 2026
2 of 11 checks passed
ashhart added a commit that referenced this pull request Nov 20, 2026
@ashhart

ashhart commented Nov 20, 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.

4 participants