Skip to content

gpu: HC prompt projections use the shared BF16 tensor-core dispatch - #693

Merged
juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-bf16-prefill
Oct 23, 2026
Merged

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

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8의 HC 프롬프트 투영을 BF16 텐서 코어로 돌려, DGX Spark에서 4K 프롬프트 prefill이 752.753 tok/s에서 888.469 tok/s로 빨라집니다.

Part of #565.

What and why

Qwen3.8's hyper-connection (HC) layers run two BF16 projections on every prompt token: a down projection from 10,240 values (four streams of 2,560) to a 320-wide rank and an up projection back to 10,240. A 4,096-token prompt makes 97 calls of each, with shapes (M, N, K) = (4096, 320, 10240) and (4096, 10240, 320). Both called the exact BF16 tile launcher directly, so they never reached the hardware dispatch that the other BF16 prompt sites use. On a GB10 that dispatch picks the tensor-core MMA.

This PR has three commits.

  1. gpu: HC prompt projections use the shared BF16 tensor-core dispatch. Q8F32Kernels in crates/gpu/src/q8f32.rs owns the BF16 prompt choice and the GB10 capability test, and both site.rs and the HC code ask it. HC no longer launches the tile kernel itself. Ordinary BF16, MXFP8 and FP8_B128 sites keep the exact-tile replay they had.
  2. gemm: keep exceptional MMA cells independent of neighboring columns. This is a correctness fix that the first commit needs. When one operand row or column held a NaN or a value outside the range the MMA handles exactly, the whole-tile exact replay recomputed every column of the tile, so a bad column changed the arithmetic of clean neighbors. HC now takes a second instantiation of the same MMA body and exact owner that marks the bad rows and columns and replays only the marked cells. The HC gate caught the defect: with the dispatch change alone it printed the other columns clean=false FAIL and exited 1. With this commit, the same check and the new wide[subnormal_columns] check both pass (the run is in the GPU evidence below).
  3. gpu: fuse HC prompt up projection and gated mixing. On GB10 with more than 8 columns, the up projection hands its MMA fragments straight to the sigmoid gate and the ordered four-stream mix, so the gated g plane of 10,240 values per column is no longer written and read back. Rows are permuted so the four streams of one column sit in the same warp group. Tiles with an exceptional cell fall back to the existing g allocation and the checked exact replay. The gate and the FMA order are shared with the narrow decode path, and the decode geometry for 2 to 4 columns does not change. On the normal 4K path this removes 335,544,320 bytes of logical traffic per site, 32,547,799,040 over the 97 sites [derived from the source, not a DRAM counter]. The allocation stays because exceptional tiles and the other formats still use it.

The activation rounding to BF16 is the default for these sites, with no new option or runtime lever.

Release notes: Changed: HC prompt projections on Qwen3.8 run on the BF16 tensor cores with the up projection fused into the gated mix, which speeds up 4K prefill on a DGX Spark.

Code shape

  • No second copy. There is one MMA tile computation and one exact tile owner. The HC entry and the ordinary entry call the same bf16_mma_body, specialized at compile time for independent cells or full-tile replay.
  • Model code holds only architecture facts. No model file changes. The fused entry needs the four-stream, rank-320 HC operator and refuses other shapes by name.
  • Dead code is gone. The direct tile launch for HC is removed. The g allocation stays because exceptional tiles and other formats read it.
  • No silent failure. The fused entry and the new MMA entries keep named refusals; the HC gate checks them.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or lint level moves. The ordinary exact-replay pins are unchanged. The new PIN(2026-10-23): lines record the unsafe counts and the PTX shapes of the two new entries.
  • cargo fmt is clean on what I touched.

Duplication found or removed (path:line): none. The overlaps the scan reported are two entry points that call the same tile body (crates/gpu/src/q8f32.rs:1823 and :1793) and the shared launch geometry (:2705, :2735).

What I ran

Speed A/B

The model is nvidia/Qwen3.8-Flash-Next-NVFP4 at revision fc694b54fb0174e0913e6adf86691ef85a4ead47. Both servers run with one slot, draft off, a 4,224-token context and no cache RAM. Each arm loads once and sends two 4,096-token prompts from a code corpus, one client at a time, greedy, generating 2 tokens. Main and head ran back to back on one idle GB10, and every request evaluated 4,096 tokens with 0 cached tokens. The A/B ran on this code before the PTX and unsafe pin files were updated and the branch was rebased onto the current main. The rebase left the implementation diff unchanged.

Metric Main Head Change
Median prefill tok/s, 4,096-token prompt 752.753 888.469 +18.03%
Median TTFT ms 5441.530 4610.243 -15.28%

Delta (head minus main): prefill +18.03% (752.753 to 888.469 tok/s), TTFT -15.28% (5441.530 to 4610.243 ms).

Prefill tok/s is the 4,096 prompt tokens divided by the request's wall time. The server-side figures move the same way, 753.605 on main and 889.653 on head. Load takes 202.6 s on main and 202.2 s on head and is outside these numbers. A separate 32-token greedy continuation of the same prompt matched on all 32 tokens.

This is one main/head pair with two requests per arm. I make no significance claim from it.

GPU evidence

Card and driver, from nvidia-smi:

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |

Card state when the timed sitting started, with the clock cap lifted, and after it, with the cap restored (nvidia-smi --query-gpu lines):

NVIDIA GB10, 595.84, 51, 4.19 W, [N/A], 208 MHz, [N/A], [N/A], [N/A]
NVIDIA GB10, 595.84, 60, 13.12 W, [N/A], 2366 MHz, [N/A], [N/A], [N/A]

The gates that cover the changed kernels:

just gate-gpu-hc-gated
just gate-gpu-bf16
bash tools/gpu-gate.sh gate_gemm --case dense_mma
gpu-gate.sh: gate_hc_gated ran 2 s (exit 0)
gpu-gate.sh: gate_bf16 ran 4 s (exit 0)
gpu-gate.sh: gate_gemm ran 1 s (exit 0)

They check eager and graph equality, untouched output tails, the named refusals, columns with NaN or subnormal operands, and the exact power-of-two range cases. The HC oracle KL is 1.591600e-5 for the down projection, below the Q8_0 reference's 4.643809e-4 on the same shape.

FAIL-first for the column fix. The first HC gate run, with the dispatch change alone, failed on the neighbor-column check. With the fix, the same line and the new subnormal-column check pass:

wide[fault] ... the other columns clean=false FAIL
gpu-gate.sh: gate_hc_gated ran 2 s (exit 1)
wide[fault] ... the other columns clean=true PASS
wide[subnormal_columns] other_columns_clean=true one_column_bits=true PASS

Four more mutations each fail a numerical check and the restored source passes: removing the HC down call, removing the fused up and mix, removing the BF16 site call, and widening the operand range check.

FAIL_FIRST hc_down numerical failure confirmed
FAIL_FIRST hc_up_mix numerical failure confirmed
FAIL_FIRST site numerical failure confirmed
FAIL_FIRST cell_range numerical failure confirmed

CPU geometry and FMA-order tests for the HC layout:

cargo oxide test --arch sm_121 -- --locked -p bloomery-gpu --release --lib hc_mma_ -- --nocapture
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 383 filtered out; finished in 0.00s

The tier t0 contribution check on the final head: DONE tier=t0 total=107 red=0 wall=348s.

Reproduce

BLOOMERY_DRAFT=off bloomery-serve -m <Qwen3.8-Flash-Next-NVFP4 folder> --host 127.0.0.1 \
  --port <port> --parallel 1 --ctx-size 4224 --cache-ram 0

Run main's binary and this branch's in turn. Each request sends 4,096 token ids from a code corpus as a greedy streamed POST /v1/completions with max_tokens 2. The greedy check is a POST /completion of the same ids with n_predict 32, temperature 0 and top_k 1.

Hardware

A DGX Spark (NVIDIA GB10, driver 595.84, CUDA 13.3, sm_121 release builds). The clock cap was lifted for the timed sitting and restored afterwards. Nothing else used the GPU.

What I ran into

None of this blocks the PR.

  • The PTX shape pins for the two new entries use the measured ptxas stack frame for the default table. I did not measure the spill values under the compute capability 8.6 driver JIT, and the PIN comments in the pin files say so. The two GB10 tables use the driver JIT values: the column-independent entry has 0 spill and 0 local bytes, and the fused HC entry has 84 spill bytes and 32 local bytes per thread. I make no zero-spill claim for the fused entry and did not check whether its local accesses are on the hot path.
  • gate_gemm without a --case opens a Qwen3 model fixture that the test machine did not have, so I did not run that gate. The Qwen3 case exercises routed GEMM, which this diff does not change: in gemm/kernels32.rs the only edits pick the new generic argument in the dense MXFP8 and FP8_B128 MMA calls. The --case dense_mma run above is the dense path this diff does change.
  • The ordinary BF16 MMA entry, timed at four HC-sized shapes against main, stays within -0.25% to +2.50% of main's time [derived from ten timed calls per shape]. These time the ordinary entry only.
  • The A/B covers 4,096-token prompts on one DGX Spark only. I did not time other prompt lengths, concurrency or TP=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 22, 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 must-fix finding remains.

Non-blocking

⚠ Complete precision-change evidence: crates/gpu/src/hc_gated.rs:2192 routes HC activations through BF16 rounding on GB10. The change-class table asks for the gate-gpu-e2e count-pin result. Attach that output, both tested commit hashes, and the exact A/B commands with output so the evidence is reproducible.

⚠ Identify replay diagnostics: crates/gpu/src/hc_gated.rs:1777 has a shared replay owner and recurrence checks, but the PR identifies no retained tools/ probe or stats()/record exposing replay decisions. Name the existing diagnostic, or explain how the gate output supplies the fix's debuggability layer. This preserves a way to diagnose another numeric failure.

Checked

Duplicates: both dryer pairs are thin entries using shared computation, with distinct format or replay semantics.
Complexity: the reported growth covers shared MMA/isolation logic, numerical fixtures, graph comparison and fused dispatch.
Silent failure: non-finite mixed outputs raise HcMix; Head::tokens returns a fault error.
Tests: the HC gate checks exceptional-column independence, per-cell replay arithmetic, and eager/graph equality. The PR reports FAIL-first and GPU mutation results.
Gates: no existing band or tolerance moved; new spill and unsafe-count pins carry dated reasons.
Escape catalog: C1–C4 do not match the diff.

Notes

GPU gates and timing were not rerun during validation.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_bf16.rs, crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu-gates/src/bin/gate_hc_gated.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 bc0e553 into midagedev:main Oct 23, 2026
6 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