Repository navigation
gpu: Qwen3.8's decode selected flash merges under the out gate, one launch fewer a selecting layer - #1028
Conversation
…aunch fewer a selecting layer
There was a problem hiding this comment.
Verdict: CLEAN: No must-fix defect was found in the fused merge, its callers, or the updated graph counts.
Non-blocking
⚠ Run the extended hardware regression: crates/gpu/src/flash_gqa_prefill.rs:6372.
The reported commands omit just gate-gpu-lib, which runs the extended decode comparison.
Attach its output and a FAIL-first run with the gated merge passing Ungated. This checks rounding and named faults against the separate merge and gate before landing.
⚠ Complete the measurement evidence: crates/gpu/src/flash_gqa.rs:4699.
The description supplies card/driver prose, commit hashes and result summaries.
Attach the nvidia-smi output, exact model filename, and complete A/B commands with output beside those hashes. These make the reported launch-fusion result reproducible.
Checked
Duplicates: 3 new definitions checked; none duplicated. The merge reuses OutGate and SigmoidGate. Dryer reported 0 pairs; its excluded gpu-gates files were checked manually.
Complexity: enqueue_pass_256_p12_sel rose from 20 to 24 through gate-length validation and gated/ungated dispatch. Both paths retain the common merge body.
Silent failure: 3 paths followed. A short gate returns a named shape error. Invalid counts produce NaN and KeyCount. Non-finite gate products raise F32Product. Device faults reach Head::tokens as errors.
Tests: static mutation analysis only. Bypassing gate.apply at flash_gqa.rs:2753 breaks the bit comparison; removing the gate-length check at :7198 breaks the named-error assertion. Restoring 14 mixer launches at q38_fixture.rs:33 breaks both changed fixture tests.
Gates: graph-count and unsafe-ratchet changes have dated PIN reasons; numeric tolerances are unchanged. Launch-count arithmetic matches all four real-model pins.
Performance: decode launch fusion removes 1 launch and 49,152 bytes of intermediate traffic per selecting layer per token [derived: 24 heads × 256 values × 8 bytes]. No allocation, copy or synchronization was added.
Adversarial checks: short buffers, zero/out-of-range counts, NaN gates, and multiple slots are blocked by length checks, fault reporting, and sequence-local query/gate/output slices.
Escape catalog: no C1–C4 pattern matched.
Notes
CUDA builds and hardware gates were not run in this review environment. GPU evidence is incomplete under CONTRIBUTING.md's evidence list.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen35moe_attn.rs, crates/gpu-gates/src/bin/gate_qwen4exp_e2e.rs, crates/gpu-gates/src/q38_fixture.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)
|
The review is done and the contribution check passed, so I'm merging this. |
Qwen3.8 decode에서 selected flash의 merge가 out gate까지 한 번에 적용해, selecting layer마다 launch가 1개(토큰당 12개) 줄어듭니다.
Part of #565.
What and why
In Qwen3.8 decode, a selecting layer runs the selected flash merge and then a separate
gqa_out_gate_f32launch that multiplies the merge's output by the sigmoid of the query projection's gate. This PR addsgqa_flash_merge_256_gated, which writes each merged value through that gate in the same launch. A selecting layer goes from 14 launches to 13, which is 12 fewer per decoded token, and theArena38::flashbuffer that held the ungated output is gone.The gated entry reuses the existing
OutGate/SigmoidGatethat the prefill flash already uses, through agateparameter onmerge_body.Ungatedkeeps the plain merge unchanged. A refused row writes the gate applied to NaN, as before.End to end the effect is below what this measurement can separate: decode is +0.288% with the base and head ranges overlapping, and greedy output is identical. What the change lowers is the launch count and the time of the two launches it fuses, both under "What I ran".
Release notes: Under the hood: Qwen3.8 decode merges the selected flash and applies the out gate in one launch, 12 fewer launches per token.
Code shape
OutGate/SigmoidGatefromflash_gqa_prefill.rs; the decode merge takes it as a generic parameter instead of copying the product.program38.rsandscratch38.rsonly drop the separate gate launch and its buffer. The kernel change sits in the common flash code.qsa_out,Arena38::flashand the gate launch of the decode path are removed, and the launch counts and gate pins that moved are updated.NODES_DECODEand the fixture launch counts, the unsafe ratchet, the new entry's PTX shape rows) carryPIN(2026-10-30):and the reason. No band or tolerance moved.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line): none.What I ran
All GPU runs are on a DGX Spark. The PR head is
93d883929424f4e225f614e274ad17e3787aa494on main9fa4e0036cea9712f683a3443593031429de3bf3. The A/B and the first two gates ran on head2b5cc298c0b55a3b0aa9aaf3d33851dac1ca89d9on main989d0106b36ca2141adf5d506c3ebdef0c86a1c9,gate-ptx-spillon the PR head, and theq38_fixturetest on headf133b63864b24704b4551d25b416848f0d8cd4cf.Decode A/B against main, FP4-Local Qwen3.8 with the draft off, one sequence, a 4096-token prompt and 128 decoded tokens, q8 KV (the default), three rounds per arm in alternating order:
Greedy output is identical between base and head.
Launches and kernel time over the 128 decoded tokens, from the same run: the merge and the out gate took 3.947 ms and 1.804 ms in 1536 launches each on the base, and the gated merge takes 4.282 ms in 1536 launches on the head, so the two together fall from 5.751 ms to 4.282 ms. The segment kernel is unchanged (23.607 ms on the base, 23.747 ms on the head). Total launches fall from 161,163 to 159,627, which is 12 per token.
GPU gates on the same patch:
just gate-gpu-minimaxm3-msa: rc 0, 36 PASS lines, 0 FAIL,gate_minimaxm3_msa: PASS. The selected flash lines includeflash every block kept ... selected = dense group-16 pass bit for bit true PASS.BLOOMERY_TIER=fixture just gate-gpu-qwen4exp-e2e: rc 0, 185 PASS lines, 0 FAIL,clauses: 27 ran, 9 left to the real tier. The decode graph holds 111 nodes (structure decode graph_nodes=111 (want 111; ...) PASS), and five eager steps against five graph replays give logits bit for bit true.just gate-ptx-spill, withgqa_flash_merge_256_gatedpinned at spill 0 and jit_local 0:generate_ds41 entries=499 pinned=499andgate_qwen3vl_tower entries=26 pinned=26 ... violations=0 PASS.cargo test --release -p bloomery-gpu-gates --lib -- q38_fixture:test result: ok. 2 passed; 0 failed.Hardware (if the change is for a machine)
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.