Skip to content

gpu: the HC up-mix's passes split the warp's columns, so a mix step reads a whole sector of each stream and its gate stores fall in 32 banks - #988

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

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

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8 FP4-Local의 긴 프롬프트 prefill을 DGX Spark에서 빠르게 하는 속도 PR입니다.

What and why

Prompt prefill on Qwen3.8 FP4-Local spends time in the dense MXFP8 gemm, the HC up-mix, the PLE row decode on the host and the end-of-prompt checkpoint copies. This PR shortens each of them.

  • gemm/f32tile.rs, gemm/nvfp4mma.rs: the MXFP8 W8A8 tile's stages arrive by TMA on stage barriers, so no block barrier runs in its main loop. A producer proxy fence orders each stage refill after the consumers' reads. norm_gate stays on cp.async.
  • ple.rs, body38.rs, quant.rs: a ubatch's NVFP4 PLE rows decode on the card from the planes the NVMe reader copied, instead of on the host.
  • hc_gated.rs: the HC norm's block sum has no terminal barrier, since its slots are never written after it. The up-mix loops split the warp's columns, so a mix step reads whole sectors of each stream and its gate stores use separate banks.
  • body38.rs, scratch38.rs: a prompt ubatch's end checkpoint copies each delta layer's stores as soon as the walk finishes that layer, under the walk's later layers.
  • tools/unsafe-ratchet.txt: two dated PINs for the new unsafe blocks and functions (gpu 2812 to 2834 blocks, 381 to 386 fns), each with its reason.

Release notes: Changed: Qwen3.8 FP4-Local prefill and time to first token are faster on a DGX Spark, with the same greedy output.

Code shape

  • No second copy. The TMA stage loop sits in the one MXFP8 tile in gemm/f32tile.rs; the PLE decode kernel lives in ple.rs beside the host decode it replaces for ubatch rows.
  • Model code holds only architecture facts. The shared tile, HC and PLE owners gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing I made unused is left behind.
  • No silent failure. The new unsafe functions carry a Safety section and their span checks fail by name.
  • Comments state what is true now.
  • No relaxed gate. No band or tolerance moved. The unsafe ratchet re-pin carries PIN(2026-10-29): 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.

What I ran

Speed

Model nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6887e18c089fdea8509a33e63429a3300, with the Q8_0 MTP draft for the draft-on arms. Each request is a 4096-id prompt and 128 greedy tokens (temperature 0) from eight corpus windows 50,000 ids apart, after one lead-in. Base is upstream main 686e8cc5ffb0cb20027fe315bd0dfb2863b17c0b and head is c65f4b702604adab8d7ad4ac7b238ba38a16f487, each built from its own tree and run alternately in the order base, head, head, base, base, head. Each cell is the median of three rounds. Greedy output is identical on every request.

git checkout 686e8cc5ffb0cb20027fe315bd0dfb2863b17c0b   # main
cargo oxide build --arch "$(just --evaluate arch)" -- --locked -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve

Build the head the same way, serve $MODEL_FP4L from each build, and send the requests above, alternating the two trees. For the draft-on arms set BLOOMERY_DRAFT=mtp and BLOOMERY_MTP_DRAFT to the MTP draft file.

Ranges are "separate" when the three head rounds and the three base rounds do not overlap.

Arm Metric main head Change Ranges
Draft off, code-fn Prefill tok/s 2564.2 2625.96 +2.408% separate
Draft off, code-fn TTFT p95 ms 1604.15 1566.05 -2.375% separate
Draft off, code-fn Decode tok/s 31.743 31.6332 -0.346% overlap
Draft on, code-fn Prefill tok/s 2418.09 2471.85 +2.223% separate
Draft on, code-fn TTFT p95 ms 1700.13 1663.55 -2.152% separate
Draft on, code-fn Decode tok/s 58.388 58.2151 -0.296% overlap
Draft on, prose-en Prefill tok/s 2494.83 2555.54 +2.433% separate
Draft on, prose-en TTFT p95 ms 1648.42 1608.99 -2.392% separate
Draft on, prose-en Decode tok/s 42.0698 41.6023 -1.111% overlap

Prefill and TTFT p95 are resolved in every arm (resolution 0.500% to 1.119%). Decode is not changed by this PR; its rows are inside the 1.002%, 0.617% and 1.842% the run can resolve.

Gates and tests

cargo oxide build --arch "$(just --evaluate arch)" -- --locked -p bloomery-gpu-gates --features gpu --release --bin gate_gemm --bin gate_hc_gated --bin gate_mxfp8 --bin gate_ple
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_hc_gated
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_gemm --case mxfp8_w8a8
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_gemm --case dense_mma
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_gemm --case zgate
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_mxfp8
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_ple
GATE gate_hc_gated rc=0 0 fail-lines;
GATE gate_gemm --case mxfp8_w8a8 rc=0 0 fail-lines;
GATE gate_gemm --case dense_mma rc=0 0 fail-lines;
GATE gate_gemm --case zgate rc=0 0 fail-lines;
GATE gate_mxfp8 rc=0 0 fail-lines;
GATE gate_ple rc=0 0 fail-lines; gate_ple: 28 clauses, 0 failed

The new unit test for the up-mix's scratch slots ran on an RTX 5090 machine:

BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local ./tools/box.sh 'bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- hc_mix_slots --nocapture'
test hc_gated::tests::hc_mix_slots_fill_the_scratch_and_every_bank ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 458 filtered out; finished in 0.00s

The head also builds for the GB10 target with cargo oxide build --arch sm_121a -- --locked -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve and the same command with --features gpu --bin gate_hc_gated --bin gate_ple --bin gate_gemm --bin gate_mxfp8: both finish with COMPILE OK.

Hardware (if the change is for a machine)

The change targets the GB10 (sm_121a). The timed runs and the gates ran on a DGX Spark.

NVIDIA GB10, 595.84
| 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 model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja 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 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: CLEAN: No behavior bug or proven quality defect survived validation.

Non-blocking

⚠ Checkpoint ordering coverage: crates/gpu/src/arch/qwen3moe/body38.rs:3161. Removing this wait leaves the new owner-mapping test green. The existing restore clause uses Prompt38::Pass (gate_qwen4exp_e2e.rs:4456). Extend it to restore a GEMM checkpoint and compare stores with an uninterrupted run. Show FAIL-first with the wait removed.

⚠ Shared tile proof: crates/gpu/src/gemm/f32tile.rs:1262. The extraction also reaches bf16_mma_cols_gemm through bf16_mma_body (kernels32.rs:1344). Attach an identical PTX comparison for the BF16 consumers and resource counts for the TMA geometry, as the change-class table requires. The reported W8A8 timing does not supply those proofs.

Optimization headroom

  • B, Overlap waiting: crates/gpu/src/arch/qwen3moe/body38.rs:3153. Enqueue copies by writer layer while preserving store indices. The current order puts PLE and key rings after every delta store. In the pinned 48-layer layout, this could advance the PLE ring and 11 key-ring copies per 4,096-position mark [derived].

Checked

Duplicates: the extracted MMA scale and store logic has callers in both stage paths.
Complexity: the new TMA pipeline and checkpoint lifecycle add synchronization work; complexity alone is not a finding.
Silent failure: checkpoint owner/event lookup errors propagate; failed-unit cleanup preserves the original error.
Tests, paper mutation: mapping keys to the PLE site at body38.rs:373 fails the owner assertion; removing the wait at line 3161 leaves that assertion green.
Gates: scratch, placement and unsafe pins carry dated reasons. FAIL-first runs are not reported.
Escapes: no catalog pattern matched the cited changes.

Notes

Static validation; no GPU tests run. Reported GPU runs name 686e8cc→c65f4b7; the reviewed pair is 7f04223→4e22b7c. Supply the correspondence or a witness for the reviewed head.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu-gates/src/bin/gate_ple.rs, crates/gpu/src/arch/qwen3moe/body38.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 29, 2026
@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 92997d0 into midagedev:main Oct 29, 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 gpu-evidence Verified on the author's card: the pull request carries the gate run and its output model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja 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