Skip to content

qwen38: run the shared expert beside the card leg - #686

Merged
juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-qwen-side-stream
Oct 22, 2026
Merged

juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-qwen-side-stream

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

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.

  1. gpu: let resident dense GEMVs use a caller stream adds resident_gemv_cols_on in crates/gpu/src/site.rs, the dense GEMV entry that takes a stream. resident_gemv_cols calls it with the main stream, so its callers do not change.
  2. qwen38: run the shared expert beside the card leg adds Parts38::beside in crates/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, Verify38 and Pass38 each call it from shadow. Verify38 and Pass38 take a branch: &mut Branch, and crates/gpu/src/arch/qwen3moe/body38.rs makes one Branch per body at load and hands it to walk_pass, enqueue_chain, walk_verify and walk_slots.

Step38 always walks one column. Verify38 covers MTP verify and the multi-slot pass that concurrent decode runs, and Pass38 is the eager prompt pass. Each holds at most PASS_ROWS (8) rows, so every walk of 8 rows or fewer overlaps. Prompt ubatches of 9 rows or more go through wide38, 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=1295 for 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

  • No second copy. Parts38::beside is the one owner of the fork, the shared launches, the card leg and the join, and all three shadow walks call it. Branch and resident_gemv_cols_on are the existing stream owners.
  • Model code holds only architecture facts. The change is the order of Qwen3.8's own launches. The common stream owners gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing became unused.
  • No silent failure. The fork, the launches and the join return their errors with ?. On a launch error, the fork's guard joins the branch, so a capture never ends with an unjoined stream.
  • Comments state what is true now. The new comments describe the current launch order.
  • No relaxed gate. No band, tolerance or lint moved.
  • cargo fmt is clean on what I touched.

Duplication found or removed (path:line), or "none": none. The decode step's inline fork moved into Parts38::beside.

What I ran

Head 5460519ac on main 010729ed6. The measured trees carry the same two patches as this PR.

GPU Evidence

On an NVIDIA GB10:

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |

just gate-gpu-qwen4exp-e2e and just gate-q38-serve-rules not 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. Branch orders 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-Local at b9ce18a6887e18c089fdea8509a33e63429a3300, served directly from its folder. The MTP arms use the external shared-head Q8_0 draft file with BLOOMERY_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 from cargo 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.

Metric (FP4-Local, one GB10) main head change
C@1 decode tok/s, 4096-id prompt, draft off 30.19 30.56 +1.24%
C@2 all-active decode tok/s, 256-id prompts, draft off 45.58 46.15 +1.26%
C@2 all-active decode tok/s, 4096-id prompts, draft off 44.89 45.49 +1.34%
C@4 all-active decode tok/s, 256-id prompts, draft off 64.12 65.13 +1.58%
C@4 all-active decode tok/s, 4096-id prompts, draft off 62.34 63.41 +1.72%
C@2 TPOT p95 ms, 256-id prompts, draft off 48.36 47.73 -1.30%
C@4 TPOT p95 ms, 256-id prompts, draft off 71.11 69.68 -2.00%
C@1 decode tok/s, 4096-id prompt, MTP 28.84 29.10 +0.90%
C@2 all-active decode tok/s, 256-id prompts, MTP 28.83 29.14 +1.08%
C@4 all-active decode tok/s, 256-id prompts, MTP 28.89 29.30 +1.41%
C@4 all-active decode tok/s, 4096-id prompts, MTP 28.63 29.14 +1.78%

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 초안 리뷰는 제가 직접 했습니다.

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.
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 22, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::shadow and Verify38::shadow, delegates to Parts38::beside; another extraction adds elements.
  • Complexity: Body38::load_placed 68 → 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)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit dd87308 into midagedev:main Oct 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant