Skip to content

qwen38: a load whose every layer runs hostless over native NVFP4 downs keeps its card route's down rows in BF16, the product rounding each to nearest even and the block's card sum widening it - #914

Merged
juliankang4 merged 6 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fp4l-prefill-gap
Oct 28, 2026

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

DGX Spark에서 Qwen3.8 FP4-Local의 prompt 처리를 빠르게 하는 PR입니다. native NVFP4 expert GEMM이 tile마다 하는 일을 줄이고, routed down 출력을 BF16으로 두어 카드 합산이 읽는 양을 절반으로 줄입니다.

Supersedes #909.

Part of #565.

What and why

Prompt processing of Qwen3.8 FP4-Local spends most of its time in the routed experts' native NVFP4 tensor-core GEMM and in the per-layer sum of the experts' outputs. This PR cuts the work in both.

  • The GEMM walk reads a lane's four activation scales with one 128-bit load, loads two activation fragments with one ldmatrix, and runs a whole tile's live fragments with a literal count, so the checks for unused fragments no longer run in the hot loop.
  • When every layer of a load runs hostless over native NVFP4 down projections, the card route keeps its down rows in BF16. The GEMM rounds each value to nearest even in a new gemm_nvfp4_mma_bf16 entry, and the card sum (q38_card_sum_shared_add_bf16) widens each value back to F32 and adds the slots in the same ascending order as before, so the sum reads half the bytes. Any other load keeps F32 rows. A value outside the BF16 range becomes infinity and the existing finite check in the combine raises its named error.

Greedy tokens differ from the base: the first difference is at token 40 of the first MTP code request, where the BF16 rounding of the down values changes the numeric result.

Release notes: Changed: Qwen3.8 FP4-Local prompt processing is 4.9% faster on a DGX Spark, with TTFT p95 4.6% lower.

Code shape

  • No second copy. The native product's walk and store are one body (product_body) that the F32 and BF16 entries share. card_acc_at reads either down form, and both card-sum entries share card_sum_shared_add_at. live_walk! calls the one walk! body with literal tile lengths, so the generated code has several bodies and the source has one.
  • Model code holds only architecture facts. The GEMM and card-slot owners gained no per-model branch, flag or trait method. The BF16 choice is made from the load in the qwen3moe route code.
  • Dead code is gone. Nothing is left unused by the change.
  • No silent failure. The F32-only paths (the Acc path and the tier join) refuse BF16 rows by name, and a BF16 product on a stack without the native NVFP4 form is refused by name.
  • Comments state what is true now.
  • No relaxed gate. bf16_eq in gate_gemm and two bf16_rows lines in gate_kquant are new checks. The two new entries and one changed walk entry carry PIN(2026-10-28) rows in the PTX shape tables, and the unsafe ratchet is raised for them with its PIN lines. The sm_86 and sm_121 rows of the BF16 entries copy their F32 sibling's values because I measured no card of those classes.
  • cargo clippy is clean. At sm_121a it exits 0 and reports one warning, needless_range_loop in the gate-up kernel's input-scale loop, which this PR does not change.

Duplication found or removed (path:line), or "none": none.

What I ran

Timed runs use one DGX Spark, bloomery-serve with --parallel 1 --ctx-size 16896, and nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6887e18c089fdea8509a33e63429a3300. A request is a 4096-token prompt with 128 generated tokens at temperature 0, on eight prompt windows of the code corpus (and of the prose corpus for the prose arm). Each side has three recorded rounds after one discarded lead-in round, and the sides alternate base, head, head, base, base, head. There are three arms: draft off on the code prompt, and the checkpoint's own MTP layers on the code and the prose prompts. Prefill and decode are the server's timings and TTFT is the client's.

git -C base checkout ef486e1d4b70667bedd23468c4cb962ea3b20efe
git -C head checkout 5512da6193b9c0692fe506e02ccb5c0513e2ceba
(cd head && cargo oxide build --arch "$(bash tools/arch.sh)" -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve)
env BLOOMERY_DRAFT=off BLOOMERY_HOST_ROOM=96G ./head/target/release/bloomery-serve -m <folder> --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896
env -u BLOOMERY_MTP_DRAFT BLOOMERY_DRAFT=mtp BLOOMERY_HOST_ROOM=96G BLOOMERY_MTP_WIDTH=cost ./head/target/release/bloomery-serve -m <folder> --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896

The base is built the same way in its own checkout.

Each cell is the median of three rounds with its range in parentheses.

Metric Base Head Difference Ranges overlap
Prefill, draft off, code, tok/s 2198.9 (2192.7 to 2201.2) 2305.7 (2304.2 to 2307.9) +106.9 (+4.9%) no
Prefill, MTP, code, tok/s 2092.5 (2088.6 to 2098.1) 2195.2 (2194.3 to 2200.3) +102.7 (+4.9%) no
Prefill, MTP, prose, tok/s 2144.5 (2095.4 to 2157.0) 2248.9 (2247.5 to 2255.8) +104.4 (+4.9%) no
TTFT p95, draft off, code, ms 1869.3 (1867.2 to 1874.4) 1782.9 (1780.7 to 1783.9) -86.4 (-4.6%) no
TTFT p95, MTP, code, ms 1963.7 (1958.7 to 1967.0) 1872.6 (1867.6 to 1873.0) -91.1 (-4.6%) no
TTFT p95, MTP, prose, ms 1916.4 (1905.8 to 1960.5) 1827.6 (1821.6 to 1829.7) -88.8 (-4.6%) no
Decode, draft off, code, tok/s 31.27 (31.09 to 31.37) 30.95 (30.80 to 31.08) -0.31 (-1.0%) no
Decode, MTP, code, tok/s 57.04 (56.94 to 57.32) 59.51 (59.38 to 60.00) +2.47 (+4.3%) no
Decode, MTP, prose, tok/s 40.99 (40.31 to 41.29) 39.53 (39.40 to 39.99) -1.47 (-3.6%) no

Prefill is 4.9% higher on all three arms (2198.9 to 2305.7, 2092.5 to 2195.2 and 2144.5 to 2248.9 tok/s) and TTFT p95 is 4.6% lower; the sample ranges do not overlap.

MTP decode is 4.3% higher on the code prompt and 3.6% lower on the prose prompt. Draft-off decode is 1.0% lower with ranges that do not overlap; I have not found the cause.

Checks on the code of this branch, on a DGX Spark at arch=sm_121a:

  • just gate-gpu-gemm --case nvfp4_native (the recipe's GPU step): 51 PASS lines and no FAIL.

  • The four whole-tile cases of that gate (128 rows, K = 128, 14, 25, 49 and 73 slots over two experts) use varied inputs, so an activation row the walk fails to copy cannot match a value an earlier case left in shared memory. With live_rows(6) changed to return 32, the two 73-slot lines fail with wrong=1152 (the 9 uncopied columns of 128 rows) and the gate exits 1.

  • just gate-gpu-gemm --case nvfp4_gate_up: 9 PASS lines and no FAIL.

  • just gate-gpu-kquant: 164 PASS lines and no FAIL, both q38_card_hostless[bf16_rows, ...] lines among them.

  • A mutant that replaces the round-to-nearest-even product with truncation fails 16 bf16_eq lines of nvfp4_native, and a mutant of the widening fails 2 of the 4 q38_card_hostless lines.

  • cargo fmt --check: fmt rc=0.

Precision on the whole model, with the NVIDIA NVFP4 checkpoint (the prepare split of nvidia/Qwen3.8-Flash-Next-NVFP4) loaded with every routed expert on the card, so every layer runs hostless over NVFP4 down projections and the card route keeps its down rows in BF16:

  • just gate-gpu-qwen4exp-nvfp4 with BLOOMERY_CARD_ALL_EXPERTS=1: exit 0; batch set by one pass kld=0.015775904, by one ubatch kld=0.066061804, 3000-token prompt by ubatches kld=0.028200012; the argmax equals the oracle's in every set; 36 flips (36 allowed).

  • ./tools/contrib-check.sh --tier t0: 37 checks, 0 red.

Result lines of the nvfp4_native gate, for a 73-slot case, and the same lines with live_rows(6) changed to return 32:

gemm32 case=nvfp4_native rows=128 slots=73 k=128 input=Varied fused=false native=true q8_eq=true producer_eq=true bf16_eq=true wrong=0 guard=true eager_graph_eq=true hash=efe95f1c81cc01a5 PASS
gemm32 case=nvfp4_native rows=128 slots=73 k=128 input=Varied fused=false native=true q8_eq=true producer_eq=true bf16_eq=true wrong=1152 guard=true eager_graph_eq=true hash=183fe65f5ec59e65 FAIL

Hardware

DGX Spark, nvidia-smi query: NVIDIA GB10, 595.84, CUDA 13.3.

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |

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 tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 28, 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: I built no failure path that the code does not block; three questions about evidence stay open.

Non-blocking

⚠ The timing does not isolate the BF16 route: wide38.rs:1077 turns BF16 on only when !tiered, every layer is hostless and every down is NVFP4. The timed runs use BLOOMERY_HOST_ROOM=96G on FP4-Local, and the body does not say that load is hostless. The 4.9% may come from the walk changes alone. Only the prompt walk reads BF16 rows; decode and verify keep F32 rows (card38.rs:456, card38.rs:659). State which change gives +4.9%, or add a timed A/B on a hostless NVFP4 load.

⚠ Unexplained decode loss: the body shows decode -1.0% (draft off, code) and -3.6% (MTP, prose), ranges not overlapping, cause not found. The walk change is a restructure (ldmatrix pairs, 16-byte scale load, literal tile arms), so it needs a timed A/B on every decode arm. Add a base-versus-base run for the noise floor, or find the cause.

⚠ The gate-up live arms are not pinned by committed cases: gate_gemm.rs:8927 adds the Varied cases to nvfp4_native only. The body says the nvfp4_gate_up run used "a build that differs only in those case inputs"; that build is not in this PR. Mutant: change $live <= 4 to $live <= 6 at nvfp4mma.rs:1534. Warp wc = 1 then skips columns 32 to 47 of a 33 to 48 column tile. No committed gate-up case is shown to make such a tile. Add one.

Checked

  • Duplicates: about 14 new items checked (DownRows, Down38, DownWin, ProductCell, ProductOut, has_native_form, all_hostless, cells_view, RowValues for &[u16] and others), none duplicated. Dryer pairs read: wide38.rs:856/:871 (a merge adds elements), nvfp4mma.rs:1189/:1231, q38.rs:592/:627 (separate kernel entries). None is one fact twice.
  • Complexity: check_hostless 25 to 37 and nvfp4_native_case 89 to 96 are gate bodies with new checks. CardRoute38::new 18 to 23 is one decision beside its owner. enqueue +1 is a match arm. Kernel bodies stay whole, as AGENTS.md requires.
  • Silent failure: 6 sites followed. BF16 rows in the Acc path and the tier join are refused by name (DownRows::f32). A BF16 product without the native form is refused by name (gemm32.rs:1861). Overflow becomes infinity, which the combine's finite check raises. CardSum::Acc and Join cannot meet BF16 rows: the caller picks Block for a hostless layer (wide38.rs:2368).
  • Tests: the bf16_eq truncation mutant turns red. A wrong cell read in the BF16 card sum turns q38_card_hostless[bf16_rows] red. The gate-up arm is the gap above.
  • Gates: no band or tolerance moved; PIN lines are dated with reasons. Safety: scale_quad alignment holds by the const assert; col_scale sits under $sr < 64.
  • Escape catalog: no pattern matched.

Notes

  • The body names head 7a90733 and base 51ed64b; pr.json has head 5512da6 and base d74b53e. Re-run the gates on this head or say the kernels are unchanged.
  • The body lists contrib-check as not run and the clippy item as unchecked.
  • The nvidia-smi line is a paraphrase and the gate output is a count, so it is not gate evidence.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu-gates/src/bin/shared/q38_combine.rs, crates/gpu/src/arch/qwen3moe/body.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 6fbf1dc into midagedev:main Oct 28, 2026
7 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