Repository navigation
hc_gated: read the normed streams once for an inject site's down and inject on GB10 - #759
Conversation
There was a problem hiding this comment.
Verdict: CLEAN: No reachable behavior defect or proven quality defect survived review.
Non-blocking
⚠ Complete the precision-change validation: crates/gpu/src/hc_gated.rs:2351. The inject now rounds activations to BF16, and the body reports a changed greedy window. AGENTS.md's precision class requires the gate-gpu-e2e count pin; only the HC gate ran. Supply that result and the affected Qwen3.8 gate outputs to check the composed prompt path before merge.
⚠ Complete the measurement evidence: crates/gpu/src/hc_gated.rs:2178. The GB10, 4096-id, C=1, draft-off A/B has summaries but lacks the timed head hash, exact model filenames and timing commands with output. Add those artifacts so the measurements can be reproduced. Also supply the final-head gate-ptx-spill result; the reported run predates the new pin rows.
Optimization headroom
- G. Per-launch and per-sync fixed cost: crates/gpu/src/hc_gated.rs:2450. Folding the elementwise bottleneck and weight glue into the packed entry, using the existing MMA tile owner, would remove one launch per packed inject site per prompt batch, or
1/mlaunches per prompt token for a batch ofmtokens [derived].
Checked
Duplicates: the packed MMA entry reuses bf16_mma_body; both precision checks use bf16_dot_rel. No duplicate finding.
Complexity: enqueue_mix adds packed dispatch; check_wide adds replay and precision checks; wide_mix adds layout unpacking.
Silent failure: 1 default site followed. wgt_ref.unwrap_or(&[]) receives Some from site.host(true). Non-finite dots reach the HC fault word and NaN outputs.
Tests: hc_gated.rs:2094 off-by-one → glue assertion; hc_gated.rs:1743 swapped lanes → MMA band; hc_gated.rs:1718 wrong replay staging → bit equality. The PR reports all three FAIL-first runs. The new entry is included in the local-depot check.
Gates: the BF16 weight-band extension and unsafe ratchet carry dated PIN reasons. No gate removed.
Escape catalog: C1–C4 do not match this diff.
Notes
Static validation; no GPU gates executed here. No ledger lessons are in force.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_hc_gated.rs, crates/gpu-gates/src/rounding.rs, crates/gpu/src/gemm/f32tile.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)
|
The review is done and the contribution check passed, so I'm merging this. |
Qwen3.8 prompt 처리의 HC에서 inject가 있는 자리의 down과 inject를 BF16 tensor core 곱 한 번으로 합쳐, GB10에서 정규화된 스트림을 한 번만 읽게 하는 작업입니다.
Part of #565.
What and why
At each HC site that has an inject weight, Qwen3.8's prompt processing runs a BF16 down product of 320 rows (
bf16_mma_gemm) and then a separate F32 inject product of 4 rows (f32_tile_gemm). Both read the normed streamsxnfrom memory.On FP4-Local, one 4096-id prompt spends 177.9 ms of GPU time in these two kernels on a GB10 (98.4 ms in the down product over 97 launches, 79.5 ms in the inject product over 96 launches).
This PR reads
xnonce for both. On GB10 an inject site's down rows and its inject rows are one BF16 tensor core product of 324 rows. A 128-row MMA tile makes 320 and 324 rows three row tiles each, so the grid stays the same size, and the separate inject launch is gone.HcDownRows(crates/gpu/src/hc_gated.rs) is a tile weight that presents the down words and the inject rows as one 324-row weight. It reads both existing buffers in place, so nothing is copied at load. The down piece is fetched withcp.async; the inject piece reads eight F32 values and writes them to shared memory as BF16.hc_gated_down_mma_4is the new kernel entry. It runsbf16_mma_bodyoverHcDownRowsand writes[m][324], with each column's inject dot after its down dot.hc_gated_lo_4x320takes apackedargument and reads[m][324]when it is set, and[m][320]followed by[m][4]otherwise.HcWideScratchdrops its separateinjbuffer and growsdownby the same size, so the scratch keeps its total bytes.enqueue_mixtakes the packed path for a BF16 down with an inject ondense_mma(GB10). A Q8_0 down and every path off GB10 are unchanged.land_valuesandmma_launchincrates/gpu/src/gemm/become visible inside the crate for the new tile weight, andbf16_dot_relmoves out ofcheck_mmaincrates/gpu-gates/src/rounding.rsso the gate shares it.The one numerical boundary this changes is that
xnis rounded to BF16 in the inject dot, which the down product already does.Both Qwen3.8 checkpoints store the inject weight as BF16
[4, 10240](98 tensors each), so rounding the weight to BF16 for the tensor core is exact. The replay path in the gate keeps the F32 values.This also supplies the base and head GB10 comparison that the review of #756 asked for with the next HC kernel change.
Release notes: Changed: Qwen3.8 prompt processing reads the normed streams once for an HC inject site's down and inject on GB10, which cuts GPU time in those two kernels.
Code shape
HcDownRowsis the only place that knows the packed layout.bf16_dot_relis lifted out ofcheck_mmaso both gate checks call it, and the gate decides its BF16-and-GB10 condition in one place.HcWideScratch::injis removed.mma_launch's shape check and the 16-byte alignment check of both buffers, and a failure is a namedGpuError.PIN(2026-10-24)and its reason, and the unsafe ratchet is re-pinned for the new blocks, each with a SAFETY line.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.just mac-fmt-checkandjust mac-lintpass on a Mac. The CUDA crate's device code does not build there, so I did not run clippy on it.Duplication found or removed (
path:line), or "none": the duplicate scan flagshc_gated_down_mma_4(crates/gpu/src/hc_gated.rs:2178) against the MMA entriesq8f32.rs:1923andgemm/kernels32.rs:1068. They share only the entry shape of one stage and one body call. Each entry is monomorphic in its weight type, andbf16_mma_gemm's weight type cannot carry two buffers, so they do not merge.What I ran
Gate and greedy output
The gate below ran on this head's device code on a DGX Spark (GB10, driver 595.84, CUDA 13.3).
It checks, among others, that
hc_injectstays within its band (worst_err_over_band=2.245508e-2,kl=3.087345e-6, againstq8_kl=7.706974e-5for the Q8 representation), that a subnormal inject value in the out-of-range row replays bit for bit like the F32 tile, and that eager and graph runs give the same bits.In the server A/B below, NVFP4 gave identical tokens on main and head in all three 128-token greedy windows.
On FP4-Local, two of three windows are identical. In the second window the output differs from token 115 of 128, the same on both head arms and the same on both main arms. After the split, the head output is ordinary Python code with no repetition or nonsense tokens. I did not measure a model-level KL: the serving harness here has no logit KL tool for Qwen3.8, so the site-level
hc_injectKL above is the only KL number.FAIL-first
Each of three changes to the new device code turns the gate red on this head.
hc_gated_lo_4x320failswide[glue:wgt].HcDownRowsfetch makesdense_mma hc_injectleave its band by a large factor.HcDownRowsfails the newwide[inject-range]check.PTX and spill
The PTX comparison against upstream main
b66d38b4eon a DGX Spark (generate_ds41, sm_86 declarations, JIT at cc 12.1), on an earlier build with this head's device code, lists one added entry and one changed entry, both the intended ones:hc_gated_lo_4x320changes because of its newpackedargument. The dense MMA entriesbf16_mma_gemm,fp8_b128_mma_gemmandmxfp8_mma_gemmandhc_gated_up_mma_mix_4are not among the changed entries. The spill check on the compared build reports the new entry with no spill and no JIT local bytes at sm_121, sm_121a and sm_86:That run printed the entry as unpinned, because the pin rows were not yet in that build. This head adds its four
tools/ref/ptx-shapesrows at0 0. I did not rerun the spill check on this head, and I did not measure the cc8.6 driver JIT, so the sm_86 row keeps the zero stack frameptxasreported.Speed
Qwen3.8 FP4-Local and NVFP4 on one DGX Spark (GB10), C = 1, draft off, a 4096-id code prompt of 128 greedy tokens, three requests per arm. Each checkpoint began with a discarded warm load, main and head alternated in one sitting, and the clock cap was lifted only around each arm's requests. FP4-Local ran two arms per tree, six requests in all; NVFP4 ran one arm per tree. Kernel times come from one profiled request per arm.
Delta (head against main): the down and inject kernels of one 4096-id prompt take about 77 ms less GPU time on FP4-Local (177.9 to 99.6 ms plus about 1 ms) and about 79 ms less on NVFP4 (179.4 to 99.7 ms plus about 1 ms); FP4-Local end-to-end prefill +2.2% (1412.8 to 1444.3 tok/s) and TTFT -2.1% (2904.5 to 2843.5 ms), from one sitting, so a single observation whose request distributions overlap; the NVFP4 end-to-end requests varied by 15% inside one arm and are not a result.
The kernel saving is the same on both checkpoints, and the 61 ms drop in FP4-Local TTFT is about the size of the 77 ms kernel saving.
The whole prompt pass on NVFP4 shows -23.7 ms where the two kernels save about 79 ms, because an untouched routed GEMM (
gemm_nvfp4p) ran 29.3 ms slower in the head arm.On FP4-Local the end-to-end gain is small and the distributions overlap: two of the head arm's requests (1384.4 and 1377.1 tok/s) are below main's lowest request.
The three NVFP4 head requests read 1491.8, 1297.7 and 1312.2 tok/s from one server in one arm, a 15% spread that a kernel difference of about 2.8% cannot explain, so I do not read the NVFP4 end-to-end pair as a result.
On the profiled NVFP4 request, head reads 1419.8 and main 1408.5 tok/s, one request each.
Decode is the same on both sides for each checkpoint.
A kernel micro-benchmark on synthetic inputs (m = 4095, clock cap on) gives the same direction: one
enqueue_mixcall took 7.20 and 7.25 ms on main and 6.44 and 6.40 ms on head (-11%).Measured build against this head
The A/B ran on an earlier build of this commit over
b66d38b4e. This head is the same commit rebased onto the current upstream main, whose new commits add the MLX 4-bit format for the Metal backend; incrates/gputhey only add that format to the site list (site.rs) and the qwen35moe body (body35.rs), where no CUDA kernel reads it, and the HC kernels and the Qwen3.8 prompt path are unchanged. The final commit differs from the timed build only in the gate test and four newtools/ref/ptx-shapesrows. The device code is the same. The gate above, the FAIL-first runs and the Mac checks ran on this head, and the kernel micro-benchmark ran on an earlier build whose down, inject and glue code equals this head's.just mac-check,just mac-lint(unsafe ratchet 3 = 3) andjust mac-fmt-checkpass on a Mac, as dotools/check-unsafe.shand the PTX name check.I ran only
just gate-gpu-hc-gatedamong the GPU gates. The gates that the changed crates also touch, and the full test run, were not run here.Hardware
DGX Spark (GB10);
nvidia-smilines from the check job on this head:Models: Qwen3.8 FP4-Local and NVFP4.
What I ran into
None of this blocks the PR.
xnis rounded to BF16 in the inject dot. The output stays valid code. A model-level KL is not measured, as said above.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.