Repository navigation
gpu: fold Qwen3.8's prompt card sum into the combine on layers without a host leg - #701
Conversation
There was a problem hiding this comment.
Verdict: CLEAN: No reachable behavior defect or proven quality defect remains in the changed code.
Non-blocking
⚠ Cover the later hostless route run: wide38.rs:1317. The new two-token check calls the launcher directly, so it cannot detect a lost c0 offset in either window. Extend the existing whole-card clause with a prompt longer than ROUTE_ROWS, comparing whole and cut walks. Replacing either offset with zero must fail; this keeps an indexing regression local to its cause.
⚠ Complete the measurement evidence: wide38.rs:1321. This is the “fold a launch into a neighbour” class. The body supplies GB10 gate output and timing tables, but neither measured commit hash nor the profiling and layer-timing commands. Add both hashes, the concrete model file identity, and the exact commands with output so the comparison can be reproduced.
Checked
Duplicates: 10 new definitions checked; no duplicated owner found. Dryer reported zero pairs in gpu; gpu-gates was searched manually. The new kernel reuses card_acc_at, and all three card combines reuse combine.
Complexity: check_hostless is new at 25, with equivalence and fault cases; CardRoute38::enqueue rises 38→44 through destination selection and bounds checks; check_q38_card rises 47→48 through one additional clause. No complexity-only finding.
Silent failure: 4 skip/length sites followed. Construction guarantees the route exists; the hostless route writes y; tier sums run at the join; the minimum buffer length feeds a named shape error.
Tests: mutation review of q38.rs:575 confirms that starting from -0.0 fails the bit assertions, as the supplied FAIL-first output shows. Dropping stray-place handling fails the NaN/fault assertions. Accepting zero tokens or a short output fails the refusal checks. The moved slot refusal remains checked.
Gates: no tolerance or existing PTX ceiling moved. The unsafe-count increase has a dated PIN and reason. The new PTX entry has zero spill/local ceilings.
Escape catalog: C1–C4 do not match the changed code.
Notes
Local validation was static; no runtime gate was run in this review. The body explains why the two-card gate was not run.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_kquant.rs, crates/gpu-gates/src/bin/shared/q38_combine.rs, crates/gpu/src/arch/qwen3moe/card38.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)
…t a host leg On a layer the load runs without a host leg, the ubatch walk summed the card slots into the unit's acc (ds41_ffn_card_acc_10, one launch a route run), zeroed the host sum and combined both with the shared expert in the back (q38_card_shared_add). q38_card_sum_shared_add does the sum and the combine in one launch a route run, from +0.0 as the zero host sum did, so the block output keeps its bits; the shared expert runs before the route so its rows are ready. Per such layer this drops the acc write and re-read, the host-sum memset and its read, and one launch. The combine's arithmetic and fault check move to one helper that the three combining kernels call.
b264a3c to
5b5c3ec
Compare
There was a problem hiding this comment.
Since the last review:
- Later route-run coverage: still open (wide38.rs:1317).
- Measurement evidence: still open (wide38.rs:1321).
Verdict: CLEAN: The interdiff corrects the rebased unsafe pin to the exact source count and retains its dated reason.
Non-blocking
⚠ Cover the later hostless route run: wide38.rs:1317. The two-token check calls the launcher directly and cannot detect a lost c0 offset in either window. Extend the existing whole-card clause with a prompt longer than ROUTE_ROWS, comparing whole and cut walks. Replacing either offset with zero must fail; this keeps an indexing regression local to its cause.
⚠ Complete the measurement evidence: wide38.rs:1321. The “fold a launch into a neighbour” class requires its owning gate and timed A/B. The body supplies GB10 gate output and timing tables, but lacks both measured commit hashes and the profiling and layer-timing commands. Add both hashes, the concrete model file identity, and the exact commands with output so the comparison can be reproduced.
Checked
Duplicates: 0 new definitions in the interdiff. Dryer reports zero pairs in gpu; gpu-gates was outside its scan and is unchanged since the last review.
Complexity: diagnostics flag check_hostless (new → 25, equivalence and fault cases), CardRoute38::enqueue (38 → 44, destination branches and bounds checks), and check_q38_card (47 → 48, one clause). All are unchanged in the interdiff.
Silent failure: 0 new sites. The interdiff changes only the unsafe-count pin and its explanation.
Tests: no tests changed since the last review. The supplied earlier FAIL-first output shows that changing the combine's initial zero to -0.0 fails the bit checks.
Gates: independent recount matches base 2250 277 10 and head 2256 277 10 for gpu blocks/functions/implementations. The dated PIN accounts for four added blocks in the kernel and two in route views; it leaves no spare allowance.
Escape catalog: C1–C4 do not match the interdiff.
Notes
Validation was static; no runtime gate was run locally. The body explains why the two-card gate was not run. GPU evidence remains incomplete because the measured commit hashes are absent.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_kquant.rs, crates/gpu-gates/src/bin/shared/q38_combine.rs, crates/gpu/src/arch/qwen3moe/card38.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 프롬프트 처리에서 호스트 몫이 없는 층은 카드 합산과 shared expert 결합을 kernel 하나로 합쳐, 4K 프롬프트마다 kernel launch 48개와 memset 48개가 줄고 프롬프트 처리가 조금 빨라집니다.
Part of #565.
What and why
On a layer without a host expert leg, the Qwen3.8 prompt walk summed the card slots and combined them with the shared expert in three steps: a memset that zeroed the host sum, one
ds41_ffn_card_acc_10launch per route run that wrote the card sum, andq38_card_shared_add, which read that sum back. On a GB10 every layer of both checkpoints takes this path, because the plan puts all experts on the card (host_experts=0 card_experts=24576).This PR adds one kernel,
q38_card_sum_shared_add, that sums the card slots and does the combine in a single launch per route run. The acc write and re-read and the host-sum memset are gone. The combine starts from+0.0, as the zeroed host sum did, so a-0.0card sum still becomes+0.0and the block output keeps the bits it has on main.crates/gpu/src/q38.rs: the new kernel and its launcher. The slot-order sum is stillcard_acc_at, nowpub(crate). The combine arithmetic and its fault check are one function,combine, whichq38_card_shared_add,q38_card_tier_shared_addand the new kernel call; the two existing kernels carried their own copy of it before.crates/gpu/src/arch/qwen3moe/wide38.rs:CardSumsays where a route run's sum goes. Tier layers (Join) and layers with a host leg (Acc) are unchanged; layers without one (Block) take the fused launch. The shared expert now runs before the card route on both paths, so its rows exist when the route reads them. Decode (program38.rs) is not touched.tools/ref/ptx-shapes*.tsvandtools/unsafe-ratchet.txt: the new entry is pinned0 0in all four PTX tables, and the unsafe count for the gpu crate goes from 2248 to 2254 because the new kernel and the per-run views add six blocks, each with itsSAFETYline and a datedPIN.On the 4K prompt this removes 48 launches and 48 memsets and 2,012,774,400 bytes of memset (48 layers x 4,095 tokens x 2,560 values x 4 B [derived]).
Release notes: Changed: Qwen3.8's prompt pass sums the card experts and adds the shared expert in one kernel on layers without a host leg, which removes 48 launches and 48 memsets from a 4K prompt.
Code shape
combineis the one owner of the combine arithmetic for the two existing kernels and the new one. The slot-order sum stays incard_acc_at.ExpertIdand NaNs its token, a non-finite value raisesF32Product.PIN(2026-10-23):reason.cargo fmtis clean on what I touched.Duplication found or removed (
path:line): the combine lines thatq38_card_shared_addandq38_card_tier_shared_addeach carried are nowcombine. The scan's two other hits (crates/gpu/src/q38.rs:551againstcrates/gpu/src/card_slots.rs:220) share only the kernel entry boilerplate; the new kernel callscard_acc_atfor the sum.What I ran
Speed
Kernel profile of one 4,096-token prompt pass, and a device-event timing of one 4,096-token layer without a host leg, both on a GB10 and both main against this branch.
Delta (head minus main): prompt pass -53.924 ms (-1.07%) under the profile, one layer -0.7796 ms.
The profile ran Qwen3.8-Flash-Next-FP4-Local with the clock cap on, one load per arm and one uncached 4,096-id code prompt. The layer timing builds one layer in two 2,048-token route runs over 512 card experts and 2,560 values with seeded random rows. It runs the main way (the host-sum memset, the card sum,
q38_card_shared_add) and the new way (the fused launch per run), with the clock cap lifted. The two outputs are bit-identical over 10,485,760 values. It takes five rounds of 20 timed layers per arm, main first in each round, and the table shows the median. Over 48 layers the layer saving is 37.4 ms [derived], which matches the profile's change for the same work (the card sum, the combine and the memsets together fall from 139.273 ms to 103.088 ms, -36.2 ms [derived]). Of the 53.9 ms the profile saves, 12.0 ms [derived] is idle time between launches, and each profile arm is one capture.Server A/B
I ran a server A/B on both checkpoints as well: one load per arm, then three uncached 4,096-token prompts with 128 greedy tokens, one client at a time, draft off, 4,224-token context, no cache RAM, clock cap lifted. Server prompt time, median of three:
The two checkpoints disagree in sign. The arm that loaded second was faster on both checkpoints by more than the change is worth, and requests inside one load moved by up to 158 ms [derived], while the expected saving is about 1% of a 4.6 s pass. I make no end-to-end claim from this A/B. The kernel profile and the layer timing above are the measured terms. Load time and client decode rate did not change.
Output
On both checkpoints, 64 greedy ids, the text and every token's top-100 log probabilities after an uncached 4K prompt are byte-identical between main and head:
greedy ids, text and top-100 log probabilities byte-identical.GPU evidence
Card, driver and CUDA, from
nvidia-smiin the layer-timing run:The profile ran with the clock cap on. The layer timing ran with the cap lifted, at 2424 MHz and 52 C by the clock query taken right after the timing, and the cap was restored afterwards:
The gate that covers the changed kernel is
just gate-gpu-kquant. Its clause 10 gets a new check,q38_card_hostless. Over the leg's real down rows with the host slots NaN, the fused launch equalsruntime::combine::combineover a zero host sum and the two old launches over zeros, bit for bit. A card sum of-0.0and a-0.0shared row give+0.0, a stray place raisesExpertIdandF32Productand NaNs its token, and the launcher refuses no token and an output one value short. On the final head:FAIL-first. With the new kernel's combine starting from
-0.0instead of+0.0, the same check fails and the gate exits 1:just gate-gpu-qwen38-twocardis not run: it needs two cards, which the test machine did not have. It coversq38_card_tier_shared_add, a kernel that now callscombine.The PTX shape tables hold the new entry at
0 0, and no pinned entry changed. Comparing the two builds atsm_121a: 399 entries on main and 400 on the head, the one added entry isq38_card_sum_shared_add, and two are changed,q38_card_shared_addandq38_card_tier_shared_add, the two kernels that now callcombine.Reproduce
Run main's binary and this branch's in turn. Each request sends 4,096 token ids from a code corpus as a greedy
POST /completionwithcache_promptoff.Hardware
A DGX Spark (NVIDIA GB10, driver 595.84, CUDA 13.3,
sm_121arelease builds). The clock cap was lifted for the layer timing and the server A/B, restored afterwards, and left on for the profile.What I ran into
None of this blocks the PR.
q38_card_tier_shared_adddiffers only in the layout of its finite test, andq38_card_shared_addin an unused register declaration and one swap of two independent lines.gate_kquantholdsq38_card_shared_addbit for bit. The tier kernel's own gate needs two cards and was not run.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.