Skip to content

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

Open
jschmied wants to merge 7 commits into
ashhart:mainfrom
jschmied:qwen3-one-row-gemm
Open

jschmied wants to merge 7 commits into
ashhart:mainfrom
jschmied:qwen3-one-row-gemm

Conversation

@jschmied

@jschmied jschmied commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Head: 34c7464864 on main a325f58258.

Review 7373913212: compare checks bit-equality with the plan's algorithm, which main runs at every row count. It doesn't check correctness on its own, and its doc line (gemm.zig:104) now says so. A planted control (gemm_test.zig:344) installs the existing split-K candidate as the 1-row algorithm past the probe, and check mode counts its rows as differing (differ > 0 of 128). The taken algorithm counts 0 of 128. qwen3-cuda-gpu-test on 5b64a28a3d: 31 passed, 2 skipped. The 11-26 CI zig failure was test-gradient-serving's pins of cuda/cublaslt.zig and cuda/root.zig, which this PR edits. Both are updated in gradient-serving.tsv (3cbdaa4b27, 34c7464864). x86 on 5b64a28a3d: the full set (2417/2417 steps, 24899/25058 tests, 159 skipped), check-native-cuda-host compile-cuda-tests 17/17, pr_check, fmt, diff-check and lean 0 new. Only the gradient step was red, on root.zig. On 34c7464864, test-gradient-serving test-qwen-serving-host test-glm-pdl-scan pass 11/11. tools/perf_receipt.py can't drive this claim: it times chat completions on tensorfold-native serve, and the only 1-row caller is tf-qwen3-asr's decode. The A-B-B-A below stands for the receipt.

Review 7178949344: the check-mode compare (errdefer s.synchronize() catch {} after defer other.free()) and probeSame (errdefer context drain after defer pr.deinit) now wait for queued launches before freeing their temporary buffers on an error, as oneRowFrom does. Two new gemm_test.zig tests refuse the second launch after a real queued one and record the driver's syncs and frees. Red on da5a6a91de: only frees ({ .free }, { .free x4 }), 2 failed. Green on b3a1308eed: { .sync, .free }, { .sync, .free x4 }, qwen3-cuda-gpu-test 30 passed, 2 skipped. On a local merge into current main 920fe22c97 (not pushed): qwen3-cuda-gpu-test 30 passed, 2 skipped; tf-qwen3-asr --check-one-row 1,423,589 rows compared, 0 differ, 40 of 40 PASS, all six (n, k) on a 1-row algorithm (no fallback shapes). Oracles on the same merge with -Dfatbins: 32 passed, 0 skipped; Qwen3-Embedding-8B cosine 4.7e-5 to 1.08e-4 (limit 2.0e-4), batch == alone bits; Qwen3-Reranker-4B worst |diff| 0.1341 (gate 0.25), |score| 0.01664 (gate 0.02), packed == alone. GB10 test-qwen3-cuda-host 22/22. x86 (x86-steps.py --final) on b3a1308eed: zig build -Dfixed-cpu test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths 2417/2417 steps, 24631/24790 tests (159 skipped); check-native-cuda-host compile-cuda-tests 17/17; pr_check 0 errors; lean 165 vs 165, 0 new; zig fmt --check and git diff --check clean.

Review 7104961514: plan frees the checked-row map on error (errdefer right after the plan value is set, before the reference-row check and the 1-row pick). A new gemm_test.zig test fails each allocation of a fresh plan in turn: 3 leaked allocations without the errdefer, none with it. qwen3-cuda-gpu-test on bdd1c86956: 26 passed, 2 skipped. x86 full set on bdd1c86956: zig build -Dfixed-cpu test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths 2417/2417 steps, 24354/24511 tests (157 skipped); check-native-cuda-host compile-cuda-tests 17/17; pr_check 0 errors; lean 165 vs 165, 0 new; zig fmt --check and git diff --check clean. The other rows below are on c2f53e0e6c; 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 in gemm_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) setAllocationLimit refuses 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 on bdd1c86956 fail 3 of 3 (25 passed, 2 skipped, 3 failed). qwen3-cuda-gpu-test on 0e2f6c8fd3 (same code as da5a6a91de): 28 passed, 2 skipped. x86 full set on 0e2f6c8fd3 (da5a6a91de differs 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-paths 2417/2417 steps, 24272/24430 tests (158 skipped); check-native-cuda-host compile-cuda-tests 17/17; zig fmt --check and git diff --check clean. pr_check on da5a6a91de: 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 shared Linear.init logs 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.zig keeps 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:

old ASR pass (66d573976 + bench tool) main this PR
wall per token 8.50 ms 12.26 ms 7.53 ms
GPU busy 94.7 % 96.6 % 94.3 %
7 projections per layer (x 28) 173 us 309 us ~165 us
tied head (151936 x 1024) 1.90 ms 2.10 ms 1.36 ms
  • The GPU is busy in all three, so host syncs, launches and the host argmax are not where the time goes.
  • On main, every projection is the 4096-row pick: Kernel2 and nvjet 128x176 tiles, 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.
  • With this PR, the same projections run at grids of 32 to 96 CTAs, and the head runs at 4752.

What changes

  • zig/src/cuda/one_row.zig is new and shared, beside cublaslt.zig. It holds the pick, the probe and their host tests.
    • pick takes 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:

      • normals at 2^-4 to 2^3;
      • wide exponents from 2^-100 to 2^100;
      • half bf16 subnormals, half the smallest normals;
      • cancelling +v/-v pairs with zeros, plus an all-zero row and an all-one row.

      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.

  • In qwen3/cuda/gemm.zig, each plan probes once when it is built. A rows == 1 call runs the taken algorithm, and every other call is as on main. The load log names the pick for each (n, k).
  • The one shared-code edit outside the new file is one API symbol, 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

  • Real activations: tf-qwen3-asr --check-one-row runs 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.
  • ASR transcripts: in the A-B-B-A below, none of the 40 clips' greedy ids differ between main and this PR, over all 8 passes. As on main, the two FLEURS near-ties from qwen3-asr: host slice, the shared tower and Qwen3 schedules over a backend binding (#2105) #2239 (cmn-10104380129516909856 token 27, cmn-15324743446256875074) differ from the package at the same token with the same margin.
  • GPU tests (qwen3-cuda-gpu-test, gemm_test.zig):
    • For each Qwen3-0.6B (n, k), 64 fresh rows on another seed, run 1 row at a time, give a batch of 64's bits.
    • Planted control (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).
  • Host tests (one_row.zig):
    • pick passes 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.
    • The probe rows cover their classes and are the same at every load (seeded).

Other callers: Qwen3-Embedding served, against main

Qwen3-Embedding-0.6B (the size on disk) through tensorfold-native serve. Main a325f58258 (md5 ceef9f7c) and this head (md5 47a3b403) 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:

    request main ms head ms paired median
    2048 ids 631.7, 630.3 632.6, 630.3 +0.9, −0.0 +0.07 %
    8192 ids 8669.5, 8664.4 8671.1, 8668.8 +1.7, +4.4 +0.03 %
    16384 ids 33721.0, 33704.2 33717.6, 33719.5 −3.4, +15.3 +0.02 %
    4 texts batched 17.3, 15.9 16.0, 15.9 −1.3, −0.0 −3.8 %

    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 main a325f58258 (md5 628c645a) and B is this head (md5 65acf5ef). 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.

pass arm decode tok/s
1 A 86.4
2 B 141.1
3 B 141.3
4 A 86.3
5 A 86.3
6 B 141.5
7 B 141.3
8 A 86.4
  • main 86.3-86.4 tok/s, this PR 141.1-141.5 tok/s: +63.5 %. Before the rebase, the same change measured 142.1 against 86.3 on e6094de13.
  • Before qwen3-asr: host slice, the shared tower and Qwen3 schedules over a backend binding (#2105) #2239's final form (66d573976, the family's own LM pass), decode was 129.7 tok/s. This PR restores that speed and goes past it.
  • None of the 40 clips' greedy ids differ across any pass or arm. Prompt-pass, tower and mel times are untouched: the 1-row algorithm runs only on 1-row calls.

Checks on c2f53e0e6c

  • x86 (x86-steps.py --final) on c2f53e0e6c: zig build -Dfixed-cpu test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths rc 0 (2,417 of 2,417 steps; 24,796 of 24,956 tests passed, 160 skipped, 0 failed); check-native-cuda-host compile-cuda-tests rc 0; tools/pr_check.py rc 0; zig fmt --check rc 0; git diff --check rc 0; lean: 0 new problems (165 on the base, 165 here).
  • GB10: zig build test test-golden test-cuda-host test-qwen3-cuda-host test-qwen3-checks-host test-qwen3-asr-host -Dnvcc rc 0 (829 of 829 steps; 12,208 of 12,300 tests passed, 92 skipped, 0 failed). qwen3-cuda-gpu-test rc 0 (25 passed, 2 skipped: the oracle-pinned embedding and reranker checks). tf-qwen3-asr --check-one-row on 40 clips: 40 of 40 PASS.
  • No kernels are added or changed, so the kernel contract has nothing new to record. The planted control is the split-K test above.

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.

@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

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.

  • Synthena

@jschmied

Copy link
Copy Markdown
Contributor Author

Done in bdd1c86956: plan now has errdefer got.value_ptr.checked.deinit(g.gpa) right after the plan value is set, before the reference-row check and the 1-row pick, so a failed load frees the checked-row map.

How it was checked: a new test in gemm_test.zig fails each allocation of a fresh plan in turn (std.testing.FailingAllocator over the leak-checking test allocator) until the plan builds. Without the errdefer it reports 3 leaked 96-byte allocations (the checked-row map, from the failures inside the 1-row probe); with it, none. qwen3-cuda-gpu-test on the GB10: 26 passed, 2 skipped (the oracle-pinned embedding and reranker checks, as before). x86 full set on bdd1c86956: zig build -Dfixed-cpu test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths 2417/2417 steps, 24354/24511 tests (157 skipped); check-native-cuda-host compile-cuda-tests 17/17; pr_check 0 errors; lean 165 vs 165, 0 new; zig fmt --check and git diff --check clean.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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.

  • Synthena

@jschmied

Copy link
Copy Markdown
Contributor Author

Done in da5a6a91de. 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. On an error path, the probe now synchronizes before it frees its buffers.

Regressions in gemm_test.zig, each checking that the plan loads with no 1-row algorithm, that device bytes return to their level before the plan, and that 64 rows run one at a time give a batch's bits:

  • a stubbed 1-row heuristic finds no algorithm for the 1-row plan, or refuses or returns nothing for the candidate list;
  • each host allocation of a plan fails in turn (FailingAllocator): the probe's failures fall back with no leak, and only the map's two fail the plan;
  • setAllocationLimit refuses each of the probe's four device buffers in turn. The peak shows the earlier ones were held, and the refused one never was.

A stubbed error status for the 1-row plan's own pick is not tested. The shared Linear.init logs it as an error, and the test runner fails any test that logs one. That path ends in the same fallback.

How it was checked: the same tests on bdd1c86956 fail 3 of 3 (25 passed, 2 skipped, 3 failed). qwen3-cuda-gpu-test with the fix: 28 passed, 2 skipped. x86 full set on 0e2f6c8fd3 (da5a6a91de differs 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-paths 2417/2417 steps, 24272/24430 tests (158 skipped); check-native-cuda-host compile-cuda-tests 17/17; zig fmt --check and git diff --check clean. pr_check on da5a6a91de: 0 errors, lean 165 vs 165, 0 new.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. Both fallback cases are handled on da5a6a91de:

  • No usable 1-row algorithm: a missing algorithm, a refused heuristic or setup, or a refused probe buffer now logs a warning, frees the probe's partial state and keeps 1-row calls on the plan's own algorithm. Only a lost context still fails the load.
  • Cleanup: on an error path the probe waits for its queued runs before it frees its buffers.
  • Tests: the stubbed heuristic, each host allocation and each of the four device buffers are covered, and each case checks that device memory returns to its earlier level and that rows run one at a time still give the batch's bits.

That closes our review of the code, and nothing more is needed from you. The landing step is on our side.

  • Synthena

@joshuaswarren

Copy link
Copy Markdown
Contributor

sm_120 contract run on RTX 5060 Ti (independent of GB10), head bdd1c86.

tf-cuda-test kernel-contract Qwen3-ASR (queued run): 2/2 kernels pass gates 1-4, 1 limit problem (tf_vit_conv_cols 20 vs 22 recorded regs).

tf-cuda-test kernel-contract qwen3 Qwen3 (full family filter, same head): 15 kernels pass gates 1-4, 0 failures, 4/4 controls red as planted, 6 known findings, 20 limit problems — the sm_120 records for qwen35_bf16_rows, attn_partial_paged/contiguous and tf_q35k_apply_pend read 0,0 placeholders; small reg drifts elsewhere (tf_q35d_gather_rows 18 vs 20, tf_q35_tap 25 vs 26, tf_q35d_norm_rope_batch 40 vs 36). nvcc 13.5 images against the 13.3 record set.

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.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

The clean trial merge of da5a6a91de into 4c79cfe346 passed 22 Qwen3 CPU tests and five host oracle checks on M5 Max. The native adapter, the CUDA test binary, and tf-qwen3-asr all cross-compiled for ARM64 Linux.

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 all

For the remaining device receipt, the embedding test needs TF_QWEN3_EMBED_DIR, TF_QWEN3_EMBED_REF and TF_QWEN3_EMBED_BAR. The reranker test needs TF_QWEN3_RERANK_DIR and TF_QWEN3_RERANK_REF. For the ASR projection check, tf-qwen3-asr MODEL_DIR CLIP.wav --check-one-row reports rows compared only for plans that selected the alternate algorithm, so please retain the comparison count and note any fallback shapes alongside the new transcript result. I could compile those checks here. The cuBLASLt runs remain open.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Thank you for closing the checked-row ownership and optional one-row setup/allocation findings. The primary plan still fails correctly on its own errors, optional failures retain it with no leaked state, and one-row dispatch remains guarded by exact probe bytes. The branch also merges cleanly on current main.

The re-review found two analogous error-only cleanup paths in the diagnostic helpers:

  1. zig/src/families/qwen3/cuda/gemm.zig:106-111: during a batch --check-one-row call, a later p.one.run failure can free other while an earlier iteration still has a queued write into it. Add errdefer s.synchronize() catch {} immediately after defer other.free().
  2. zig/src/families/qwen3/cuda/gemm.zig:211-214: probeSame has the same queued-candidate/deinit ordering when Same.same fails before its success-path synchronization. Add the context-drain error defer immediately after defer pr.deinit(gpa).

A focused regression should make a second comparison or candidate launch fail and assert that synchronization precedes temporary-buffer release. This is the same lifetime pattern already fixed in oneRowFrom.

After those corrections, the remaining current-main gates are the real-activation ASR projection/transcript run with its exact comparison count and fallback shapes retained, plus the previously skipped embedding and reranker oracle gates executing rather than skipping. No rebase is requested.

  • Synthena

@jschmied

Copy link
Copy Markdown
Contributor Author

Done in b3a1308eed, both at the lines you named:

  1. gemm.zig:108: compare has errdefer s.synchronize() catch {} right after defer other.free(). A later refused p.one.run now waits for the rows already queued into other before it goes.
  2. gemm.zig:214: probeSame has errdefer _ = g.d.api.cuCtxSynchronize() right after defer pr.deinit(g.gpa), the same drain oneRowFrom has.

Regression. Two new GPU tests in gemm_test.zig (:301, :324). Each wraps cuBLASLt's cublasLtMatmul and the driver's cuStreamSynchronize, cuCtxSynchronize and cuMemFree_v2. The first launch of the path is real and queued. After it, the launched Linear asks for more workspace than any call gives, so Linear.run refuses the second launch with error.Invalid and logs no cuBLASLt error. The tests record what the driver sees after the refusal, and the first event must be a sync, with the frees after it.

  • Check mode: a 64-row run with a tally runs the batch's launch, then row 0 alone, and row 1 is refused.
  • probeSame: the plan's probe pass, then probe row 0 alone, and row 1 is refused.

qwen3-cuda-gpu-test on the GB10:

tree check mode, after the refusal probeSame, after the refusal result
da5a6a91de + the tests (red) { .free } { .free, .free, .free, .free } 28 passed, 2 skipped, 2 failed: the two new tests
b3a1308eed (green) { .sync, .free } { .sync, .free, .free, .free, .free } 30 passed, 2 skipped

Current-main gates. These ran on a local merge of b3a1308eed into current main 920fe22c97 (merge b1cade98fa, clean, not pushed). This is integrated current main, not a rebase of the branch. Main has since moved to 67ae36c4dc: the branch still merges cleanly, and nothing since 920fe22c97 touches qwen3/, cuda/one_row.zig, cuda/cublaslt.zig or the Qwen3 CUDA build.

  • qwen3-cuda-gpu-test: 30 passed, 2 skipped (the oracle checks; see below), with the same red/green order output as above.
  • ASR, real activations: tf-qwen3-asr --check-one-row on the 40 public clips (binary md5 d9e40605, built from merge a5ef344ed9, which is 3205de82d0 on 920fe22c97; b3a1308eed differs from 3205de82d0 only in one test's printed line). 1,423,589 rows compared, 0 differ, 40 of 40 PASS. That is the same count as on c2f53e0e6c.
  • Fallback shapes: none. All six (n, k) plans take a 1-row algorithm in all 40 loads: (2048, 1024) pick 1, (1024, 1024) pick 3, (1024, 2048) pick 3, (3072, 1024) pick 0, (1024, 3072) pick 4, (151936, 1024) pick 1. No load logs a probe failure or "no 1-row pick".
  • Transcripts: 38 of 40 equal the package byte for byte. The two FLEURS near-ties from qwen3-asr: host slice, the shared tower and Qwen3 schedules over a backend binding (#2105) #2239 (cmn-10104380129516909856, cmn-15324743446256875074) differ at the same token with the same margins as on c2f53e0e6c and on main.

Oracle checks, executing (same merge, qwen3-cuda-gpu-test -Dfatbins=<images from zig build fatbins -Dsm=121>): 32 passed, 0 skipped.

  • Embedding: Qwen3-Embedding-8B at the pinned 1d8ad4ca9b, against the fp32 CPU reference and its BF16 bar. The 9 inputs of 8 to 32,759 tokens have cosine distances of 4.7e-5 to 1.08e-4, under the limit of 2.0e-4. Each batch's rows equal the inputs' bits alone.
  • Reranker: Qwen3-Reranker-4B at the oracle's pinned 22e683669b, against a BF16 reference from tools/rerank/qwen3_reranker_oracle.py oracle (sources passed). Over 32 cases, the worst |diff| is 0.1341 (gate 0.25) and the worst |score| 0.01664 (gate 0.02). The packed decision of 32 branches (trunk 43) and the edge branches of 600, 513, 1 and 530 rows equal their runs alone.
  • Why they did not run before: on 11-23 the 8B check failed "without output" identically on head and main. Run directly, the test binary names the error: BuiltWithoutKernels. qwen3-cuda-gpu-test built with -Dnvcc alone embeds empty kernel images, and the check needs -Dfatbins. That was our build invocation, not a main bug. The reranker had no checkpoint here until now.

Other checks on b3a1308eed. GB10 test-qwen3-cuda-host: 22 of 22. x86 (x86-steps.py --final) on b3a1308eed: zig build -Dfixed-cpu test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths 2417/2417 steps, 24631/24790 tests (159 skipped); check-native-cuda-host compile-cuda-tests 17/17; pr_check 0 errors; lean 165 vs 165, 0 new; zig fmt --check and git diff --check clean.

@ashhart

ashhart commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Thank you, @jschmied. Both requested corrections are in place. compare drains the stream before releasing its temporary output, and probeSame drains the context before releasing probe storage. The two regressions queue real work, refuse the next launch, and check synchronization before freeing, so they exercise the original lifetime errors.

The earlier checked-map cleanup and optional fallback remain intact. One-row candidates still require exact probe bytes, and batch behavior is unchanged. Your integrated receipts also cover the embedding and reranker oracles with no skips, 1,423,589 ASR rows with zero differences, no fallback shapes and unchanged transcript baselines.

The code is ready. One step is ours before it can land: this changes the default CUDA path for Qwen3, and our landing rule asks for our own device run of the default path, but we don't yet hold a Qwen3 checkpoint on a CUDA box we can use. We'll post here once that is settled. When it lands, the CHANGELOG entry will be:

- Qwen3 CUDA one-row projections use a separately probed cuBLASLt algorithm only when it preserves batch bits, accelerating ASR decode without adding default rounding (#4734). Thanks to @jschmied.
  • Synthena

@ashhart ashhart added kind:perf Classified by Synthena as performance improvement synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 3, 2026
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Synthena Initial Review — Performance receipt required (kind:perf)

Adds an optional 1-row cuBLASLt algorithm per (n,k) plan, taken only when probe rows run alone reproduce the batch plan's bits, with a check-mode comparison path and fallback tests. ASR decode throughput improves from 86.4 to 141.3 tok/s.

  • Failing CI check(s): zig.
  • Performance claim detected without a verified tf-receipt-v1 receipt.

Performance PRs require a verifiable benchmark receipt before running project CI hardware. See CONTRIBUTING.md (Performance PRs: verifiable benchmark receipt) and attach the output of:

python3 tools/perf_receipt.py run --base-bin /path/to/base-tf --head-bin /path/to/head-tf --model /path/to/model.tfold --out receipt.json

Findings:

  • [WARNING] zig/src/families/qwen3/cuda/gemm.zig: In check mode with a 1-row algorithm, compare() runs the plan's algorithm at 1 row into a fresh buffer and downloads both outputs, but the 1-row algorithm's output y is only compared, never validated against a reference; a systematic error in the 1-row path would pass silently since both sides could agree on wrong bits only if the plan's algorithm is also wrong. Suggested fix: Acceptable as a check-mode control since the plan's algorithm is the reference; consider documenting that the check validates bit-equality, not correctness, against the batch plan.
  • Synthena

@jschmied

jschmied commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Head is now 34c7464864: three new commits on b3a1308eed, no rebase.

Check mode (the WARNING). That's right. compare checks bit-equality with the plan, not correctness on its own. A 1-row call runs the 1-row algorithm and then compare (gemm.zig:89-92). With rows == 1 it runs the plan's own algorithm at 1 row into other (:109) and compares every row's bytes (:121). A batch call runs the plan, then each row alone on the 1-row algorithm (:95, :109-111). The reference is the plan's algorithm: main runs it at every row count, and the transcripts and the embedding and reranker oracles check it. 5b64a28a3d says this in compare's doc line (:104). It also adds a planted control (gemm_test.zig:344). Installed past the probe as the 1-row algorithm, the split-K candidate from the existing control leaves rowsAgree false and gives red.differ > 0 over 128 compared rows. The taken algorithm gives { .rows = 128, .differ = 0 }. qwen3-cuda-gpu-test on the GB10 at 5b64a28a3d: 31 passed, 2 skipped (the oracle-pinned checks, as before), the new test included.

CI zig (11-26). It was ours. The DeviceLost lines are warnings from tests that pass. The one failure is test-gradient-serving: serving source changed: zig/src/cuda/cublaslt.zig, from the one added API symbol. The test stops at its first mismatch, and cuda/root.zig (the one_row export) was the second. 3cbdaa4b27 and 34c7464864 update both pins in gradient-serving.tsv, with the reason, as 52375ee098 did for #2285. On x86, 5b64a28a3d had everything green except that step, which still named root.zig: zig build -Dfixed-cpu test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths 2417/2417 steps, 24899/25058 tests (159 skipped), check-native-cuda-host compile-cuda-tests 17/17, pr_check, fmt, diff-check and lean 0 new. On 34c7464864: zig build -Dfixed-cpu test-gradient-serving test-qwen-serving-host test-glm-pdl-scan 11/11 steps, 4/4 tests; fmt, diff-check and pr_check 0 errors. The commits since 5b64a28a3d change only that fixture. Main has since changed cuda/root.zig and that fixture too, so the root.zig pin line now conflicts. On a merge it takes the merged file's hash. No rebase unless you ask for one.

Receipt. tools/perf_receipt.py can't drive this claim. It starts tensorfold-native serve and times /v1/chat/completions decode. The only 1-row caller of qwen3/cuda/gemm.zig is tf-qwen3-asr's decode, and the native server's qwen3 CUDA family serves only embedding and reranker checkpoints (native/cuda_qwen3.zig), which run prompt passes. The existing A-B-B-A stands in for it: tf-qwen3-asr, 40 clips per pass, A = main a325f58258 (the merge base), B = the PR as opened (c2f53e0e6c, md5 65acf5ef). The commits since change only error paths, tests, a comment and a pin. A: 86.4, 86.3, 86.3, 86.4 tok/s. B: 141.1, 141.3, 141.5, 141.3 tok/s. No greedy ids differ in any pass. The served Qwen3-Embedding-0.6B run against main (20 of 20 requests byte-equal, prompt passes within 0.07 %) is in the body.

@ashhart ashhart added synthena:needs-changes Reviewed by Synthena; changes requested and removed synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 3, 2026
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Synthena Initial Review — Needs changes (kind:perf)

Adds a shared 1-row cuBLASLt algorithm selection path for Qwen3 CUDA GEMMs, taking a 1-row heuristic candidate only when probe rows run alone reproduce the plan's bits, plus a check mode and tests. Claims ASR decode speedup from 86.4 to 141.3 tok/s.

  • Branch currently has merge conflicts against base.

Findings:

  • [BLOCKER] zig/src/families/qwen3/cuda/gemm.zig: The 1-row fast path is taken whenever a candidate was picked at plan build time, but the probe only validates bit-equality on synthetic probe rows at plan-build shapes; there is no runtime guard that the current (n, k) or workspace still matches, and a mismatch would silently produce wrong decode logits. Suggested fix: Verify the probe covers the exact (n, k) and workspace constraints of every runtime call, or add a runtime assertion/fallback when the 1-row plan's shape assumptions do not hold.
  • [WARNING] zig/src/families/qwen3/cuda/gemm.zig: The error-path synchronize is best-effort (catch {}), so on a context error the queued writes may still race the free of other; the comment acknowledges this but the failure mode is a silent use-after-free on the device. Suggested fix: Propagate or log the synchronize failure instead of swallowing it, or defer the free until after a successful synchronize.
  • [WARNING] zig/tests/qwen3_asr_cuda.zig: The check-mode gate requires tally.rows > 0, but if no projection ever runs with a 1-row algorithm (e.g. all plans fell back), the tool exits 1 even though nothing is wrong; the failure message does not distinguish 'no 1-row algorithm' from 'bits differ'. Suggested fix: Report a distinct status when tally.rows == 0 (no 1-row algorithm taken) versus tally.differ > 0, and only fail the run on actual bit differences.
  • [WARNING] zig/src/families/qwen3/cuda/gemm.zig: The fallback swallows all non-CudaContextLost errors with only a log.warn, so a probe failure (e.g. HeuristicRefused, OutOfMemory on device) silently degrades to the batch plan with no test asserting the warn path is exercised for each error kind. Suggested fix: Add a test covering each swallowed error kind, or narrow the catch to the specific expected errors and propagate unexpected ones.
  • Synthena

@jschmied

jschmied commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

On 34c7464864. The head is unchanged: I checked each finding against the code, and none needs a code change.

BLOCKER (shape and workspace guard). Every call already gets the plan of its own (n, k), and the probe ran at that exact (n, k) and workspace:

  • run takes the plan by the call's (n, k) (gemm.zig:88). Plans are keyed by (n, k) (:54, :143), so a 1-row call can't reach another shape's plan.
  • The 1-row Linear is built at (1, n, k) for that plan (:180). Its probe runs on one_row.Probe.init(.., n, k) at the same (n, k) (:193), against that plan's own algorithm (:196, :220-221).
  • The workspace is one constant, workspace_bytes. run passes it (:90), and Linear.run refuses a smaller one with error.Invalid before it launches (cublaslt.zig:194).

A mismatch therefore can't run silently. A guard that compared these values would compare a value with itself, so I didn't add one. What the probe can't cover is real activations: --check-one-row compared 1,423,589 real rows with 0 differing, and gemm_test.zig:53 checks fresh rows on another seed for every Qwen3-0.6B (n, k).

WARNING: catch {} on the error-path sync (gemm.zig:108, :214). An errdefer can't return a second error. The launch's own error still propagates. A failed synchronize means the context has a sticky error, and then it runs no more queued work, so nothing writes into other after that. compare exists only in check mode.

WARNING: tally.rows == 0 fails check mode (qwen3_asr_cuda.zig:202-203). That's deliberate. --check-one-row asks for a comparison, and a run that compared 0 rows checked nothing (the review on 11-25 asked us to keep the count). The line prints the count, so 0 rows compared ... 0 differ is easy to tell apart from N differ. The load log names each shape that fell back (gemm.zig:156, :199).

WARNING: the fallback catches every error except CudaContextLost (gemm.zig:152-159). Review 7121441602 asked for exactly that: keep the batch plan when the optional path fails. The kinds are tested:

  • the heuristic refuses or finds nothing (gemm_test.zig:170);
  • each host allocation fails in turn (:123);
  • each of the four device buffers is refused in turn (:199).

Each test checks that the plan loads with no 1-row algorithm, frees what it took, and still gives a batch's bits. The one untested kind is an error status from the 1-row plan's own pick: Linear.init logs it as an error, and the test runner fails any test that logs one.

Merge conflict: main changed cuda/root.zig and gradient-serving.tsv, so the root.zig pin line conflicts. It takes the merged file's hash. I'll rebase only if you ask.

jschmied and others added 7 commits December 5, 2026 03:20
…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.
…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.
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.
…ns before freeing on error

A refused later 1-row launch in the --check-one-row compare, or a failed candidate in
probeSame, now waits for the rows already queued before the temporary buffers go, as
oneRowFrom does. Two GPU tests refuse the second launch and check the sync comes first.
@ashhart
ashhart force-pushed the qwen3-one-row-gemm branch from 34c7464 to 2be5340 Compare December 5, 2026 03:20
@ashhart

ashhart commented Dec 5, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Author's exact-head GB10 qwen3 CUDA A/B (the files' device cell) is on the thread; QR35 re-check READY. Rebased on main 2866350 with cuda/root.zig re-pinned in gradient-serving.tsv; no code changed in the rebase.

  • Synthena

@ashhart ashhart removed the synthena:needs-changes Reviewed by Synthena; changes requested label Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:perf Classified by Synthena as performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants