Repository navigation
qwen38: run the shared expert beside the card leg - #686
Conversation
The decode step, a verify, a pass of several slots' rows and an eager prompt pass fork the shared expert's four launches onto a branch stream the body makes at load, beside the card leg on the main stream, and join it before the gated sum. A layer without card experts has no card leg to overlap, so its shared expert stays on the main stream and the layer forks nothing. The kernels and the sum order are unchanged. Each of these walks holds at most the pass arena's rows.
BY_NAME, resident_type, WideActs::views_mut and WideActsMut have no caller outside bloomery-gpu, so they take the default visibility. tools/hf-arch-check.py finds BY_NAME by its declaration, so its anchor follows.
There was a problem hiding this comment.
Verdict: CLEAN: The fork and join order shared-expert reads, sums and buffer reuse; no must-fix defect was found.
Non-blocking
⚠ Complete the stream-overlap evidence: crates/gpu/src/arch/qwen3moe/program38.rs:676.
Each card layer adds two event records and two stream waits per eager unit [derived]; overlapping kernels changes concurrent occupancy.
The occupancy change class calls for the owning gate and timed A/B. Include just gate-gpu-qwen4exp-e2e output for eager/graph/pass bit parity, plus exact A/B commands and output covering small eager prefills.
These checks establish ordering and event overhead before further overlap changes make regressions harder to isolate.
Checked
- Duplicates: 2 new functions checked; neither duplicates an existing owner. The dryer pair,
Step38::shadowandVerify38::shadow, delegates toParts38::beside; another extraction adds elements. - Complexity:
Body38::load_placed68 → 69 adds fallible stream creation at load; no growing decision tree. - Silent failure: 2 optional-input fallback sites followed; both select the documented arena buffer. Launch errors propagate, and the fork guard joins on early returns.
- Tests: none added or changed; mutation check does not apply. GPU gates were not run during this static review.
- Gates: no thresholds, clauses or tests moved or were removed.
- Escape catalog: no matching patterns.
Notes
The PR explicitly defers GPU gates. Its timing table lacks exact benchmark commands and raw output, and names measured commits other than the reviewed base and head. GPU gate evidence is missing.
Card check: needs-gpu. This pull request changes crates/gpu/src/arch/qwen3moe/body38.rs, crates/gpu/src/arch/qwen3moe/program38.rs, crates/gpu/src/site.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를 card leg 옆의 별도 stream에서 함께 돌려, DGX Spark 한 대에서 draft를 끈 decode 속도를 약 1.2%에서 1.7% 높입니다.
Part of #565.
What and why
A Qwen3.8 layer runs the routed experts on the card and then the shared expert, one after the other on the main stream. The shared expert is four small kernels per layer (gate and up GEMVs, SwiGLU, down GEMV). Its gate and up GEMVs launch only 80 blocks each, so the GPU has room to run the routed experts at the same time.
This PR launches the shared expert on a second stream while the card leg runs on the main stream, and joins the two before the shared-expert sum. Under a profiler, one decode step takes 35.4 ms and the shared expert's kernels take 1.56 ms of it (4.41%). That share is the most the overlap can recover.
This is the shared-expert half of the line in #565 section 4, "Shared expert and GDN projections on a side stream beside the routed experts, on Qwen3.8". The GDN projections are not in this PR and stay open.
gpu: let resident dense GEMVs use a caller streamaddsresident_gemv_cols_onincrates/gpu/src/site.rs, the dense GEMV entry that takes a stream.resident_gemv_colscalls it with the main stream, so its callers do not change.qwen38: run the shared expert beside the card legaddsParts38::besideincrates/gpu/src/arch/qwen3moe/program38.rs. It forks the side stream, launches the shared expert on it, runs the card leg on the main stream and joins.Step38,Verify38andPass38each call it fromshadow.Verify38andPass38take abranch: &mut Branch, andcrates/gpu/src/arch/qwen3moe/body38.rsmakes oneBranchper body at load and hands it towalk_pass,enqueue_chain,walk_verifyandwalk_slots.Step38always walks one column.Verify38covers MTP verify and the multi-slot pass that concurrent decode runs, andPass38is the eager prompt pass. Each holds at mostPASS_ROWS(8) rows, so every walk of 8 rows or fewer overlaps. Prompt ubatches of 9 rows or more go throughwide38, which stays serial.The change adds no kernel, launch or byte. The graph node count is the same with and without it (
capture graph_nodes=1295for the decode step,verify rows=2..4 nodes=1331). Each layer of each walk adds one event record and wait at the fork and one at the join, which a capture records as edges.Release notes: Changed: Qwen3.8 decode runs the shared expert beside the routed experts, which raises decode throughput by about 1.2% to 1.7% with the draft off on one DGX Spark.
Code shape
Parts38::besideis the one owner of the fork, the shared launches, the card leg and the join, and all threeshadowwalks call it.Branchandresident_gemv_cols_onare the existing stream owners.?. On a launch error, the fork's guard joins the branch, so a capture never ends with an unjoined stream.cargo fmtis clean on what I touched.Duplication found or removed (
path:line), or "none": none. The decode step's inline fork moved intoParts38::beside.What I ran
Head
5460519acon main010729ed6. The measured trees carry the same two patches as this PR.GPU Evidence
On an NVIDIA GB10:
just gate-gpu-qwen4exp-e2eandjust gate-q38-serve-rulesnot run: their fixtures (the Qwen3.8 GGUF and reference sets) are not on the machine I measured on, so a maintainer runs them.The shared expert writes only its own buffers (
sh_g,sh_u,sh_h,sh_y) and the card leg writes its own, and both only read the layer input. The router's selection comes from before the fork. The sum kernels read the shared result after the join in the same order as before, so no device arithmetic changes.Branchorders an eager run with the same two event waits it records in a capture. I did not run the eager against graph bit comparison gate. What I have is the greedy comparison below.Throughput
The checkpoint is
nvidia/Qwen3.8-Flash-Next-FP4-Localatb9ce18a6887e18c089fdea8509a33e63429a3300, served directly from its folder. The MTP arms use the external shared-head Q8_0 draft file withBLOOMERY_MTP_WIDTH=cost. Both trees carry one measurement-only commit that lets a checkpoint folder load an external MTP draft, which the draft-off arms do not reach. Release binaries come fromcargo oxide build --arch sm_121.Each arm loads its server once. The arms ran in the order main draft off, head draft off, head MTP, main MTP, inside one timing lease, with the GPU clock cap lifted for each arm only. Each arm sends 4096-id prompts at 1, 2 and 4 concurrent requests and 256-id prompts at 2 and 4, with 128 generated ids per request, temperature 0, EOS ignored, no RAM cache and context 16896. The 256-id groups finish prefill early, so their decode window has every request decoding. "All-active" means the tokens generated inside the window where every request of the group decodes. Each cell is one observation, with no confidence interval.
Decode rose by 1.3% at two requests and by 1.6% to 1.7% at four with the draft off, and by 1.1% to 1.8% with MTP; every greedy id matched. TPOT p95 fell by 1.30% at two requests and 2.00% at four.
Every greedy id is identical between main and head, with the draft off and with MTP (
PARITY {"base-off=head-off": true, "base-mtp=head-mtp": true, "head-off=head-mtp": true, "base-off=base-mtp": true}).What I ran into
This does not block the PR. Two client numbers of the 4096-id groups at four requests look worse on the head than the table suggests. The cause is how the scheduler grouped the prefills. Main prefilled the four prompts as 2+2 and the head as 1+3, so the head's first token arrived 5.7 s earlier and its client clock started that much sooner. Total tok/s reads from 26.37 to 20.81 and TPOT p95 from 151.3 to 191.7 ms. The group still finishes sooner with the head, in 29.83 s against 30.35 s. The all-active rows in the table exclude prefill, which is why they use that window.
Hardware
One NVIDIA DGX Spark (GB10), driver 595.84, CUDA 13.3, with CUDA 13.3.1 in the build image.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.