Repository navigation
Flash Next CUDA: TF_FLASHNEXT_READOUT_FUSED, a prompt pass's BF16 read-out on two fused tiles - #3413
Conversation
auditbenchaibot
left a comment
There was a problem hiding this comment.
🤖 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
| 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
|
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
|
|
Thanks. The checks have run at Main has moved on since this head (it was |
|
@BadAd84, we applied the series to main and read it end to end: the setting is off by default, the kept-state Nothing to change from us. Two notes for the record: main has gained rows in the two environment tables since On our side we will run the same pair of device commands on our GB10 - the kernel contract and the fused
|
|
Thanks. The tip to review is
|
|
@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 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.
|
|
@BadAd84, a heads-up: #2837 landed and also changes
|
|
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.
|
c8f586e to
10c8424
Compare
|
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.
|
10c8424 to
72968e8
Compare
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.
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.
…t under 1.2.9 -- 2.43.0
….zig and cuda_prompt_wt.zig at this change
…nches resolve their image
….3 on sm_80 to sm_121
…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.
…ver 19 cells, docs and changelog numbers
72968e8 to
f78dc21
Compare
|
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. |
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_actis 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.Issue: Refs Flash Next CUDA: a prompt pass's BF16 read-out runs five launches where two fused tiles give the same bytes 3.5% faster #3392. The setting is off by default, so main's prompt path still runs the five launches.
Stacked on: main
cf4555373554867a72c53263e905f203a03d4d96. The branch was cut fromd6c4cce602and brought up to date by merge commits (5fe8848e54for2ba55ec7d3,5fd462304ffor643db94726,ee13555c8efor41a72fd257,ea6ca150d5forcf4555373), not by a rebase. The last merge had one conflict,CHANGELOG.md, settled by keeping every line main added and this branch's one entry at the end of Unreleased. Main was then merged into the branch once more by the maintainer's agent (02a2b65440), which is the head now.atc overlap --base up/main --json(up/main =cf4555373), run last onea6ca150d5, 00:21 to 00:22 UTC:complete: false(other pull requests, their files and time limits). It listed 42 open pull requests against this tree: 4clean, 5conflictsand 33unknown. Each was fetched from its head and merged bygit merge-treewith this head and with main alone:CHANGELOG.mdand for two of them in other files they share with main.zig/tests/fixtures/gradient-serving.tsv, where each pins sources near this branch's: qwen35 cuda: fuse the dense MLP's NVFP4 prompt gate and up projections into one launch #2410, CUDA: #1764's BF16 prompt tile for Qwen ModelOpt, Nemotron and Dory, plus two exact Qwen prompt kernels (#1762) #2008 and Flash Next TP=2 on CUDA: head and rollback graphs replay, and one-row split lanes skip the interleave copies #2837 (the last also conflicts inCHANGELOG.mdwith main alone), and idol: Idol's denoiser on CUDA (stacked on #1766) #1767, which also conflicts in the#includelist at the end ofzig/kernels/cuda/contract_controls_set.cu(both add one line) and already conflicts with main alone in the pin file,zig/build/metal_targets.zigandzig/src/tensorfold.zig.No conflict is in code logic. Whichever lands second takes the other's include line and pin row.
Checks
02a2b6544, the maintainer's merge of main on top ofea6ca150d5(the last commit pushed from here).python3 tools/zig/lean_check.py, each tree's own copy, the head's checker byte-identical to main's: maincf4555373has 6,514 files and 341 problems;ea6ca150d5has 6,520 files and 341 problems;lean_new.pyprintslean: 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.ea6ca150d5, on the GB10 host (aarch64 Ubuntu 24.04.5, Zig 0.17.0, CPU only, umask 022,-j8except-j4for the twotest-hostruns), on freshgit archivetrees: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 onea6ca150d5, 2,090 of 2,095 steps and 20,808 of 20,948 tests passed, 139 skipped, 1 failed; exit 1 on maincf4555373, 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 withipv6.disable=1.zig fmt --check build.zig zigandgit diff --checkagainst main: exit 0, no output.3d2a267747, before the last merge:zig build teston Windows, exit 0. The merge touches none of the files the two mutants below change.test-disk-identity-host(33 of 34), and the refusal without its error failstest-flashnext-readout-fused-host(22 of 23).ee13555c8e(ea6ca150d5's code):tf-cuda-test kernel-contract fn_hcn, exit 0, andtf-cuda-test flashnext-readout-fused, 16 of 16 row counts byte-equal, exit 0.nvcr.io/nvidia/pytorch:26.07-py3), once fromee13555c8e's kernel sources and once fromea6ca150d5's:flashnext_hcn.cu(234,576 bytes, sha256d231b42dfeae3fa8) andqmmf.cu(2,360,296 bytes, sha256f1395659bd31d839) are byte-identical both times, although main'scommon/fp_pairs.cuh, which both include throughcommon/qmm_frag.cuh, gained 6 lines meanwhile.02a2b6544(this head), run on this pull request:fmt,zig,zig-b,zig-windows,pytest,benchmark-clients(ubuntu and windows),release-pathsandzig-macos-dev-toolsall completed successfully;host-nightly-linuxandhost-nightly-macosare skipped by their own conditions.ee13555c8e's image and were not repeated on02a2b6544; the maintainer's device check on it is on this pull request.Receipt
Main against branch:
docs/receipts/flashnext-readout-fused/README.md(withcells.csv,noise-rule.mdandexactness.md), on main41a72fd257. 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 against1's two:1bench_cache.py --require-cold, 2,571 tokensNoise 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
1alike; with1, four faster and the other 15 level. No cell needed a rerun.Why the receipt still describes this head: between
41a72fd257andcf4555373main changed 119 files; this branch shares 4 with them (CHANGELOG.md,docs/environment.md,docs/recipes/flash-next-cuda.mdandzig/tests/cuda/main.zig), and the merge was clean outsideCHANGELOG.md. On a Flash Next CUDA request's path main changedcommon/fp_pairs.cuh(the byte-identical fatbins above) andzig/src/core/lane_host.zigandlane_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:0or1, default0; unset or blank is off; anything else stops the start (TF_FLASHNEXT_READOUT_FUSED="2": expected 0 or 1 (default 0)). Rows indocs/environment.mdanddocs/recipes/flash-next-cuda.md. With1, 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 theTF_FLASHNEXT_HC_FUSEslot), so unset leaves main's key.Environment: TensorFold
41a72fd257and 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-Localatb9ce18a6887e18c089fdea8509a33e63429a3300,--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 and1, 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 (CudaFailedaftercuMemsetD8Async: 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. Withtools/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 with1(-3.6%).Licence of any new weights or drafter: n/a, no weights.
Kernel contract, only when a GPU kernel is new or changed
zig/tests/cuda/contract_flashnext_hcn.zig):fn_hcn_down2,fn_hcn_down3andfn_hcn_down4replacefn_hc_normalizethen the qmmf lane's fp32 down;fn_hcn_up3replaces the qmmf lane's bf16 up thenfn_hc_dense_mix. The replaced launches run on the engine's lane, with qmmf's BF16 prompt tiles loaded asTF_FLASHNEXT_PROMPT_BF16leaves 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.contract_hcn_controls.cuh, gate 3):tf_ctl_hcn_down3_rzrounds the normed rows toward zero and differs from byte 0;tf_ctl_hcn_up3_rawgates the up rows before their bf16 rounding and differs from byte 2.SUMMARYline and exit status: CUDA,tf-cuda-test kernel-contract fn_hcnon 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.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.