Skip to content

qwen38: a ubatch walk carries its HC streams and normed rows as BF16 values, each rounded to nearest even once - #920

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

juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fp4l-prefill-profile

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

DGX Spark에서 Qwen3.8 FP4-Local의 prompt 처리를 빠르게 하는 PR입니다. prompt 처리 중 HC 구간이 읽고 쓰는 residual stream과 정규화 결과를 BF16 값으로 두어 메모리 이동량을 줄입니다.

Part of #565.

What and why

Prompt processing of Qwen3.8 FP4-Local spends much of its time in the hyper-connection (HC) steps of each layer, which are limited by memory traffic over F32 values. This PR halves that traffic.

  • On GB10 a BF16 HC site keeps its normed streams (xn) as BF16 values, rounded to nearest even when the norm writes them; the down MMA, the fused up/mix and the glue mix read them directly.
  • A Qwen3.8 ubatch walk carries its residual streams as BF16 values in the arena's other stream buffer, so no memory is added. The PLE site and the last combine write F32 streams, so every reader of the final buffer still reads F32.
  • gate_hc_gated gains a clause for the HC norm at hidden 4352, past one chunk a thread.

Release notes: Changed: Qwen3.8 FP4-Local prompt processing is 8.1% faster on a DGX Spark at a 4096-token prompt, with TTFT p95 7.4% lower.

Code shape

  • No second copy. BF16 rounding in three gate binaries now goes through rounding::bf16_round; the final-buffer rule written twice in the Qwen3.8 body is final_res.
  • Model code holds only architecture facts. The HC, PLE and GEMM owners gained no per-model branch; the Qwen3.8 ubatch walk picks the BF16 streams.
  • Dead code is gone. The in-place hc_gated_combine_4w, the old normed-output type, WideParts::cur and UnitRows38::cur are removed.
  • No silent failure. A stream window past its buffer or a mix with the wrong stream length is refused by name.
  • Comments state what is true now.
  • No relaxed gate. The BF16 xn band adds BF16's unit roundoff with PIN(2026-10-28); the moved spill pins and the unsafe ratchet carry PIN lines.
  • cargo fmt and cargo clippy: their results are under "What I ran".

Duplication found or removed (path:line), or "none": crates/gpu-gates/src/rounding.rs:19 replaces the copies in gate_dspark_hc.rs, gate_hc_gated.rs and gate_ple.rs; crates/gpu/src/arch/qwen3moe/scratch38.rs:268 replaces body38's two copies.

What I ran

Timed runs use one DGX Spark and nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6887e18c089fdea8509a33e63429a3300, against upstream 89a728d26d90a8f2a693ce011f84c395b0cea69c, with the MTP draft off. One request runs at a time: a 4096-token prompt and 128 generated tokens at temperature 0, on eight windows of a code corpus. Each side has one round after one discarded round, base then head. Prefill and decode are the server's timings and TTFT is the client's.

git -C base checkout 89a728d26d90a8f2a693ce011f84c395b0cea69c
(cd base && 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)
git -C head checkout 790a0bfcbb6c11b852c69eb27a3432151b001489
(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

Each cell is one round over the eight windows.

Metric Base Head Difference
Prefill, draft off, code, tok/s 2296.0 2481.5 +185.4 (+8.1%)
TTFT p95, draft off, code, ms 1790.2 1657.1 -133.1 (-7.4%)
Decode, draft off, code, tok/s 31.41 31.09 -0.32 (-1.0%)

Prefill is 8.1% higher and TTFT p95 is 7.4% lower; decode moves -1.0%.

  • cargo check --target x86_64-unknown-linux-gnu --workspace --all-targets with every gate feature: Finished with no warning line.
  • DGX Spark, just gate-gpu-hc-gated run as its two steps (cargo oxide build --arch sm_121a ... --bin gate_hc_gated and bash tools/gpu-gate.sh gate_hc_gated): PASSED: gate_hc_gated.
  • DGX Spark, just gate-gpu-ple run the same way: gate_ple: 24 clauses, 0 failed.
  • RTX 5090, just gate-gpu-hc-gated built with --arch sm_120a: PASSED: gate_hc_gated.
  • A mutant of the new hidden 4352 clause (let one = true; in the norm) turns its three hidden[...] lines to bit_equal=false FAIL on the DGX Spark, with FAIL-FIRST mutant rc=1; the clean tree passes all three.
  • A mutant that drops the BF16 output's overflow check in the PLE conv turns the new fault conv BF16 output line to FAIL on the DGX Spark, with gate_ple: 24 clauses, 1 failed and FAIL-FIRST mutant rc=1; the clean tree passes it.
  • DGX Spark, just gate-ptx-spill at sm_121a: PTX-SPILL arch=sm_121a rc=0.
  • DGX Spark at 790a0bfcbb6c11b852c69eb27a3432151b001489, cargo fmt --all --check: exit 0, no diff.
  • DGX Spark at 790a0bfcbb6c11b852c69eb27a3432151b001489, just lint (sm_121a): Finished with no warning line, exit 0.
  • DGX Spark at 790a0bfcbb6c11b852c69eb27a3432151b001489, just gate-gpu-hc-gated: PASSED: gate_hc_gated.
  • DGX Spark, just ptx-scan gate_hc_gated --features gpu --no-jit hc_gated_ at base and head: the decode entries hc_gated_norm_4 (md5 e2e0d61cce91577e832c0d84b9edbde6) and hc_gated_combine_4 (md5 df6155a75f474f43f76a2c6d3f2ca143) are identical, with the same registers, shared memory, spill and loads.

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)
  • NVIDIA GB10, driver 595.84 (gate runs; nvidia-smi reports NVIDIA GB10, 595.84), CUDA 13.3.1 in the build container

Gate runs also used an RTX 5090:

  • NVIDIA GeForce RTX 5090, driver 595.99.02 (nvidia-smi reports NVIDIA GeForce RTX 5090, 595.99.02); the CUDA version was not recorded for these runs

AI help

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

…s; the down, its inject rows and the mix read them
…s; the PLE site and the last combine read them into F32 streams
… hidden 4352, in both arms

The norm's second walk over the streams (hidden above 4096) ran in no
gate. A Q8_0 site at hidden 4352 now holds the capped arm's xn to the
rule's bits, plain and after a combine, and the wide arm's plain xn.
The norm's register-reuse PIN carries its commit's date.
@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: two comments are wrong now (a stale PIN block and a misplaced doc line); no behavior defect survived.

Must fix

1. unsafe-ratchet.txt holds two PIN blocks for one change, and the first names code that does not exist

tools/unsafe-ratchet.txt:664 The first block gives the same move (gpu 2781 -> 2803, 361 -> 375) as the second block at line 670. It names NormedOut, which no file in the tree defines (Grep: only these two comment lines). The second block says Slots "replaces NormedOut, norm_wide", but norm_wide is new in this diff. A reader cannot tell which new code the count pays for.
Cost: the PIN is the evidence for a raised ratchet; a wrong one costs a re-audit each time the file is touched.
Fix: delete lines 664 to 669 and move their items (Bf16WordCols, MmaCols::landed_fits, hc_gated_norm_4w_bf16, mix_glue, hc_gated_mix_4_bf16) into the second block. In that block, drop which replaces NormedOut, so Slots is listed as new code.

2. check_hidden carries check_combine's doc line

crates/gpu-gates/src/bin/gate_hc_gated.rs:741 The line /// Clause 4 (module doc). was check_combine's. The new function was inserted between it and check_combine (line 804). Now check_hidden claims clause 4 (its clause is 10, module doc line 67) and check_combine has no clause line.
Fix: move the line above fn check_combine, and start check_hidden's doc with /// Clause 10 (module doc).

Non-blocking

⚠ Precision change without its e2e proof: the ubatch walk now rounds every stream value to BF16 at each combine, init and PLE site. AGENTS.md (line 115) asks for the gate-gpu-e2e count pin for "float sum order or precision". Gate (g) of gate_qwen4exp_e2e.rs:175 holds the walk's logits and stores to gemm_band, which models the q8 step only. The PR body shows neither run. Please add both outputs. If (g) goes red, the band needs a dated PIN with the 2^-8 term, as xn_band has.

⚠ Decode moved -1.0% in one round (31.41 to 31.09 tok/s), and the decode entries should be unchanged. Please show ptx-scan equal for the narrow entries (hc_gated_norm_4, hc_gated_combine_4), or a second round.

⚠ PIN date edited: hc_gated.rs:741 changes PIN(2026-10-27) to PIN(2026-10-26) on an unrelated lint allow. Restore the date, or say why it moved.

⚠ Spill grows with no timing: bf16_mma_norm_gate 572 to 644 B on sm_121/sm_121a. The pin says FP4-Local does not run it, so the timed A/B does not cover it. State the checkpoint and one prefill timing where it runs, or that no shipped path reaches it.

⚠ Clause 10 (hidden 4352) runs only F32 streams (gate_hc_gated.rs:748). The production case, BF16 streams at 4352 (hc_gated_norm_4w16, _bf16), has no line there; check_wide_bf16 uses WIDE only. Consider a wide_mix16 line at HID in hidden_lines.

Checked

  • Duplicates: 24 new items checked. Hit: gate_hc_gated bf16_bits vs vision_taps::to_bf16 (two lines, not worth a shared owner). The hc_gated.rs and ple.rs dryer pairs are #[kernel] entries that differ only in slice types; the device ABI forbids a generic entry.
  • Complexity: enqueue_mix gained a branch decided in one match; the others are test or match-arm growth.
  • Silent failure: 9 sites followed; BF16 overflow in the PLE conv raises Ple, window_of and check_mix refuse by name.
  • Tests: planting x unrounded in the norm's res.store turns wide[bf16_streams] red; the wrong half in Slots<u16>::store turns combine_alone red.
  • Gates: xn_band and the spill pins carry dated PINs. Escape catalog: no match.

Notes

  • The timed base 89a728d is not the PR's base e7eae36. Confirm no commit between them touches these paths.
  • The cargo fmt and cargo clippy box is unchecked and "What I ran" lists no result for either.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_dspark_hc.rs, crates/gpu-gates/src/bin/gate_hc_gated.rs, crates/gpu-gates/src/bin/gate_ple.rs … and carries a gate run on the author's card, which counts as verified.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@github-actions github-actions Bot added gpu-evidence Verified on the author's card: the pull request carries the gate run and its output and removed needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 28, 2026
…or the BF16 streams; the range-loop pin keeps its date
@juliankang4

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. The two must-fix items are fixed in 790a0bf, and the body now carries the fmt, clippy and ptx-scan results.

1. Two PIN blocks in unsafe-ratchet.txt. Fixed. There is now one PIN(2026-10-28) block for gpu 2781 -> 2803 blocks and 361 -> 375 fns. It lists the new code only: Bf16WordCols, MmaCols::landed_fits, the Slots trait for F32 and BF16 values, norm_wide, the hc_gated_norm_4w16 and hc_gated_norm_4w_bf16 entries, mix_glue, hc_gated_mix_4_bf16, conv_unit, ple_conv_bf16 and window_of. NormedOut is no longer named.

2. check_hidden carrying clause 4. Fixed. /// Clause 4 (module doc). is back above check_combine, and check_hidden now opens with /// Clause 10 (module doc).

BF16 streams and the e2e count pin. I could not run gate (g) here. The real tier needs the reference set ref_qwen4exp (its MANIFEST.tsv), which is not on our machines. The fixture tier stops in 0 s with stale recorded fixture budget 9482272768, and it stops the same way at base 89a728d. gate-gpu-e2e runs the 27-layer V2-Lite chain, which does not reach the HC path.

Decode -1.0%. just ptx-scan gate_hc_gated --features gpu --no-jit hc_gated_ on the DGX Spark gives the same PTX for both decode entries at base and head: hc_gated_norm_4 (md5 e2e0d61cce91577e832c0d84b9edbde6) and hc_gated_combine_4 (md5 df6155a75f474f43f76a2c6d3f2ca143). Registers, shared memory, spill and load columns are equal too. The body now has this line.

PIN date on hc_gated.rs. Restored to PIN(2026-10-27). This PR had no reason to change it.

Spill of bf16_mma_norm_gate. The entry runs from site::resident_gemm_norm_gate when the norm-gate projection's weight is BF16, which is the NVFP4 checkpoint during prompt processing. FP4-Local's projection is MXFP8, so the timed runs here, all on FP4-Local, do not cover it, and I have no NVFP4 prefill timing for this head.

Clause 10 and BF16 streams at 4352. Clause 10 runs F32 streams at hidden 4352. The BF16 streams at 4352 are not in hidden_lines; check_wide_bf16 covers the BF16 forms at WIDE. I left the gate as it is in this PR.

Base 89a728d against e7eae36. The nine commits between them touch Metal, the justfile, the release tools, hf quant config, model-hf cut and the recipe tools. None of them touches a file this PR changes (git diff --name-only 89a728d26 e7eae361 and the PR's file list share no path).

fmt and clippy. On the DGX Spark at 790a0bf, cargo fmt --all --check exits 0, and just lint (sm_121a) finishes with no warning line. The body's box is checked and lists both.

(AI 코딩 에이전트가 작성한 코멘트이며, 내용은 제가 확인했습니다.)

@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: both earlier must-fix items are fixed, and the new commit adds no defect.

Since the last review:

  • Must fix 1 (two PIN blocks in unsafe-ratchet.txt): fixed. One block lists the new names; each exists in PR_TREE. Counts (gpu 2803 375) are unchanged.
  • Must fix 2 (misplaced doc line): fixed. check_hidden says clause 10, check_combine says clause 4.
  • ⚠ PIN date: fixed. hc_gated.rs:741 is PIN(2026-10-27) again.
  • ⚠ Decode -1.0%, ⚠ fmt and clippy: answered in the body (ptx-scan equal for the decode entries; fmt and just lint exit 0).
  • ⚠ e2e proof, spill timing, BF16 line at hidden 4352: still open, below.

Non-blocking

⚠ Precision change without its e2e proof: the walk rounds every stream value to BF16. AGENTS.md asks for the gate-gpu-e2e count pin for a precision change. The body shows neither that run nor gate (g) of gate_qwen4exp_e2e. Add both outputs. If (g) goes red, the band needs a dated PIN with the 2^-8 term.

⚠ Spill grows with no timing: bf16_mma_norm_gate 572 to 644 B. The pin says FP4-Local does not run it, so the timed A/B does not cover it. Name one checkpoint and a prefill timing where it runs, or say no shipped path reaches it.

⚠ Clause 10 runs only F32 streams at hidden 4352. The production case, BF16 streams at 4352 (hc_gated_norm_4w16, _bf16), has no line there. Consider a wide_mix16 line at HID in hidden_lines.

Checked

  • Duplicates: the new commit adds no function, type or constant. The earlier items and the dryer pairs stand.
  • Complexity: the new commit changes no function body.
  • Silent failure: no new site; comments and a PIN only.
  • Tests: none changed. Gates: no pin moved. Escape catalog: no match.

Notes

  • The timed base 89a728d is not the PR's base e7eae36. Confirm no commit between them touches these paths.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_dspark_hc.rs, crates/gpu-gates/src/bin/gate_hc_gated.rs, crates/gpu-gates/src/bin/gate_ple.rs … and carries a gate run on the author's card, which counts as verified.

🔨 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 93c563f into midagedev:main Oct 28, 2026
8 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 gpu-evidence Verified on the author's card: the pull request carries the gate run and its output 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