Repository navigation
gpu, gpu-gates: Qwen3.8's MTP store walk projects and appends the keys and values alone - #765
Conversation
…s and values alone A store walk (the prompt's warmup) keeps a row's keys and values and nothing else of it, yet it projected each row's query and gate and normed and turned the queries. It now runs the k and v GEMMs over the mix and the head-256 append at no query head, which turns the keys and appends both planes bit for bit as the launch with its query heads does. The partial-turn launchers take n_head 0 as the key heads alone; gate_qwen35moe_attn's rope clause holds that launch to the full one's keys and planes and to writing no query. The store walk's arena drops its query rows and turned queries, 4,718,592 B at its 64 rows: the append's unread query arguments are the live walk's buffers. place::mtp_arena_bytes counts 4,718,592 B less, and the Qwen3.8 plan pins that hold the draft's reserve (the drafted card plans, plan (b') with the draft and the largest drafted context) move with it.
There was a problem hiding this comment.
Verdict: CLEAN: No merge-blocking defect found in the keys-only store walk or its arena accounting.
Non-blocking
⚠ Complete the hardware evidence: crates/gpu/src/arch/qwen3moe/mtp38.rs:2517. This changes launch count and append geometry. The timings cover an earlier patch and base; the gate logs omit the tested head hash and concrete model path. Attach both tested hashes, the model path, owning-gate output and a current-head A/B on the contributor's card. This makes the claimed gain reproducible.
Optimization headroom
- G. Per-launch and per-sync fixed cost: crates/gpu/src/arch/qwen3moe/mtp38.rs:2467. Reuse the two dense routing tables when successive
store_rowscalls have the same total row countm. Their existingfilled()state can avoid two launches per repeated 64-row call, or 1/32 launch per prompt token [derived].
Checked
Duplicates: 1 new function checked by Grep; no duplicate owner. Dryer reported 0 pairs; GPU and GPU-gates were searched manually.
Complexity: crapper flagged no changed function.
Silent failure: 1 new error arm followed; a refused launch returns false and makes the gate fail.
Tests, source mutation audit: restoring zero-head rejection at crates/gpu/src/rope_neox.rs:2008 fails the new clause. Restoring the old arena term at crates/model/src/arch/qwen35moe/place.rs:1063 fails the formula, Q4/Q3 card-plan and tier-plan assertions.
Gates: arena, planner and unsafe-count changes have dated PIN reasons; no tolerance moved.
Bounds: zero-query blocks access only key heads; short query buffers, block offsets and invalid cache positions were traced through the shared kernel.
Escape catalog: no C1–C4 pattern matched.
Notes
Static review only; no build or GPU gate was run here. The submitted GPU gates exit 1 on clauses the author reports also failing on base. The submitted evidence does not meet the complete GPU-evidence list.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen35moe_attn.rs, crates/gpu/src/arch/qwen3moe/mtp38.rs, crates/gpu/src/rope_neox.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
Filed outside this PR: #767
|
The review is done and the contribution check passed, so I'm merging this. |
Qwen3.8 MTP draft의 prompt 준비 단계에서 아무도 읽지 않는 query와 gate 계산을 빼고 key와 value만 계산하게 해서, GB10의 prefill 시간을 조금 줄이는 작업입니다.
Part of #565.
What and why
Qwen3.8's MTP draft keeps its own key/value store. While a prompt is prefilled, a store walk runs the draft layer over blocks of up to 64 prompt rows and appends each row's keys and values to that store. A later row reads the keys and values of earlier rows and nothing else, so no part of a store walk reads its query side. The walk still projected the query and the per-head gate (a
2560 x 12288weight, 4.03 GFLOP per 64-row block), normed and turned the queries, and wrote them into a buffer nothing reads.This PR makes the store walk compute the keys and values alone:
Mtp38::store_rowsquantizes the mix for thekandvweights only and runs two attention GEMMs instead of three.Mtp38::append_storecalls the head-256 norm, rotation and append launch withn_head: 0. Atn_head0 the launch handles the key heads alone: it reads no query source and writes no query. The query and gate window arithmetic is gone from that function.partial_launchincrates/gpu/src/rope_neox.rsacceptsn_head0. The five launchers that use it run the same device body (norm_partial_append), which splits its blocks into query and key heads byh < n_head, so atn_head0 each block takes one key head. No kernel code changes. The other launchers keep refusingn_head0.gate_qwen35moe_attngets a clause, "rope keys alone", that runs the existing rope clause's inputs atn_head0. It requires the keys and both cache planes to equal the launch with 16 query heads bit for bit, the query buffer to stay at zero bits, and no fault.tools/unsafe-ratchet.txtraises gpu-gates from 103 to 104unsafeblocks under aPINline for the clause's one launch.StoreArenano longer holds theqgandqbuffers, 4,718,592 bytes at its 64 rows (64 x (12,288 + 6,144) f32 x 4 B). The append's query arguments are the live walk arena's buffers, which the launch does not read at no query head.mtp_arena_bytesincrates/model/src/arch/qwen35moe/place.rscounts those bytes out: 53,526,700 to 48,808,108 bytes at the 248,320-row head. The Qwen3.8 plan pins that depend on it (CARD_PLANS,CARD_PLANS_Q3,BP_DRAFTEDandCARD_MAX_CTX_MTP) move with it under datedPINlines.Release notes: Changed: on GB10, Qwen3.8's MTP prompt preparation computes only the keys and values it stores, which trims prefill time, and the draft's arena is 4,718,592 bytes smaller; outputs are unchanged.
Code shape
partial_launch. The new gate clause reusesrope_gate::run,rope_run,bits_equalandverdict.partial_launchstill refuses zeron_kv,ctxormandm > ctxby name; onlyn_head0 is now accepted, with its meaning in the doc ofPartialNeoxArgs.tools/check-comments.shis ok.PIN(2026-10-24)line andSAFETYcomment. The plan pins that follow the smaller arena each carry aPIN(2026-10-24)line with the derivation.cargo fmtandcargo clippyare clean on what I touched:cargo fmtis clean,cargo clippyhas not run on this head.Duplication found or removed (
path:line): none.What I ran
Output is unchanged
In the timed run below, the greedy output of 128 tokens hashes the same on head and main for every arm and prompt. The draft counts differed in one place: the second prompt of the round 2 main arm drafted 102 tokens where the other five arms drafted 103, with the same 84 accepted. The default MTP width is chosen from measured pass times, so those counts move between runs of the same binary. A separate run on a second DGX Spark fixed the width (
BLOOMERY_MTP_WIDTH=fixed) on both checkpoints, so that the draft side is compared on equal terms. It is an output check only, not a timing: FP4-Local drafted 105, 117 and 105 tokens with 90, 89 and 93 accepted on head and on main, and NVFP4 drafted 105, 126 and 105 with 90, 85 and 93 accepted on both. The token hashes match per prompt in each pair.The store walk's own clauses in
gate_qwen4exp_mtpprint the same numbers on head and main: keys within 7.148e-3 and values within 6.997e-3 of the eager walks underAuto, 7.226e-3 and 7.338e-3 underPass, and the warmup stores the host's 64 rows as given.GPU evidence
The gate runs used an RTX 5090 (built for sm_86) at the head's arena change (the patch is equal to this head):
The first line is the smaller
StoreArenamatching the plan's new byte count exactly. The gate exits 1 on head and on main for one clause:(kp-draft)fails with "the checkpoint at 85 was evicted by the host budget" in both runs.This gate exits 1 on head and on main for one reason: its fixture-oracle clause needs the
fx_ref_qwen35moereference set, which is missing on that machine. The clauses above it pass.The timing machine, a DGX Spark (GB10), reported:
Plan pins
The RTX 5090 machine ran the plan tests on the head's code. Without the pin changes, only the arena change in place,
hw_qwen4exp_card_plan(8 rows),hw_qwen4exp_q3_card_plan(6 rows) andhw_qwen4exp_bp_mtp_plan(2 rows) fail. Withmtp_arena_bytesalone put back to its old value in a copy of the same tree, all three pass, so the failures come from the arena change and nothing else.cargo check -p bloomery-gpu -p bloomery-gpu-gates --all-targetsreports no warning and no error.hw_qwen4exp_mtp_specandhw_qwen4exp_mtp_planopen the unshared draft file, which that machine does not have, so they do not run to the end here. ForCARD_MAX_CTX_MTPI ranhw_qwen4exp_mtp_planin a temporary copy that points it at the shared draft file. It printed "A6000 with the draft holds ctx 1213983 (true; predicted 1213982) and breaks with CardOver at 1213984 (true): PASS" and the same for the 3090 (ctx 380583, predicted 380582). The same copy with the old arena value passes under the old pins.FAIL-first
With
partial_launchmade to refusen_head0 again, the new clause prints "rope keys alone: the launch at no query head refused" withFAIL,rope-256printsFAIL, and the gate exits withMUTANT-RC refuse-n_head-0 1. The tree was clean after the run.Speed
One DGX Spark (GB10), Qwen3.8 FP4-Local, default
sm_121abuild of both trees, MTP on (BLOOMERY_DRAFT=mtp), C = 1. Each request is one of three 4096-id windows of a code corpus (offsets 0, 4096 and 8192) with 128 greedy tokens (/completion, temperature 0,top_k1,cache_promptfalse). Each arm started a fresh server and sent the three requests; the clock cap was lifted for each arm and restored after. One discarded warm load of the main binary came first, then the arms ran in the order head, main, main, head, head, main, so each tree has three arms. Reproduce withBLOOMERY_DRAFT=mtp BLOOMERY_HOST_ROOM=96G target/release/bloomery-serve -m <model dir> --host 127.0.0.1 --port 18674 --parallel 4 --ctx-size 16896, built withcargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve. Main is100c224fc.Delta (head against main): median prefill +0.68% (1474.7 to 1484.8 tok/s) and median time to first token 19.0 ms lower (2782.2 to 2763.2 ms) over three rounds on one machine, with the head's first-start round 3.7% slower than main; one sitting, so a single observation, and a gain under 1%.
Round 1 is the head binary's first server start on that machine. Its load took 244.8 s against 230.2 s and 232.8 s for the other two head arms, and two of its three requests ran at 1,420.7 and 1,405.8 tok/s, which sets that round apart from every other arm. After that first start, the two later head arms were ahead of all three main arms on each of the three prompts: prefill +0.88, +0.75 and +0.91 %, time to first token 23.9, 20.9 and 25.3 ms lower. Decode is the same within the run-to-run spread. The read probe measured 231.2 to 238.8 GB/s in every arm, so the card was in the same state throughout.
The kernel time behind this, from one profiled 4096-id request with MTP on (Nsight Systems, an
sm_121build of an earlier commit of this patch): the BF16 GEMM at grid 96 took 122.20 ms in 163 launches on main and 97.41 ms in 97 launches on head, and the store walk's append kernel took 1.01 ms at grid 1,664 on main and 0.23 ms at grid 128 on head, about 25.6 ms less GPU time in all. Preparing the MTP prompt cost 78.81 ms of kernel time on main (MTP on against MTP off), so about 53 ms remains. The 19.0 ms gain in time to first token is smaller than the 25.6 ms of kernel time removed, and I have not isolated the difference.Measured head
The timings are for the patch without the arena change, over main
100c224fc. The arena change touches an allocation and the unread query arguments only, not a launch, copy or sync, so the device code is the timed code. Main has moved since, including a change to the BF16 prompt-site activation copy that the store walk's GEMMs also use, so the time saved there may differ on the newer main. I did not repeat the timings on it.Hardware
DGX Spark (GB10), driver 595.84, CUDA 13.3, Qwen3.8 FP4-Local for the timings and Qwen3.8 FP4-Local and NVFP4 for the fixed-width output check. The gate clauses and plan tests ran on an RTX 5090, driver 595.99.02, CUDA 13.2. The
nvidia-smilines are under GPU evidence.What I ran into
None of this blocks the PR.
hw_qwen4exp_mtp_specandhw_qwen4exp_mtp_planunmodified (see Plan pins); a timed A/B on NVFP4, because the store walk does not depend on the weight format and NVFP4 was checked for output only;ptx-compare, because no kernel code changed, only the host's launch arguments; and the gate's fixture-oracle clause, whose reference set is missing.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.