Repository navigation
flashnext cuda: the MTP head's fc_h lane is sized for its own part rows - #4801
Conversation
|
Thanks @BadAd84. The fix covers the missing One small correction to the description: at 65,536 rows,
|
|
sm_120 cross-check (RTX 5060 Ti, live), head
|
partRows sized the pass scratch's part for two consumers: an out projection's slice plus the zero slice at cap rows, and a legacy lane tile's out_sk slices below 64 rows. The MTP head's fc_h lane is a third one. It runs over streams * rows rows (four streams by a pass's rows), and the lane writes one fp32 slice of them and zeroes a second, so it needs 2 * streams * rows rows of part. cuda_tiles.matmul zeroes at part + m rows and cuda_batch_ops.sumSlices then reads that slice back, so a head pass over more than cap / 4 rows leaves part: at four streams and a 256-row piece the lane needs 2,048 rows, against 2 * cap below a 1,024-row scratch, and 4 * cap while the piece is half the scratch. A head pass takes at most piece_rows rows (cuda_mtp_ops.zig's forwardHead and headGroup), so any pass over 63 rows can ask for more than part below a 1,024-row scratch. The single-stream path, whose piece is half the scratch, first overruns at 128 rows, a prompt chunk of about 128 tokens, and runs short to 1,023. partRows now takes the maximum over every consumer, the head's term being 2 * streams * min(cap, piece_rows). The term changes nothing from a 1,024-row scratch up, where the out projection's two cap-stride slices already dominate, so a long cache's part keeps its 671,088,640 bytes at 32,768 rows. Below that it costs at most 15,728,640 bytes, at 256 rows. The host test sweeps every cap against each consumer's write range, with the head's lane under both a reachable pass and the widest pass the lane admits.
1c06f68 to
c470307
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
partRows(cap)sizes the Flash Next pass scratch'spartfor the out projection and the legacy lanetile. The MTP head's
fc_hlane is a third consumer it did not size for, so from a 128-rowscratch up to 1023 the head's zero slice started past the end of
part. The branch adds thehead's term, one private function named after that consumer; nothing else changes.
The arithmetic, all of it in the tree:
partRows(cap)wasmax(2 * cap, out_sk * min(cap, 63))without_sk = 8;forwardHeadtakespiece = max(1, min(256, s.cap / 2)); the lane runsstreams = 4rows per pass rowwith
fc_sk = 4slices and writes one fp32 slice plus a second, zeroed one, so it needs2 * streams * piecerows. At a 128-row scratch the piece is 64 rows, so the lane needs512 rows against the 504 the old term gave (the reverted-tree run prints the same pair: it
needs 512 and is given 504); at 1,023 it is 2048 against 2046,
and from 2048 rows up
2 * capcovers the 2048 the lane asks for.partisdims = 2560fp32 a row, so 10240 bytes a row: at 65536 rows the head's termis inert and
partstays at 671088640 bytes, so a long cache pays nothing, and the largest cost ofthe change is 15728640 bytes at a 256-row scratch.
Fixes #4800, the bug report this pull request carries: no matching report existed on this tracker(searched
partRows,fc_h,flashnext scratch,MTP head scratch,CUDA_ERROR_INVALID_VALUE flashnext,cuMemsetD8Async; the one hit, dsv41: one request does not repeat bit for bit on one boot (main) #2715, is the DeepSeek-V4.1 bit-repeatability report), so Flash Next on CUDA: a 128 to 1,023-token prompt with drafts on writes past the MTP head'spart#4800 is that report.The change completes the defect, so
Fixesapplies.main, gated at 7bd7081, where every check below was run. Main has moved past that tipsince (556094f at the time of writing), and none of its commits since touches
zig/src/families/flashnext/, so this one commit still applies to main's tip; posting re-seats it only if themaintainer asks for a rebase, and a re-seat re-runs these checks.
atc overlap --json, run on this head from a full clone withmainfetched first: the snapshot is partial(
complete: false; limitationsotherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit). Against upstream main at 7bd7081, whose merge basewith this head is 7bd7081, it counts this commit's 2 changed files and lists
40 open pull requests: 2
conflicts, 8cleanand30
unknown, the last explained by itspullFilesUnavailablelimitation. None of thoseconflicts is this change's, measured rather than assumed: the GitHub API's full file list for every one of
the 40, page by page, contains neither of our two files (0 of
40 share either). Those 40 are the truncated list its
pullRequestsLimitnames, sothe complete set was measured the same way: 9 of the 413 open pull requests change
cuda_scratch_sizes.zigand none changes the test file, and none of the 9 editspartRows'sbody or the head's term, 7 of them adding a
partRowsForformat dispatch beside it and therest extending
Sizes. The tool attaches this work to the existing open pull request Flash Next on CUDA: TF_FLASHNEXT_MTP_WEIGHTS selects how the drafter keeps its BF16 linears #3218from the same account, because this branch has no pull request yet, so the snapshot's per-entry
sharedFilescounts are Flash Next on CUDA: TF_FLASHNEXT_MTP_WEIGHTS selects how the drafter keeps its BF16 linears #3218's files against the others, not this change's. Re-run it on the head at posting.
Checks on this head
Head commit: 1c06f68, tree 86ef754445071f1373c9dc5f265dd57bd6899d99, 2 files, 133 insertions,
2 deletions, signed.
Lean checker,
python3 tools/zig/lean_check.py, on the base and on this head: base 7689files and 165 problems, head 7690 files and 165
problems, and
tools/zig/lean_new.pyreads165 problems, 165 on the base, 0 new. The twolean_check.pyruns exit 1because the tree carries its standing findings; the gate is the pair.
Tests run, with the command and pass, fail and skip counts:
zig build test-cuda-hostBuild Summary: 474/474 steps succeeded; 8673/8715 tests passed (42 skipped); the Flash Next module's binary ran 316 of 316partRowsreverted (anchor count 1, base body line 1)Build Summary: 472/474 steps succeeded (1 failed); 4936/4968 tests passed (31 skipped, 1 failed); the same binary ran 315 pass and 1 fail of 316zig build test-flashnext-mtp-plan-hostzig build test-environment-hostzig build -Dfixed-cpu test-gradient-serving test-qwen-serving-hostzig build -Dfixed-cpu test-kernel-contractzig build -Dtarget=aarch64-linux-gnu compile-config-serverBuild Summary: 8/8 steps succeededzig build -Dtarget=aarch64-linux-gnu compile-cuda-testsBuild Summary: 10/10 steps succeededzig build -Dnvcc=<toolkit>/bin/nvcc compile-cuda-testsBuild Summary: 183/183 steps succeededzig build -Dnvcc=<toolkit>/bin/nvcc -Dtarget=aarch64-linux-gnu compile-cuda-testsBuild Summary: 183/183 steps succeededzig build -Dnvcc=<toolkit>/bin/nvcc -Doptimize=fast fatbins install nativeBuild Summary: 367/367 steps succeededzig fmt --check build.zig zigpython3 tools/zig/cuda_common_check.pycuda common: 55 local copies, 0 violationspython3 tools/zig/cuda_fragment_check.pycuda fragments: 2 fragments, 15 includes, 0 missespython3 -m unittest discover -s tools/zig -p cuda_common_check_test.pypython3 tools/test_pdl_early_loads.py -vpython3 pincheck.py <tree>/files 169 failing 0python3 tools/pr_check.py --base 7bd7081e061ca22e3431d2342cd66104dd5fe320, run from this branch's worktree: rc 0 in7 s,
merge base 7bd7081e061ca22e3431d2342cd66104dd5fe320; 2 changed files; lean 165 vs 165, 0 new, 0 error(s), 1 warning(s), the warning beingits
--pr NUMBERCHANGELOG advisory.CI: not yet run. The branch is pushed for this pull request and no workflow has reported at this head; the host
gates above are the ones this change reaches, run on a fresh
git archiveof the head whose every blob waschecked against the commit (2 files differ from main, and the tree verified with no mismatch).
The sweep itself, caps 32 to 4,095 plus 4,096 to 262,144: 896 caps short on main's sizing, from
128 to 1023, and 0 caps short after the change, over every consumer's
write range (the out projection, a legacy out lane, and the head's lane at both its reachable and its widest
pass).
Not run, and why: a device run, which is the only place the failure itself can be reproduced and the
drafted-versus-plain comparison made (see the receipt). The
atc overlapsnapshot above is partial, and it isre-run on the head at posting.
Receipt
Main against branch: the head test is the measurement this change turns on. On main's
partRowsthe newtest fails by name:
short at 896 caps, 128 to 1023, withfirst cap 128 needs 512 rows, partRows gives 504; on the branch it passes and the samebinary runs 316 of 316 tests.
Boxes it reaches: the same Flash Next CUDA path on any box, since the allocation is host code; no per-box
difference.
New switch? None.
partgrows only where the head's term exceeds the out projection's, and from a2048-row scratch up the term is inert.
Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and
revision: head 1c06f68; Zig 0.17.0; CUDA 13.3 (V13.3.73); one x86_64 machine with 16 threads running the
host gates, and nvcc 13.3 compiling the CUDA tests for x86_64 and cross-compiling for aarch64-linux-gnu;
checkpoint n/a, because no kernel, record or launch changed and the gates are host tests.
Paths and platforms the change reaches, which I ran and which I could not: the Flash Next prompt pass and
the MTP head, on the host tests listed above for x86_64 and aarch64; the CUDA device path is the one I could
not run.
Exactness, from
tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false:n/a on the host. The sizing change leaves every kernel and every arithmetic path as it was; only the
allocation grows, so a device run is the one that proves a drafted reply equals its
"draft": falsetwin(see below).
Main against this branch, same machine and checkpoint, posted before asking for a run on our machines:
not measured on a device. The host-side measurement above is the whole of what this change moves.
Decode speed before and after, from
tools/bench_openai.py: n/a, no kernel or launch changed. The branchchanges an allocation size, and on a served chunk of 3,072 rows the size does not change at all.
Prompt speed before and after: n/a for the same reason. The cold first request's
ttft_scannot move from ascratch allocation whose byte count is unchanged at the served chunk.
Licence of any new weights or drafter, or "n/a": n/a, no new weights or drafter.
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 equalssolo: unticked, because it takes the device run this pull request asks for. The change alters no
arithmetic, so the risk it changes a reply is nil, but the claim needs that run and I will not tick it
without it.
No precision traded for speed. If the bits change, the description says which sums change and why:
no bits change.
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: unticked, because no device measurement wastaken. The allocation is unchanged at the served chunk, which is why no host gate shows a difference.