Skip to content

gpu: fuse the hostless Qwen3.8 card sum with the shared add - #974

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-sa-q2-decode-moe
Oct 29, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-sa-q2-decode-moe

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8의 hostless decode 층에서 card 합산과 shared add를 기존 fused kernel 한 번으로 합쳐 step당 launch를 48개 줄이는 PR입니다.

What and why

On a Qwen3.8 layer that runs without a host leg, the step, the verify and the pass launched a zero fill, a card sum and a separate shared add. This PR keeps the card slots' down rows and runs the existing q38_card_sum_shared_add kernel once per layer, so each hostless layer saves one launch, the accumulator write and read, and the zero read. The slot reduction and the (0 + acc) + shared * weight order are unchanged, and no kernel is added.

  • crates/gpu/src/arch/qwen3moe/card38.rs: a hostless layer retains the down rows and joins through enqueue_hostless_join. The zero buffer is gone.
  • crates/gpu/src/arch/qwen3moe/program38.rs: the hostless path selection and the graph launch count follow.
  • crates/gpu-gates/src/bin/gate_qwen4exp_e2e.rs: the expected graph node count of the hostless layers drops by the fused launch. No band or tolerance moved.

Decode throughput does not change beyond the run-to-run range (table below). The change removes launches and memory traffic without a measurable regression.

Release notes: Under the hood: the hostless Qwen3.8 decode layer sums the card slots and adds the shared expert in one launch.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. Logic two models (or two call sites) share has one common owner; I lifted it there instead of
    copying it (AGENTS.md "Common code first", docs/rust-quality.md R14). Where I found an existing copy, I
    named it below.
  • Model code holds only architecture facts. A model's own files carry only what its architecture forces
    (tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing I made unused is left behind (functions, flags, gate clauses, docs).
  • No silent failure. Undefined input is a named error or panic, never a defined-looking output.
  • Comments state what is true now. No dates, issue numbers or how a bug was found (tools/check-comments.sh).
  • No relaxed gate. No band, tolerance or lint moved to make a check pass; a re-pin carries PIN(YYYY-MM-DD):
    and its reason.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": none. The fused kernel is the existing one; enqueue_hostless_join only assembles its arguments.

What I ran

Checks: cargo fmt --all and git diff --check exit 0.

Card gates on the changed path, DGX Spark, tested head f3c21d96c60d018715c83aac626168a6cb15c190:

BLOOMERY_FIXTURE_ROOT="$sa_q2_fresh" BLOOMERY_BOX_LOCAL=1 just gate-fixture-budget
BLOOMERY_BOX_LOCAL=1 BLOOMERY_TIER=fixture just gate-gpu-qwen4exp-e2e
BLOOMERY_BOX_LOCAL=1 BLOOMERY_TIER=real just gate-ptx-spill
qwen38: budget 9327083520, experts a layer [256, 256, 256, 256]
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 15 filtered out; finished in 0.06s
verify structure T=4: graph_nodes=125 (want 125; the program counts 125) batch_mem_op=1 (want 1) ... PASS
card leg whole plan: 4 of 4 layers without the host leg (want 4: the fixture fits the card); batch_mem_op 0 (want 0) ... PASS
paths whole plan: graph steps vs host legs kept: tokens [157377, 137169, 47835, 32521, 34727] vs [157377, 137169, 47835, 32521, 34727]; every position's logits bit for bit: true ... PASS
paths whole plan: eager steps vs host legs kept: tokens [157377, 137169, 47835, 32521, 34727] vs [157377, 137169, 47835, 32521, 34727]; every position's logits bit for bit: true ... PASS
verify whole plan vs host legs kept: rows [47835, 32521, 34727, 48499] vs steps [47835, 32521, 34727, 48499] (4 compared), logits bit for bit: true ... the step after: 59209 vs 59209, logits bit for bit true PASS
paths one pass of five rows vs five graph steps: ... the last logits bit for bit: true ... PASS
ptx-spill bin=generate_ds41 entries=492 pinned=492 ... violations=0 PASS
ptx-spill bin=gate_qwen3vl_tower entries=26 pinned=26 nonzero=none violations=0 PASS

Real binary A/B. Base 7163db37ff5c25f41870df1692bce5777536f22e, head f3c21d96c60d018715c83aac626168a6cb15c190. Model nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6887e18c089fdea8509a33e63429a3300, with the MTP draft from the same folder. Prompt 4096 tokens, 128 generated, one request at a time, 8 windows per corpus, one warm-up then 3 measured rounds per revision. Server:

BLOOMERY_DRAFT=off BLOOMERY_HOST_ROOM=96G bloomery-serve -m "$MODEL_FP4L" --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896
BLOOMERY_DRAFT=mtp BLOOMERY_HOST_ROOM=96G BLOOMERY_MTP_WIDTH=cost bloomery-serve -m "$MODEL_FP4L" --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896
Metric Base Head Difference Ranges overlap
draft off, code, decode tok/s 31.6698 31.8379 +0.531% yes
MTP, code, decode tok/s 58.3572 58.3874 +0.052% yes
MTP, prose, decode tok/s 42.0080 42.2836 +0.656% yes

Medians of three rounds. Prefill and TTFT ranges also overlap on every row, and the generated tokens match between base and head.

Hardware (if the change is for a machine)

  • NVIDIA GB10, driver 595.84
  • CUDA 13.3.1, sm_121a

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@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 labels Oct 29, 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: MUST_FIX: the changed graph-node pins lack the required dated reasons.

Must fix

1. Add PIN comments to both changed graph-node expectations

crates/gpu-gates/src/bin/gate_qwen4exp_e2e.rs:3626 and crates/gpu-gates/src/bin/gate_qwen4exp_e2e.rs:3876 lower the decode and verify expectations by one node per hostless layer. Neither change carries the dated PIN(YYYY-MM-DD): reason required for a moved gate pin (kind B).
Record the derivation now, while the launch change and its evidence are available.

Replace the decode expectation with:

// PIN(2026-10-29): each hostless layer folds its card sum into the shared add.
let want_nodes =
    shape().nodes_decode_card(plan.card_layers) - (memops() - want_memops) - hostless(plan);

Replace the verify expectation with:

let want = (
    // PIN(2026-10-29): each hostless layer folds its card sum into the shared add.
    shape().nodes_verify_card(plan.card_layers) - (memops() - want_memops) - hostless(plan),
    want_memops,
);

Non-blocking

⚠ Tie GPU evidence to the reviewed head: crates/gpu/src/arch/qwen3moe/card38.rs:686. The gate results name f3c21d9; the reviewed head is bb03180. Supply the nvidia-smi line and gate/A/B commands with output for this head, or establish patch equivalence. This connects the required launch-fold proof to the code being merged.

Checked

  • Duplicates: 2 new functions checked; no duplicate owner. Dryer reported 0 pairs; the gate changes were grepped manually.
  • Complexity: crapper flagged no functions; no kernel body changed.
  • Silent failure: 4 optional-state sites followed. Missing card buffers error; absent host/tier selects the intended path; an absent run owns zero bytes. Device faults still reach the head.
  • Tests: static mutation check. Restoring the separate hostless sum adds a node and fails the exact graph counts. Dropping the fused join fails logits comparisons against the kept-host path.
  • Gates: decode and verify count expectations move; missing PIN comments are item 1. No band or tolerance changes.
  • Escape catalog: no patterns matched. Retained rows are consumed before reuse; the fused kernel reuses the same reduction and explicit rounding.

Notes

Dryer did not search crates/gpu-gates. Validation was static; CUDA gates were not rerun.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen4exp_e2e.rs, crates/gpu/src/arch/qwen3moe/card38.rs, crates/gpu/src/arch/qwen3moe/program38.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)

let ([k, b], other) = count_kinds(&m.step_graph_nodes()?, [kernel, memop]);
let want_memops = shape().memops_card(hostless(plan));
let want_nodes = shape().nodes_decode_card(plan.card_layers) - (memops() - want_memops);
let want_nodes =

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.

The changed decode node-count pin needs a dated reason.

Suggested change
let want_nodes =
// PIN(2026-10-29): each hostless layer folds its card sum into the shared add.
let want_nodes =

let want_memops = shape().memops_card(hostless(plan));
let want = (
shape().nodes_verify_card(plan.card_layers) - (memops() - want_memops),
shape().nodes_verify_card(plan.card_layers) - (memops() - want_memops) - hostless(plan),

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.

The changed verify node-count pin needs a dated reason.

Suggested change
shape().nodes_verify_card(plan.card_layers) - (memops() - want_memops) - hostless(plan),
// PIN(2026-10-29): each hostless layer folds its card sum into the shared add.
shape().nodes_verify_card(plan.card_layers) - (memops() - want_memops) - hostless(plan),

@juliankang4
juliankang4 force-pushed the dgx-spark-q38-sa-q2-decode-moe branch from bb03180 to 607d0ec Compare October 29, 2026 15:30

@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.

Since the last review:

Verdict: CLEAN: the interdiff supplies both requested PIN comments and introduces no behavior change.

Non-blocking

⚠ Connect GPU evidence to this head: crates/gpu/src/arch/qwen3moe/card38.rs:686. The results name tested head f3c21d9; this head is 607d0ec. Supply the required nvidia-smi line and either establish patch equivalence or attach gate and timed A/B commands with output for this head. This connects the launch-fold proof to the code being merged.

Checked

  • Duplicates: 0 new functions, types or constants in the interdiff. Dryer reported 0 pairs; no duplicate candidates to read.
  • Complexity: crapper flagged no functions. The interdiff changes comments only.
  • Silent failure: 0 new sites. Rechecked missing-card refusal and hostless selection; no fallback output added.
  • Tests: no assertion changes in the interdiff. Static mutation check: restoring the separate sum at program38.rs:754 adds a verify node and fails card_rows' exact count.
  • Gates: both dated PIN reasons are present at gate_qwen4exp_e2e.rs:3625 and :3877. No values change in the interdiff.
  • Escape catalog: no patterns matched. Signed-zero behavior retains combine(0.0, acc, ...); the branch joins before retained rows are consumed.

Notes

Dryer did not search crates/gpu-gates. Validation was static; CUDA gates were not rerun.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen4exp_e2e.rs, crates/gpu/src/arch/qwen3moe/card38.rs, crates/gpu/src/arch/qwen3moe/program38.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 c7b6420 into midagedev:main Oct 29, 2026
8 of 9 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant