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 - #909

Closed
juliankang4 wants to merge 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fp4l-prefill-gap

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으로 두어 카드 합산이 읽는 양을 절반으로 줄입니다.

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 -p bloomery-gpu-gates --all-targets -- -D warnings is clean on this head. I did not run cargo fmt --check on this head.

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. The base is upstream 51ed64b09a06124de61e3ebfb5cd03b8334a2fff and the head is 7a9073307db854c2cfc4537a40f8d151ff85f87d. 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 51ed64b09a06124de61e3ebfb5cd03b8334a2fff
git -C head checkout 7a9073307db854c2cfc4537a40f8d151ff85f87d
(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 "${MODEL_FP4L}" --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 "${MODEL_FP4L}" --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:

  • cargo clippy -p bloomery-gpu-gates --all-targets -- -D warnings: exit 0 on this head.
  • RTX 5090, this head, just gate-gpu-gemm --case <case> run as its two steps, cargo oxide build --arch sm_120a -- -p bloomery-gpu-gates --features gpu --release --bin gate_gemm and bash tools/gpu-gate.sh gate_gemm --case <case>: nvfp4_native 43 PASS lines, nvfp4_gate_up 9 PASS lines, and the nvfp4_swiglu case matched no lines.
  • DGX Spark, an earlier head of this branch with the same crates/ patch (the last rebase onto upstream changed only the unsafe ratchet and PTX shape tables), arch=sm_121a: gate_gemm --case nvfp4_native PASS=43 FAIL=0 and gate_kquant q38_card_hostless PASS=4 FAIL=0. A mutant that replaces the round-to-nearest-even product with truncation fails 16 bf16_eq lines of nvfp4_native (PASS=27), and a mutant of the widening fails 2 of the 4 q38_card_hostless lines.

Not run on this head: the DGX Spark gates, cargo fmt --check, the workspace tests and contrib-check. The change touches crates/gpu, so a maintainer needs to run the GPU gates on a card.

Hardware

Timed runs and the DGX Spark gates ran on:

  • NVIDIA GB10, driver 595.84, CUDA 13.3 (timed runs; nvidia-smi reports Driver Version: 595.84 and CUDA Version: 13.3)

Gate runs on this head used an RTX 5090:

  • NVIDIA GeForce RTX 5090, driver 595.99.02, CUDA 13.2, 400 W power cap (gate_gemm on this head; nvidia-smi reports Driver Version: 595.99.02 and CUDA Version: 13.2)

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: MUST_FIX: one PIN comment states a move that the table does not make; the kernel and combine changes held up under my checks.

Must fix

1. The gemm_nvfp4_mma PIN narrates a change the row does not make

tools/ref/ptx-shapes/sm_121a-cc12.1.tsv:187 says "spill 16 -> 0 B, JIT local 8 -> 0 B" above gemm_nvfp4_mma 0 0. The base row is already 0 0, and this diff leaves it unchanged. A PIN records a moved value with evidence. This one records a move that is not in the table, and it carries history, which the project keeps in commit messages. The reader cannot tell whether the base gate was stale or the comment is wrong. Fixing it now is cheaper than a later reader trusting it.
Fix: delete the two lines at 187-188 and put the new entry's own PIN above its row:

# PIN(2026-10-28): gemm_nvfp4_mma_bf16, a new entry: 0 spill and 0 JIT local bytes (sm_121a ptxas 13.3.73, cc 12.1 JIT on GB10 driver 595.84, gate-ptx-spill).
generate_ds41 gemm_nvfp4_mma_bf16 0 0

(Keep the existing generate_ds41 gemm_nvfp4_mma 0 0 line as it is.)

Non-blocking

⚠ Decode numbers moved with no cause: the PR body shows draft-off decode -1.0% and MTP prose decode -3.6%, ranges not overlapping, "cause not found". card_acc_at (card_slots.rs:439) is now generic over RowValues and also serves the decode kernels. Class "move, split, rename" needs ptx-scan identical for the F32 entries (q38_card_sum_shared_add, ds41_ffn_card_acc_10). Please show that output. If it differs, the generic change is the cause.

⚠ Tile-length coverage of live_walk!: nvfp4mma.rs:649 has five arms (1, 2, 4, 6, 8 fragments). The cases in nvfp4_native_case are (rows, slots) pairs, and I cannot tell which of them make tiles of 1-8, 17-32 and 33-48 columns. Mutant: live_rows(6) returns 32 instead of 48. Only a case with a 33-48 column tile turns red. Name the case per arm in the PR body, or add the missing one.

⚠ Same shared-stage block twice: product_stages! (nvfp4mma.rs:981) repeats the four static mut arrays and as_raw_mut_ptr calls of the gate-up kernel at nvfp4mma.rs:1495. Reusing the macro there would remove about 14 lines and 4 unsafe blocks. I did not make it a must-fix because it is a "move" class change that needs a ptx-scan check. Do it in a follow-up with that proof.

⚠ Two PIN blocks in the unsafe ratchet: unsafe-ratchet.txt:652 has two PINs that each say "2776 -> 2782 blocks, 355 -> 361 fns" for one line. Merge them into one PIN that lists both parts of the delta.

Checked

  • Duplicates: 14 new items checked (Down38, DownWin, DownRows, ProductCell, ProductOut, cells_view, scale_quad, b_pair, col_scale, live_rows, product_stages, card_sum_shared_add_at, has_native_form, all_hostless). One hit: product_stages against the gate-up statics (⚠ above). cells_view replaces f32_view everywhere; no old use is left. Dryer pairs read: wide38 856/871 is Down38::rows and DownWin::rows over two types, with no shorter fix, so no finding. nvfp4mma 1189/1231 and q38 592/627 are paired kernel entries, which AGENTS.md keeps flat.
  • Complexity: check_hostless 25→37 (a new BF16 block in a gate, the same shape as the F32 block), nvfp4_native_case 89→96 (one more clause), CardRoute38::new 18→23 (the bf16_down condition, one owner), CardRoute38::enqueue +1 (match arm). No split suggested.
  • Silent failure: 6 sites followed. .f32(WHAT)? on the Acc and tier paths refuses BF16 by name. enqueue_gemm32_bf16 refuses a non-native stack by name. An overflow to infinity reaches the combine's finite check. f32_to_bf16_rne keeps NaN (documented at crates/gpu-vision/src/lib.rs:91). hostless is fixed per load, so the route's row type cannot change after new.
  • Kernel bounds: live_rows(live) equals the rows b_pair reads for every arm. col_scale is a permutation (const-asserted) and scale_quad stays 16-byte aligned. The gate-up continue skips no barrier.
  • Tests: bf16_eq fails on a truncating product (the PR's own mutant). The bf16_rows lines fail on a narrowing widen. A dropped live guard in a dead fragment is covered only if the arm coverage question above is answered.
  • Gates: PTX rows added with PINs. One PIN is misleading (must-fix 1). No band or tolerance moved.
  • Performance: no allocation, lock or launch added per step. The BF16 route halves the card sum's read bytes (a derived claim, not a measurement). Escape catalog: no pattern matched (no shell changes).

Notes

  • The timed runs name head 7a9073307db8, but the PR head is ae96c1809a13. The DGX Spark gates and cargo fmt --check did not run on this head. A maintainer needs a card run, as the author wrote.
  • The nvidia-smi line itself and the command output of the gates are not in the PR text, so I marked GPU evidence as not present.

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

Superseded by #914.

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