Skip to content

quant_config: an FP8 weight of one scale a 128 by 128 block is held as FP8_B128, an f32 scale a 128 values of a row - #562

Merged
juliankang4 merged 4 commits into
midagedev:mainfrom
juliankang4:dgx-spark-fp8-weights
Oct 20, 2026
Merged

juliankang4 merged 4 commits into
midagedev:mainfrom
juliankang4:dgx-spark-fp8-weights

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

체크포인트의 FP8 가중치(128x128 블록마다 스케일 하나)를 카드 형식 FP8_B128로 읽고, gemv, m열 gemv, 넓은 타일 GEMM, routed expert select, join까지 돌리는 공통 형식 층을 추가합니다. quant_config가 이런 가중치를 FP8_B128로 잡고 크기를 맞추며, Qwen MTP draft의 routed launch와 GLM decode의 resident_gemv가 FP8 fixture 텐서로 증명됩니다.

Part of #495.

What and why

Several checkpoints store their F8_E4M3 weights with one scale for each 128 by 128 block (weight_scale_inv or weight_scale, in F32, BF16 or E8M0). bloomery had no card format for them. This PR adds the format once, for every model that ships it: the Qwen3.8 MTP experts, GLM-5.3-Flash (official FP8 and the FP4-Local attention projections), Qwen3.6, Qwen3-30B FP8 and MiMo dense.

  • GgmlType::FP8_B128 (id 2003) is bloomery's own type. A block is 132 bytes: an f32 little-endian scale, then 128 E4M3 bytes. The square 128 by 128 scale is copied onto each row of 128 values it covers, so the card walks it like MXFP8, with the same two planes, the same ByteBlocks walk and the same F32 tile. check_fp8_b128 refuses a scale that is not finite, an E4M3 NaN (0x7F, 0xFF), a scale times a value that leaves f32's range, and a short block, each by tensor name. dequant_row decodes with the same rule.
  • The reader (crates/hf/src/modelopt.rs) reads Format::Fp8Block{128,128} as FP8_B128 for dense tensors and for routed expert stacks. The scale grid may be [r, c] or ModelOpt's [r, 1, c, 1], in F32, BF16 or E8M0. A stack takes experts in order as [k, rows, n_expert], and experts of different shapes are refused by name.
  • On the card (crates/gpu), CardFormat::Fp8B128Planes and DevWeight::Fp8B128 hold the two planes. The MXFP8 entry points are renamed as the shared owner of both block-scale variants (enqueue_e4m3_gemv, enqueue_e4m3_tile, E4m3Weight, e4m3_planes, Weights::e4m3). New kernels: fp8_b128_gemv, fp8_b128_gemv_mcol, fp8_b128_gemv_sel_f32 and fp8_b128_tile_gemm. Each term is the E4M3 value times the f32 scale, rounded once, which is what the host dequant computes, so the output equals the host walk bit for bit.
  • Routed select: q8_0_gemv_sel_f32 and fp8_b128_gemv_sel_f32 share SelArgs and sel_launch (the launch checks), and both call one device body, blocks_gemv_sel_body<F: ByteBlocks> (the id load, a bad id's fault and NaN store, the walk and the store), so the Q8_0 entry's body moved there with the same operations in the same order. Fp8B128Bytes::scale_at reads its scale word through Mxfp8Bytes::scale_at, which owns the load of word b / 4; only scale differs by format. site::resident_sel_f32 picks the kernel by the stack's resident format, and CardFormat::of_routed accepts FP8_B128.
  • Placement (crates/placement): SiteEntry::Fp8B128 with f32 activations in the dense table. The gate_up, down, GEMM, head and embed tables have no FP8_B128 row.
  • quant_config: a weight of one scale per 128 by 128 block counts as FP8_B128 in held(), which now measures card bytes, rows * k / 128 * 132, and cuts at [128, 1] (the square scale is copied per row on the card). Other block sizes keep the square count. For a tensor of r rows and k values the count grows by 4 * (k / 128) * (r - r / 128) bytes. A GLM FP4-Local rank's pinned totals follow: 10,737,098,888 bytes for the layer fixture at N=1, 6,021,603,208 at N=2 and 3,663,855,368 at N=4, which an independent Python count from the header shapes reproduced.

Two callers use the format without a model change:

  • The Qwen3.8 MTP draft's routed launch (crates/gpu/src/arch/qwen3moe/mtp38.rs) now goes through site::resident_sel_f32 for gate, up and down instead of calling q8_0_gemv_sel_f32 directly. Its 1,536 expert tensors (F8_E4M3, block 128) run on the card without a Q8_0 repack.
  • GLM decode's body::gemv re-exports site::resident_gemv, which now has an FP8_B128 arm, so the latent attn_q_b and attn_output run with no GLM code change. The gate_mxfp8 decode clause runs site::resident_gemv at GLM layer 3's real shapes (attn_q_b 16,384 by 1,536, attn_output 4,096 by 16,384), and the model-hf test fp4_local_ranks_hold_the_header_tables_split_bytes counts the FP4-Local header's q_b_proj as FP8_B128 card bytes. Loading a GLM Hugging Face folder onto cards with TP is not part of this PR, so no full GLM checkpoint ran end to end.

Sites that only know Q8_0 (GLM's prefill GEMM q8() helper, the DeepSeek shared expert block, and a latent join of mixed formats) refuse an FP8_B128 weight by name.

Existing paths: the gate below holds the Q8_0 gemv, the Q8_0 select, the F32 tile and every earlier MXFP8 clause bit for bit against their host rules.

Release notes: Added: FP8 weights with one scale per 128 by 128 block load as a card format (FP8_B128) and run as gemv, wide GEMM and routed expert select.

Code shape

  • No second copy. The FP8_B128 kernels are thin entries over the shared blocks_lane_partial_1col, blocks_lane_partials_m and f32_tile_body walks (a cuda-oxide #[kernel] entry cannot be generic, so each format needs its own entry). The F32 and BF16 scale decode uses safetensors::f32_values, and the MXFP8 API became the owner for both block-scale types.
  • Model code holds only architecture facts. The two model-side changes are the MTP launch going through the site owner and the held() byte rule. No common owner gained a per-model branch.
  • Dead code is gone. The Q8_0-only direct select call in the MTP launch is removed.
  • No silent failure. A non-finite scale, an E4M3 NaN, a product outside f32's range, a short block, an expert stack of mixed shapes and a stack of the wrong format are named errors (see the refusal clauses below). The shared E4M3 plane check also refuses zero rows, zero width and a packed width that overflows, before any dense, tile or expert select launch. GEMV buffer spans are checked for overflow, and held() returns None for a zero block dimension instead of dividing by zero.
  • Comments state what is true now.
  • No relaxed gate. The unsafe ratchet's gpu row went from 1991 blocks and 222 fns to 2001 and 224 (the new kernels and the shared select body, each block with its SAFETY line), and the three PTX shape tables only grew by the new kernels' rows.
  • cargo fmt --all --check passes, and tools/check-unsafe.sh and tools/check-ptx-names.sh pass.

Duplication found or removed: the F32 and BF16 scale decode in crates/hf/src/modelopt.rs duplicated crates/hf/src/safetensors.rs and now calls it (E8M0 stays local because f32_values refuses that dtype). The remaining duplicate-scan candidates are entry wrappers or per-format block geometry that share their walk through one generic owner: crates/gpu/src/q8f32.rs:1596, :1638 and :1857, crates/gpu/src/gemm/kernels32.rs:1100, crates/gguf/src/quant.rs:1215 and crates/gpu-gates/src/bin/gate_mxfp8.rs:183.

What I ran

All device runs are on a DGX Spark (GB10) inside the dev container image bloomery-dev:cuda13.3.1. Raw nvidia-smi output of that node and image:

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

The gate runs used the query form too (nvidia-smi --query-gpu=name,driver_version,compute_cap), which printed:

NVIDIA GB10, 595.84, 12.1

gate_mxfp8 at head 08e2026c

just gate-gpu-mxfp8 stops with exit 70 in this node's container (tools/box.sh cannot find the pinned cargo-oxide in cargo install --list), so the recipe body ran without the wrapper, with the card checks set the way the recipe sets them:

export BLOOMERY_BOX_LOCAL=1 BLOOMERY_ARCH=sm_121 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any
cargo oxide build --arch sm_121 -- -p bloomery-gpu-gates --features gpu --release --bin gate_mxfp8
bash tools/gpu-gate.sh gate_mxfp8
NVIDIA GB10, 595.84, 12.1
GATE rc=0
gpu-gate.sh: gate_mxfp8 ran 14 s (exit 0)

The saved log keeps the last 60 output lines: 59 PASS and 0 FAIL, among them 12 FP8_B128 select rows and 24 Q8_0 select rows. The select rows of both entries:

Select entry Outputs equal to the host walk Result
fp8_b128_gemv_sel_f32, slot 5, expert 0 64/64 PASS
q8_0_gemv_sel_f32, slot 5, expert 0 64/64 PASS

Both select entries equal the host walk in all 64 outputs of the slot shown in each row.

The table rows run blocks_gemv_sel_body through both entries. The full 222-line output below is from 02850b39, before the select entries shared that body; the run on 08e2026c above covers the move.

At 02850b39 the same recipe body printed:

cargo oxide build --arch sm_121 -- -p bloomery-gpu-gates --features gpu --release --bin gate_mxfp8 --bin gate_e2e --bin oxart_jit
bash tools/gpu-gate.sh gate_mxfp8
GATE-RC 0
PASS 222 FAIL 0
gpu-gate.sh: gate_mxfp8 ran 14 s (exit 0)

Every FP8_B128 output sits inside the f64 reference band γ(k/32 + 5) Σ|w x| + k u64 Σ|w x| and equals the host walk bit for bit (runtime::hc_gated::card::q8_dot; the tile uses f32_dot). Sample lines:

fp8_b128 clause=tile.bits shape=blk.3.attn_q_b rows=16384 k=1536 m=64 equal=1048576/1048576 PASS
fp8_b128 clause=decode.bits shape=blk.3.attn_output rows=4096 k=16384 m=1 equal=4096/4096 PASS
fp8_b128 clause=sel.bits ids=[2, 0, 3, 3, 1, 0] rows_per_expert=64 k=256 slots_per_col=2 slot=0 id=2 equal=64/64 PASS
q8_0 clause=q8_0.bits rows=16384 k=1536 m=3 equal=49152/49152 PASS
f32 clause=f32_tile.bits rows=256 k=1536 m=64 equal=16384/16384 PASS

What the gate covers:

  • Scale end values (f32 subnormal 2^-149, smallest normal 2^-126, and 2^118 with values of plus or minus 448) match the host in the gemv, decode and tile clauses.
  • Select: 6 slots, 3 columns, 2 slots per column, with every slot equal in all 64 outputs. An out-of-range expert id gives NaN and an ExpertId fault (code 7) and leaves the other slots' bits alone. An MXFP8 stack is refused by name.
  • Refusals: an inf scale, a 0xFF value byte and a 2^127 x 448 product each name their tensor.
  • Existing paths: Q8_0 gemv at m=1 and m=3, the Q8_0 select, the F32 tile, and every earlier MXFP8 clause (gemv, tile, scales E0, E1 and E254, join, refusal, plane shape).

GPU library tests on the same node and tree: cargo oxide test --arch sm_121 -- -p bloomery-gpu --release --lib -- q8f32 site:: weights:: f32tile mtp38:

test result: ok. 13 passed; 0 failed; 0 ignored; 0 measured; 312 filtered out; finished in 0.01s

The gate catches a defect

Each defect was planted by one line in the node's work tree and reverted afterwards (head 5adaf423, where each select entry still held its own body):

Planted defect Gate result
fp8_b128_gemv_sel_f32's own body ignores the slot's expert id (row_abs = row % rpe) exit 1, PASS 212, FAIL 10 (sel.bits and sel.band, FP8_B128 select only)
Fp8B128Bytes::scale flips the scale's last bit exit 1, PASS 186, FAIL 36 (gemv, decode, tile, join and select, FP8_B128 only)

The second run fails no MXFP8, Q8_0 or F32 clause, so the two format paths are separate. The same run also ran cargo oxide test --arch sm_121 -- -p bloomery-gpu --release --lib -- arch::qwen3moe, which printed test result: ok. 27 passed; 0 failed; 2 ignored.

Input boundary checks at head 9016033b

The checks that reject zero sizes and overflow sit in host code (dimensions, e4m3_planes, check_gemv_geometry and Format::held). Each test was run on the old code first.

  • held with a zero block dimension: the quant_config test fails on the old code with attempt to divide by zero (exit 101, x86 Linux host). With the check, the same test and the fp8_block_weights test print test result: ok. 2 passed.
  • GEMV span overflow: on the GB10 node, gemv_geometry_refuses_wrapped_buffer_spans fails on the old code with wrapped buffer spans: (): the old check accepted a span that wrapped.
  • Plane checks: a CPU harness compiles the real bodies of dimensions, check_gemv_geometry and e4m3_planes from the old and the new source, with stub tensor metadata and no CUDA. The old bodies fail all 3 tests (exit 101): dimensions returns k-zero: Ok((1, 0)) for a zero width, a wrapped span passes, and a zero row reader succeeds. The new bodies pass all 3 (exit 0). A regression case on real CUDA planes is in gate_mxfp8::plane_shapes.

Host tests and static checks

On an x86 Linux host, cargo test -p bloomery-gguf -p bloomery-hf -p bloomery-placement -p bloomery-model-hf --lib at 5adaf423:

test result: ok. 42 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.51s   (gguf)
test result: ok. 89 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.65s   (hf)
test result: ok. 21 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.56s   (model-hf)
test result: ok. 160 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 86.17s   (placement)

After the final change to crates/hf/src/modelopt.rs (the shared F32 and BF16 scale decode), cargo test -p bloomery-hf -p bloomery-model-hf --lib ran again: test result: ok. 89 passed for hf and test result: ok. 21 passed for model-hf. The modelopt tests cover the F32 and BF16 grid scales.

cargo fmt --all --check, tools/check-unsafe.sh and tools/check-ptx-names.sh pass. tools/ptx-spill-check.sh on the generate_ds41 and gate_e2e builds (sm_121 and sm_86, cc 12.1 tables) prints no line for the four new kernels, which are pinned at spill 0 and local 0. Its other lines name kernels this PR does not touch, for example gate_e2e kq_gate_up_act_q4k_tiles spill=752 pinned=756 BELOW.

Select entries' PTX on the GB10 at 08e2026c

q8_0_gemv_sel_f32 is an existing entry, so its PTX was compared with the base e3ce40fd1 in generate_ds41 and gate_e2e (sm_121 scan, driver JIT). Every resource column is the same on both sides (40 registers, spill 0, JIT local 0, 40 JIT registers). The normalized body differs by one line, 562 to 563 lines, and its digest changes (852560911c63... to 5c3170d6f5f0...); the device code moved into blocks_gemv_sel_body is not byte-identical. just canon-check ec66ae8c at head cdd8b179 on GB10 classifies that difference: 931 of 946 entries are identical, the 12 entries on one side only are the new FP8_B128 kernels, and q8_0_gemv_sel_f32 differs in three bins by the order of independent parameter loads, register numbering and the position of the shared ret block (one extra bra.uni). There is no arithmetic or memory-access change. The new fp8_b128_gemv_sel_f32 has 40 registers, spill 0 and JIT local 0.

Which head each result ran on

The device runs above ran on the heads named with them. The PR head is 82f1d060, the same three commits rebased onto 87044eca: git range-diff shows all three commits as =, the one conflict was an import line in crates/gpu/src/gemm/kernels32.rs, and the gpu row of tools/unsafe-ratchet.txt holds the numbers above. No device body changed in the rebase. On 82f1d060, cargo check and the --lib tests of bloomery-gguf, bloomery-hf, bloomery-model-hf and bloomery-placement pass (42, 89, 21 and 160 tests, rc 0), and tools/check-unsafe.sh passes.

Fp8B128Bytes::scale_at passing b / 4 to Mxfp8Bytes::scale_at (word b / 16 for block b) makes q8f32::tests::fp8_b128_card_decode_is_the_hosts panic at q8f32.rs:3063 (rc 101) on the GB10 at 08e2026c; with the real code that test and mxfp8_card_decode_is_the_hosts pass.

Device evidence for the f32 m-column walk

PR #511 changed the m-column walk of f32_lane_partials in crates/gpu/src/q8f32.rs to keep 8 chunk loads in flight. This PR edits the same file, so it carries the device evidence for that change. Everything below compares #511's merge (6c49bab0) with its base (c900efac). This PR does not change the walk: the four affected entries have the same PTX md5 at this PR's GPU code as at 6c49bab0.

PTX comparison, tools/ptx-compare.sh c900efac generate_qwen3moe --features gpu

On the GB10 above (sm_86 PTX through the driver JIT for cc 12.1). It exits 3 because 4 entries changed and nothing was added or removed (277 entries on both sides). The four are the entries that use the m-column walk. spill and jit_local are 0 on both sides for all four, and none has a local-memory depot.

Entry regs, base to #511 JIT regs, base to #511 spill JIT local
f32_gemv 48 to 60 40 to 40 0 0
qwen35moe_router_fused 42 to 40 48 to 64 0 0
qwen35moe_router_fused_512 48 to 62 48 to 64 0 0
qwen3moe_router_fused 42 to 40 40 to 44 0 0

On sm_121, the production arch, the same four entries change (f32_gemv JIT regs 40 to 40, the routers 48 to 64, 48 to 64 and 40 to 44) with spill 0 and JIT local 0 on both sides.

Owning gate

just gate-gpu-gemm --case g32_f32tile stops with exit 70 in the node's container for the same tools/box.sh reason as above. Its recipe body ran without the wrapper on a 6c49bab0 tree (BLOOMERY_REF_MODEL set to a Qwen3-30B-A3B-Instruct-2507 Q4_K_M file):

echo "just gate-gpu-gemm --case g32_f32tile: recipe body without tools/box.sh"
cargo oxide build --arch sm_121 -- -p bloomery-gpu-gates --features gpu --release --bin gate_gemm
bash tools/gpu-gate.sh gate_gemm --case g32_f32tile
gemm32 case=g32_f32tile rows=96 K=2560 n=4095 bits_differ_vs_f32_gemv=0 past_end_untouched=true PASS
gemm32 case=g32_f32tile rows=512 K=2560 n=512 bits_differ_vs_f32_gemv=0 past_end_untouched=true PASS
gpu-gate.sh: gate_gemm ran 0 s (exit 0)
GATE-RC 0

All 16 g32_f32tile lines (rows 96, 100, 128 and 512) are PASS with bits_differ_vs_f32_gemv=0. The tile kernel is independent of the walk #511 changed, and it equals the f32 gemv at 1 to 8 column groups (n = 4,095 passes through a final group of 7 columns and n = 9 through 8 and then 1). The unit test q8f32::tests::f32_walks_are_the_scalar_walk (1 to 8 columns, row lengths 32 to 1,536, each column equal to a sequential fma loop) passes at 6c49bab0 and at this PR's head. The first line of the recipe, a CPU unit-test pass, was not run.

A/B of f32_gemv, #511 against its base

Four single-process runs in the order base, #511, #511, base, on one GB10 (idle before: NVIDIA GB10, 305 MHz, 5.31 W, 48, with no compute process). k = 2,560, graph replay with 64 weight copies so the cache is not reused, minimum of the runs. The output digest y_fnv64 is the same in all four runs for every rows and m value, so the outputs are bit identical. The table is the ratio of the base time to the #511 time (above 1 means #511 is faster):

rows m=1 m=2 m=3 m=4 m=5 m=6 m=7 m=8
96 0.985 3.25 2.93 3.02 2.95 2.58 2.81 2.31
128 0.991 3.24 2.92 2.98 2.92 2.55 2.79 2.30
512 0.997 2.04 2.04 2.28 2.37 2.30 2.51 2.16
2048 0.998 1.054 1.039 1.057 1.076 1.087 1.136 1.119

For m = 2 to 8, #511 is 2.0 to 3.3 times faster at 96 to 512 rows and 4 % to 14 % faster at 2,048 rows. At m = 1 and 96 rows it is 0.11 us slower (7.47 us against 7.59 us). At 512 and 2,048 rows m = 1 differs by 0.3 % or less. This is a comparison bench run within about ten minutes, not a three-sitting median.

Hardware

A DGX Spark (GB10), driver 595.84, compute capability 12.1, CUDA 13.3 container (ptxas 13.3.73). The host tests ran on an x86 Linux machine.

What I ran into

This does not block the PR.

  • just gate-* recipes stop with exit 70 in the node's dev container because tools/box.sh does not find the pinned cargo-oxide in cargo install --list, so each gate above ran as the recipe's own body.
  • tools/ptx-spill-check.sh exits 1 on the cc 12.1 tables for kernels this PR does not touch (for example gemm_nvfp4p unpinned and kq_gate_up_act_q4k_tiles spill=752 pinned=756 BELOW). No FP8_B128 kernel appears in its output.
  • The f32_gemv m = 1 path is 0.11 us slower at 96 rows after f32 gemv: the m-column walk keeps eight chunks' loads in flight a column #511 (table above). I did not find the cause, so the PR leaves that path alone.

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 20, 2026
github-actions[bot]
github-actions Bot previously approved these changes Oct 20, 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 reachable behavior defect or proven quality defect survives review.

Non-blocking

⚠ Complete the PTX comparison for the Q8_0 select move: crates/gpu/src/q8f32.rs:1867.
The PR reports a changed digest and one extra normalized PTX line after extracting the shared body, without comparing the instructions. Equal resource counts and output bits do not establish the move-class proof in AGENTS.md.
Attach just canon-check 22e1a7940a5b8e9cdd817cc599e0706c9eb7daa4 at the current head and classify any surviving instruction difference. This comparison is small while the extraction is isolated.

Checked

Duplicates: 45 new items checked; all 9 dryer pairs read. They are format entry wrappers, distinct mappings or distinct capability tables. The device walks and select body have common owners.
Complexity: new fp8_b128_append (24) validates and packs; enqueue_e4m3_gemv (19) dispatches; sel_launch (16) validates; e4m3_case (18) runs gate stages. cases grows 23→34 through fixture construction. Other flagged functions (upload_rows, join_rows, dequant_row, as_u32, from_u32, site::gemm, normalize, held, buffer_bytes) gain format arms or validation.
Silent failure: 6 candidate sites followed. The maximum scans 128 bytes; unsupported scale dtypes and zero slot widths reach named errors; unmatched join parts reach an error; the unused column argument remains a launch bound.
Tests: static mutation audit only; no tests executed here. Wrong type IDs or block sizes fail the split tests; removing finite-value checks fails refusal assertions; changing modelopt.rs:585 from row / 128 to row fails scale-grid assertions; changing q8f32.rs:751 to load word b / 16 fails decode bits; removing checked products at q8f32.rs:2919 fails overflow assertions. Ignoring selected expert IDs, dropping the fault branch, choosing the wrong tile decoder, or dropping join/dispatch support fails the gate's bits, fault or success checks. Format-table and TP-byte assertions reject omitted entries and stale byte counts. Supplied device logs report red scale and expert-ID mutants.
Gates: bands unchanged; format admissions and unsafe ratchets have dated PIN reasons. Byte-count expectations follow the new row-scale layout.
Escape catalog: C1–C4 do not match changed code.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_load_v41.rs, crates/gpu-gates/src/bin/gate_mxfp8.rs, crates/gpu/src/arch/qwen3moe/body.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 20, 2026
…t, read, run and joined beside Q8_0

A checkpoint's F8_E4M3 weight with a weight_scale or weight_scale_inv of one
scale a 128 by 128 block (FP8_BLOCK_SCALES, FP8_PB_WO; F32, BF16 or E8M0
grids, [r, c] or ModelOpt's [r, 1, c, 1]) becomes bloomery's own GGUF type
FP8_B128 (2003): each row's 128-value blocks as the f32 scale of the square
the block lies in, then its 128 value bytes as stored. Routed experts stack
as [k, rows, n_expert]. hf::modelopt refuses a non-finite scale, an E4M3 NaN
and a product past f32 by row (gguf::quant::check_fp8_b128).

On the card the type loads in MXFP8's two planes (CardFormat::Fp8B128Planes,
DevWeight::Fp8B128), one f32 scale a word, and runs through the same owners,
renamed for both block-scale variants: enqueue_e4m3_gemv (fp8_b128_gemv and
_mcol), enqueue_e4m3_tile (fp8_b128_tile_gemm), Weights::join_rows and
site::gemv/gemm/resident_gemv. Every term is the E4M3 value times its f32
scale rounded once, as the host dequant rounds it, so each output is bit for
bit the host walk over the dequantized rows.

The expert select gains fp8_b128_gemv_sel_f32 beside q8_0_gemv_sel_f32,
sharing their checks (SelArgs, sel_launch), and site::resident_sel_f32
dispatches by the stack's resident form; the qwen3moe MTP draft's routed
gate, up and down launch through it, so an FP8_B128 expert stack runs where
a Q8_0 one did (CardFormat::of_routed admits it).

gate_mxfp8 covers both types: gemv at one and m columns, the resident
(decode) launch, the tile, the scale's ends, joins, the select (bits, a bad
id's NaN and ExpertId fault, an MXFP8 stack refused), the load's refusals
and plane-shape errors, and the Q8_0, Q8_0 select and F32 paths unchanged.
…s FP8_B128, an f32 scale a 128 values of a row

The card holds such a weight as FP8_B128, so Format::held counts its card
bytes, rows * k / 128 * 132, and cuts it by whole 128-value blocks along a
row and by any row ([128, 1]), where it counted one F32 a 128 by 128 square
and cut by squares. Other FP8 block sizes keep their square count.

The GLM-5.3-Flash-FP4-Local plan's bytes rise by each FP8_PB_WO tensor's
added scales, 4 * (k / 128) * (r - r / 128) for a part of r rows of k values:
layer 3's q_a [1536, 4096] and kv_a [512, 4096] whole on every rank, q_b
[16384, 1536] and the shared gate and up [2048, 4096] cut by row, o
[4096, 16384] and the shared down [4096, 2048] cut along k; layer 4's shared
expert the same. A rank holds 3,901,440 + 780,288 more bytes at N = 1,
2,080,768 + 390,144 at N = 2 and 1,170,432 + 195,072 at N = 4 (layers 3 and
4), and the trunk, at 11 latent and 31 KDA sparse layers,
67,104,768, 34,982,912 and 18,921,984 more: 10,737,098,888 and
181,500,571,640 B at N = 1, 6,021,603,208 and 91,635,719,928 at N = 2,
3,663,855,368 and 46,703,294,072 at N = 4.

@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 was established.

Non-blocking

⚠ Cover the down-select column stride: crates/gpu-gates/src/bin/gate_mxfp8.rs:463. Every successful select case uses slots_per_col = 2; MTP down uses 1. Replacing the shared column calculation at crates/gpu/src/q8f32.rs:1379 with slot / 2 leaves this gate green and selects the wrong activation columns for down slots after slot 0. Extend the existing case to run both strides for both formats, using its existing bit assertions.

Checked

Select path: site::resident_sel_f32 forwards the launch arguments to the resident format's kernel. The shared body currently divides by slots_per_col, as required.

Tests: both successful select fixtures use stride 2. The stride-1 calls in this gate exercise format or malformed-plane refusals. The existing host reference uses slot / spc and compares every output's bits.

Scope: the cited gate and shared indexing are added by this full-review diff. No ledger lessons apply. Escape catalog C1–C4 do not match the retained finding.

Notes

Static validation only. Tests and GPU gates were not run. Dryer excluded gpu-gates; the select fixture was inspected manually.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_load_v41.rs, crates/gpu-gates/src/bin/gate_mxfp8.rs, crates/gpu/src/arch/qwen3moe/body.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 d2c4ea5 into midagedev:main Oct 20, 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 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