Repository navigation
qwen3 cuda: a 1-row call runs cuBLASLt's 1-row algorithm when 64 probe rows alone give the plan's bits (ASR decode 86.4 -> 141.3 tok/s) - #4734
Conversation
…alone gives the plan's bits Each (n, k) plan keeps its 4096-row algorithm for every row count. At 1 row that algorithm launches 4 to 16 CTAs on the GB10's 48 SMs and reads the weights at 60-160 GB/s, so Qwen3-ASR's decode, the pass's only 1-row caller, ran at 86.3 tok/s. A plan now asks cuBLASLt's heuristic for 8 algorithms at 1 row and keeps the first that runs in the workspace, splits no K and gives the plan's bits on 64 probe rows run alone: normals, wide exponents, subnormals and cancelling pairs, over probe weights of the plan's (n, k). Without one, 1-row calls run the plan's algorithm as before. cuda/one_row.zig (shared, beside cublaslt.zig) holds the pick and the probe, with host tests. gemm_test.zig (qwen3-cuda-gpu-test) checks 1 row against a batch of 64 for Qwen3-0.6B's pairs and plants a split-K candidate: other bits, refused, fallback. tf-qwen3-asr --check-one-row runs every projection on both algorithms and fails on a differing bit.
|
Thanks, @jschmied, for the carefully guarded one-row path and exact-bit controls. I found one cleanup issue. Once the initial row check succeeds, the plan’s checked-row hash map owns storage. If creation of the one-row plan or its probe then fails, the existing error handlers remove the plan and destroy its linear descriptor, but never deinitialize that hash map. Outer teardown cannot recover the storage because the plan has already been removed. Please add an error defer for the checked-row map immediately after initializing the plan value, before either fallible operation, so failed loads release it.
|
…s checked-row map plan() removed a failed plan and destroyed its linear descriptor but never deinitialized the checked-row map, which owns storage once the first row check succeeds; a failing 1-row pick or probe leaked it. An errdefer now frees it right after the plan value is set. gemm_test.zig fails every allocation of a fresh plan in turn: 3 leaks without the errdefer, none with it.
|
Done in How it was checked: a new test in |
|
Thanks, @jschmied. The checked-row map cleanup is now in the right place, and the allocation-failure test reaches the later probe allocations that exposed the leak. The cleanup order looks correct, with no double free. Two fallback cases still need attention. If the optional one-row heuristic cannot provide an algorithm or its setup fails, please keep the valid existing batch plan instead of failing model loading. The optional probe also needs a second full weight copy and output buffers—about 350 MB of extra GPU memory for the tied head—so an allocation failure can stop a model that otherwise fits. Please release partial optional state and fall back to the existing algorithm for these cases, with regressions proving the fallback and leak-free cleanup. The guarded dispatch itself still looks sound: batch calls stay on the original plan, and an admitted one-row candidate must match every probe row bit for bit.
|
No 1-row algorithm, a refused heuristic or setup, and a refused host or device probe buffer now log a warning, free the probe's partial state and leave 1-row calls on the plan's own algorithm; only a lost CUDA context still fails the load.
|
Done in Regressions in
A stubbed error status for the 1-row plan's own pick is not tested. The shared How it was checked: the same tests on |
|
Thanks @jschmied. Both fallback cases are handled on
That closes our review of the code, and nothing more is needed from you. The landing step is on our side.
|
|
sm_120 contract run on RTX 5060 Ti (independent of GB10), head bdd1c86.
No gate failures on sm_120; the limit diffs look like record-staleness on this arch. The 1-row pick itself is host-side and untouched by the contract kernels; no checkpoint available on this box for the qwen3-cuda-gpu-test oracles. |
|
Thank you @jschmied. The checked-row cleanup and optional heuristic/allocation fallback are in place, with queued probe work waited for before its buffers are released. The batch dispatch is preserved. The new sm_120 contract receipt is useful, but it uses the earlier head and does not exercise the one-row selection. Current-main exact projection and transcript checks, plus the skipped embedding and reranker checks, remain before landing. No further code change is requested from this review.
|
|
The clean trial merge of zig build test-qwen3-cuda-host check-native-cuda-host -Dfixed-cpu -j2 --summary all
zig build test-qwen3-checks-host qwen3-cuda-gpu-build tf-qwen3-asr -Dtarget=aarch64-linux-gnu -Dfixed-cpu -j2 --summary allFor the remaining device receipt, the embedding test needs Igor Lessio - AIFLOW LABS |
Head:
da5a6a91deon maina325f58258.Review 7104961514:
planfrees the checked-row map on error (errdeferright after the plan value is set, before the reference-row check and the 1-row pick). A newgemm_test.zigtest fails each allocation of a fresh plan in turn: 3 leaked allocations without the errdefer, none with it.qwen3-cuda-gpu-testonbdd1c86956: 26 passed, 2 skipped. x86 full set onbdd1c86956:zig build -Dfixed-cpu test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths2417/2417 steps, 24354/24511 tests (157 skipped);check-native-cuda-host compile-cuda-tests17/17; pr_check 0 errors; lean 165 vs 165, 0 new;zig fmt --checkandgit diff --checkclean. The other rows below are onc2f53e0e6c; this change touches only the error path.Review 7121441602: the 1-row algorithm is optional now. In
plan, any failure of the 1-row path logs a warning, frees the probe's partial state and keeps 1-row calls on the plan's own algorithm. That covers no 1-row algorithm, a refused heuristic or setup, and a refused host or device probe buffer. Only a lost CUDA context still fails the load. The probe synchronizes the context before it frees its buffers on an error path. Regressions ingemm_test.zig: (a) a stubbed 1-row heuristic finds no algorithm for the 1-row plan, or refuses or returns nothing for the candidate list; (b) each host allocation of a plan fails in turn (FailingAllocator), and the probe's failures now fall back without a leak; (c)setAllocationLimitrefuses each of the probe's four device buffers in turn. In each case the plan loads with no 1-row algorithm, device bytes return to their level before the plan, and 64 rows run one at a time give a batch's bits. Control: the same tests onbdd1c86956fail 3 of 3 (25 passed, 2 skipped, 3 failed).qwen3-cuda-gpu-teston0e2f6c8fd3(same code asda5a6a91de): 28 passed, 2 skipped. x86 full set on0e2f6c8fd3(da5a6a91dediffers from it by one test comment folded to one line):zig build -Dfixed-cpu test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths2417/2417 steps, 24272/24430 tests (158 skipped);check-native-cuda-host compile-cuda-tests17/17;zig fmt --checkandgit diff --checkclean. pr_check onda5a6a91de: 0 errors, lean 165 vs 165, 0 new. A stubbed heuristic that returns an error status for the 1-row plan's own pick is not tested: the sharedLinear.initlogs it as an error, and the test runner fails any test that logs an error. That path ends in the same fallback.Qwen3-ASR-0.6B decode on the GB10 goes from 86.4 to 141.3 tok/s (+64 %). That's above the 129.7 tok/s the family's own LM pass had before #2239 moved it onto qwen3's CUDA pass. Every token and every bit is unchanged: a 1-row call now runs a second cuBLASLt algorithm only after that algorithm has given the plan's own bits on every probe row.
Root cause
qwen3/cuda/gemm.zigkeeps one algorithm per (n, k), picked at 4096 rows, and runs it at every row count, so a batch's rows keep the bits they have alone. At 1 row that algorithm launches 4 to 16 CTAs on the GB10's 48 SMs and reads the weights at 60-160 GB/s. Qwen3-ASR's decode is the pass's only 1-row caller: the embedding and reranker engines run prompt passes.nsys, clip
1221-135766-0001, 60 decode tokens, per token:66d573976+ bench tool)Kernel2andnvjet 128x176tiles, 72 KB of shared memory, grids of 4 to 16 CTAs. The 28 layers' extra 136 us each make up the whole 3.8 ms gap.What changes
zig/src/cuda/one_row.zigis new and shared, besidecublaslt.zig. It holds the pick, the probe and their host tests.picktakes cuBLASLt's 1-row heuristic candidates in order. It passes over any that won't run in the workspace or that split K (refused before the probe runs), and any whose probe bits differ. It takes the first one left. With none left, nothing changes.The probe has 64 input rows, 16 of each kind:
The weights are N(0, 0.03), with one value in 512 an outlier of 1 to 8, repeated over the plan's [n, k]. Every output bit of all 64 rows, each run alone, must equal the plan's algorithm over the 64 together.
qwen3/cuda/gemm.zig, each plan probes once when it is built. Arows == 1call runs the taken algorithm, and every other call is as on main. The load log names the pick for each (n, k).cublasLtMatmulAlgoConfigSetAttribute, used by the planted control.On the GB10, all six Qwen3-0.6B (n, k) pairs take a 1-row algorithm: the heuristic's candidate 1, 3, 3, 0, 4 and 1, the same picks an 8-row probe made. Loading the plans takes 0.17 s longer, the median over 40 loads.
Exactness
tf-qwen3-asr --check-one-rowruns each projection's rows on the other algorithm too and compares every bit. A 1-row call is checked against the plan's algorithm at 1 row, and each row of a batch against the 1-row algorithm alone. Over the 40 public clips (LibriSpeech test-clean 20, FLEURS cmn 20), every prompt pass and every decode step, all seven projections and the head: 1,423,589 rows compared, 0 differ, 40 of 40 clips PASS.cmn-10104380129516909856token 27,cmn-15324743446256875074) differ from the package at the same token with the same margin.qwen3-cuda-gpu-test,gemm_test.zig):gemm_test.zig:90): the 1-row heuristic's first candidate with K split 4 ways. Past the K-order check, the probe alone sees other bits (red,gemm_test.zig:106). The candidate the plan took passes the same probe (green,:112). Offered alone, the planted candidate is refused and no 1-row algorithm is set (:115). The 1-row calls then run the plan's algorithm, with a batch's bits (:121).one_row.zig):pickpasses over an unrunnable, an over-budget, a split-K and an other-bits candidate, in order. The split-K one never reaches the probe, and with none left it returns null.Other callers: Qwen3-Embedding served, against main
Qwen3-Embedding-0.6B (the size on disk) through
tensorfold-native serve. Maina325f58258(md5ceef9f7c) and this head (md547a3b403) took turns in the order main, head, head, main. The page cache was dropped before each start, and one server ran at a time. Each run made 20 requests: the card's 4 texts alone and batched, 10 one-token inputs alone and batched, and seeded ids of 2048, 8192, 16384 and 30000 tokens.Bytes: every vector's SHA256 is equal across all four runs (20 of 20 requests). Repeat requests didn't drift.
The 1-row path: each one-token input runs alone through the new 1-row algorithm. Its vector equals the same input's row in one batch of 10, which runs the plan's algorithm, in every run on main and on head. The embedding server's load log takes the same 1-row picks as ASR (1, 3, 3, 0, 4).
Prompt passes, paired (head − main), median over 3 requests in each run:
4 of 8 pairs are slower on head, all within 0.07 %, and their spread includes zero. Runs of more than one row execute the same code as main. Server load is 2.0 s in all four runs.
qwen3-cuda-gpu-test's embedding and reranker checks skip here. Their oracle is pinned to Qwen3-Embedding-8B, and a reranker checkpoint isn't on this box either. The served bytes above against main stand in for them on the 0.6B.Seeded sampling, resume and concurrency don't apply here. Qwen3-ASR's CUDA path is greedy on one stream (
tf-qwen3-asr), and the embedding and reranker engines keep no decode state across requests. The change sits below them all, in which algorithm a 1-row projection runs, and its bits are the plan's. The served bytes and the 1-token-alone-vs-batched rows above cover the serving side.Speed: ASR decode, A-B-B-A, final head
tf-qwen3-asr, 40 clips (421.2 s of audio) per pass, passes ordered A B B A A B B A. A is maina325f58258(md5628c645a) and B is this head (md565acf5ef). The page cache was dropped first. The SM clock, sampled every second, read 2288 MHz in all 744 samples, with the same throttle word in both arms (the box's 2300 MHz cap) and no thermal or power throttle.e6094de13.66d573976, the family's own LM pass), decode was 129.7 tok/s. This PR restores that speed and goes past it.Checks on
c2f53e0e6cx86-steps.py --final) onc2f53e0e6c:zig build -Dfixed-cpu test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-pathsrc 0 (2,417 of 2,417 steps; 24,796 of 24,956 tests passed, 160 skipped, 0 failed);check-native-cuda-host compile-cuda-testsrc 0;tools/pr_check.pyrc 0;zig fmt --checkrc 0;git diff --checkrc 0; lean: 0 new problems (165 on the base, 165 here).zig build test test-golden test-cuda-host test-qwen3-cuda-host test-qwen3-checks-host test-qwen3-asr-host -Dnvccrc 0 (829 of 829 steps; 12,208 of 12,300 tests passed, 92 skipped, 0 failed).qwen3-cuda-gpu-testrc 0 (25 passed, 2 skipped: the oracle-pinned embedding and reranker checks).tf-qwen3-asr --check-one-rowon 40 clips: 40 of 40 PASS.Proposed CHANGELOG line (not committed):
- qwen3 cuda: a 1-row projection runs cuBLASLt's 1-row algorithm when 64 probe rows alone give the 4096-row plan's bits; Qwen3-ASR-0.6B decode 86.3 -> 142.1 tok/s on the GB10, tokens unchanged.