Skip to content

gpu: normalize independent BF16 output heads to MXFP8 - #665

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-c1-bandwidth
Oct 22, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-c1-bandwidth

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8 서버가 독립 BF16 출력 head를 load할 때 MXFP8로 바꿔 읽고, BF16 HC up의 m=1 전용 kernel을 더해 GB10의 C@1 decode를 빠르게 합니다.

Part of #565.

What and why

Single-request decode (C@1) on a GB10 reads the whole output projection (the LM head) from memory for every new token. A BF16 head stores 2 bytes per value. This PR changes two things on that path.

  1. An independent BF16 output.weight loads as MXFP8. Each value becomes one byte, with one scale byte for every 32 values, so the resident head takes about 1.03 bytes per value instead of the 2 in the file. The encoder rounds to nearest even and picks a power-of-two scale per 32 values. It applies when K is a multiple of 128; a head with another K stays BF16. Tied embeddings and the hyper-connection (HC) head-stage matrices keep their formats. head_card_format in crates/placement/src/placement.rs is the one owner of this choice, and both the placement and the upload read it, so their resident byte counts agree. The normal head and the MTP draft heads borrow the same resident planes, and the selected-row kernel (blocks_gemv_ids in crates/gpu/src/q8f32.rs) serves Q8_0 and MXFP8 rows alike, so no draft copy of the weight is added. The encoder refuses non-finite values and any value whose rounded MXFP8 form would leave f32 range, each with a named load error.
  2. The BF16 HC up kernel has an entry for one column. For m = 1 it keeps only the 320 bottleneck values in shared memory, where the general entry reserves 8 columns of 320. The m > 1 path is unchanged.

The MXFP8 head rounds the weights, so its logits differ slightly from the BF16 head. The default path is the faster one; greedy agreement and KL are reported below as diagnostics.

Release notes: Changed: an independent BF16 output head loads as MXFP8 on the card, which speeds up single-request decode on GB10.

Code shape

  • No second copy. The card format choice has one owner (file_card_format), called by placement, by the upload and by the GLM checkpoint folder's tensor-parallel plan. The selected-row kernel is shared by Q8_0 and MXFP8 rows.
  • Model code holds only architecture facts. The head rule is common placement and upload code, chosen by the tensor's name, role and type. The MTP files only borrow the resident planes.
  • Dead code is gone. Nothing I made unused is left behind; the new HC entry and the shared helper both have callers.
  • No silent failure. A head with a non-finite value, a value that rounds outside f32 range, a wrong shape or a bad selected id is a named error or a device fault.
  • Comments state what is true now. Head and encoder comments describe the current formats.
  • No relaxed gate. No band or tolerance moved.
  • cargo fmt and cargo clippy are clean on what I touched.

Duplication found or removed (path:line), or "none": none. The new selected-row kernel and the HC entry reuse the existing lane-partial arithmetic in crates/gpu/src/q8f32.rs and crates/gpu/src/hc_gated.rs.

What I ran

Head 417bcdc86, base main 2a2d2d2fa. The GPU gates below ran on a38851339. The head changes only host code after it: the GLM checkpoint folder's tensor-parallel plan counts a BF16 head at its MXFP8 size (16,896 bytes for 64 rows of 256, where it counted 65,536), and two tests expect the MXFP8 head. The decode timing ran on 4e5082d58 against 3e03d745c, the same device code for the output head; later commits add a finite-range refusal in the host encoder and the pins that follow the head's new format.

GPU Evidence

On an NVIDIA GB10:

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

The MXFP8 gate covers the head encoding, the row layout, selected ids, the invalid-id fault and the eager and replay bits:

just gate-gpu-mxfp8
mxfp8 clause=head.bits rows=19 k=128 m=1 equal=19/19 PASS
mxfp8 clause=head.bits rows=19 k=128 m=3 equal=57/57 PASS
gpu-gate.sh: gate_mxfp8 ran 6 s (exit 0)

The BF16 gate covers the raw BF16 words, and the HC gate covers a BF16 hyper-connection site:

just gate-gpu-bf16
gpu-gate.sh: gate_bf16 ran 2 s (exit 0)
just gate-gpu-hc-gated
gpu-gate.sh: gate_hc_gated ran 1 s (exit 0)

The tensor-parallel checkpoint gate, whose expected head bytes now follow the head's MXFP8 format:

just gate-gpu-glm5next-tp
gpu-gate.sh: gate_glm5next_tp ran 94 s (exit 0)

With the head conversion bypassed in both callers, the head output transposed and non-finite BF16 accepted, the placement test and the MXFP8 gate fail. With the source restored they pass:

GATE RED (exit 101)
GPU GATE RED: gate_mxfp8 (exit 1)

On a076b6e58, an RTX 5090 machine ran the encoder test for the f32-range refusal. It fails when the new bound is removed and passes with it restored:

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 382 filtered out; finished in 0.00s
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 382 filtered out; finished in 0.00s

Decode and prefill

One server load per arm, base then head, two requests per load. Each request has a different 4096-token code window and generates 128 tokens, at temperature 0 with top-k 1, no prompt cache and no draft, with --parallel 1 --ctx-size 4224. Model nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6887e18c089fdea8509a33e63429a3300, loaded from its checkpoint folder, on one GB10 with driver 595.84, CUDA 13.3 and release binaries.

Metric Base Head Change
C@1 decode (tok/s) 27.3817 29.3169 +7.07%
Prefill (tok/s) 509.6721 509.7835 +0.02%

Decode speed rose by 7.07%, and prefill did not change.

Each arm is one load with two requests. The base requests decoded at 27.670 and 27.519 tok/s, and the head requests at 29.589 and 29.505 tok/s.

Quality diagnostics over 64 greedy steps: the greedy token ids matched on 64 of 64. The KL is computed over the shared top 100 token ids plus one bucket for the rest, so it is a lower bound on the full-vocabulary KL. Its mean is 1.393e-5 and its maximum is 3.833e-4.

What I ran into

This does not block the PR. The m=1 HC kernel is in both timed arms, and its own effect was too small to separate from run-to-run variation, so I claim no speed gain for it. MTP draft throughput with the shared head planes was not measured.

Hardware

One NVIDIA DGX Spark (GB10), driver 595.84, CUDA 13.3. The encoder test ran on an RTX 5090 machine.

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 placement Placement planning: crates/placement 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 defect was found in the changed paths.

Non-blocking

⚠ Complete the precision-change evidence: crates/gpu/src/q8f32.rs:3505.
The encoder rounds BF16 head weights to MXFP8. The base contract's precision-change class requires the just gate-gpu-e2e count-pin result.
Attach that output and the exact timing commands with output for 3e03d745c versus 4e5082d58. The PR body supplies family-gate output and timing tables, but omits these records. The review rules classify missing measurement evidence as non-blocking.

Checked

Duplicates: 14 new or relocated definitions checked; no duplicate requiring fewer elements after extraction. Dryer reported zero pairs; GPU and gate code were searched manually.

Complexity: new head_rows_case (23) covers layout, replay and fault stages. walk (85→91), enqueue_mix (28→31), enqueue_over (18→20), enqueue_e4m3_gemv (19→21) and upload_rows (52→53) grow by format dispatch. e4m3_case (18→22) adds gate dispatch; cases (38→39) adds one clause. No complexity finding.

Silent failure: six sites followed. Missing dimensions and size-conversion failures become named errors. Host column checks block the kernel fallback arms. Encoder clamps follow finite-input validation and implement representable quantization.

Tests: mutation analysis covers bypassing file_card_format (placement.rs:516), restoring old plane sizing (card.rs:606), transposing output (q8f32.rs:2799), dropping the ID fault (q8f32.rs:1365), and removing finite/range refusals (q8f32.rs:3526,3548); their format, byte, layout, fault and refusal assertions fail. The BF16 gate retains its raw-format coverage explicitly.

Numeric check: an independent arithmetic check of 32,640 positive finite BF16 values found no nearest-even mismatch against the E4M3 value table. Rounded overflow reaches the encoder's named range error.

Adversarial paths: malformed shapes, NaN/infinity, extreme finite weights, repeated and out-of-range IDs, invalid column counts, tied embeddings and K=320 fallback were traced to guards or defined behavior.

Gates: changed format/byte pins and the unsafe ratchet carry dated reasons; no numeric tolerance was relaxed.

Escape catalog: C1–C4 do not match the changed code.

Notes

Rust and GPU gates were not executed locally. Hardware evidence was assessed from the PR body.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_bf16.rs, crates/gpu-gates/src/bin/gate_mxfp8.rs, crates/gpu-glm5next/src/tp/source.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 22, 2026
@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

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 placement Placement planning: crates/placement 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