Repository navigation
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
Conversation
There was a problem hiding this comment.
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)
…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.
20bcf09 to
ea27a32
Compare
There was a problem hiding this comment.
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)
|
The review is done and the contribution check passed, so I'm merging this. |
체크포인트의 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_invorweight_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 sameByteBlockswalk and the same F32 tile.check_fp8_b128refuses 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_rowdecodes with the same rule.crates/hf/src/modelopt.rs) readsFormat::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.crates/gpu),CardFormat::Fp8B128PlanesandDevWeight::Fp8B128hold 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_f32andfp8_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.q8_0_gemv_sel_f32andfp8_b128_gemv_sel_f32shareSelArgsandsel_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_atreads its scale word throughMxfp8Bytes::scale_at, which owns the load of wordb / 4; onlyscalediffers by format.site::resident_sel_f32picks the kernel by the stack's resident format, andCardFormat::of_routedaccepts FP8_B128.crates/placement):SiteEntry::Fp8B128with 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 inheld(), 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 ofrrows andkvalues the count grows by4 * (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:
crates/gpu/src/arch/qwen3moe/mtp38.rs) now goes throughsite::resident_sel_f32for gate, up and down instead of callingq8_0_gemv_sel_f32directly. Its 1,536 expert tensors (F8_E4M3, block 128) run on the card without a Q8_0 repack.body::gemvre-exportssite::resident_gemv, which now has an FP8_B128 arm, so the latentattn_q_bandattn_outputrun with no GLM code change. Thegate_mxfp8decode clause runssite::resident_gemvat GLM layer 3's real shapes (attn_q_b16,384 by 1,536,attn_output4,096 by 16,384), and themodel-hftestfp4_local_ranks_hold_the_header_tables_split_bytescounts the FP4-Local header'sq_b_projas 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
blocks_lane_partial_1col,blocks_lane_partials_mandf32_tile_bodywalks (a cuda-oxide#[kernel]entry cannot be generic, so each format needs its own entry). The F32 and BF16 scale decode usessafetensors::f32_values, and the MXFP8 API became the owner for both block-scale types.held()byte rule. No common owner gained a per-model branch.held()returnsNonefor a zero block dimension instead of dividing by zero.cargo fmt --all --checkpasses, andtools/check-unsafe.shandtools/check-ptx-names.shpass.Duplication found or removed: the F32 and BF16 scale decode in
crates/hf/src/modelopt.rsduplicatedcrates/hf/src/safetensors.rsand now calls it (E8M0 stays local becausef32_valuesrefuses 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,:1638and:1857,crates/gpu/src/gemm/kernels32.rs:1100,crates/gguf/src/quant.rs:1215andcrates/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. Rawnvidia-smioutput of that node and image:The gate runs used the query form too (
nvidia-smi --query-gpu=name,driver_version,compute_cap), which printed:gate_mxfp8at head 08e2026cjust gate-gpu-mxfp8stops with exit 70 in this node's container (tools/box.shcannot find the pinned cargo-oxide incargo 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_mxfp8The 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:
fp8_b128_gemv_sel_f32, slot 5, expert 0q8_0_gemv_sel_f32, slot 5, expert 0Both select entries equal the host walk in all 64 outputs of the slot shown in each row.
The table rows run
blocks_gemv_sel_bodythrough 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:
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 usesf32_dot). Sample lines:What the gate covers:
2^-149, smallest normal2^-126, and2^118with values of plus or minus 448) match the host in the gemv, decode and tile clauses.ExpertIdfault (code 7) and leaves the other slots' bits alone. An MXFP8 stack is refused by name.2^127 x 448product each name their tensor.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: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):
fp8_b128_gemv_sel_f32's own body ignores the slot's expert id (row_abs = row % rpe)sel.bitsandsel.band, FP8_B128 select only)Fp8B128Bytes::scaleflips the scale's last bitThe 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 printedtest 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_geometryandFormat::held). Each test was run on the old code first.heldwith a zero block dimension: thequant_configtest fails on the old code withattempt to divide by zero(exit 101, x86 Linux host). With the check, the same test and thefp8_block_weightstest printtest result: ok. 2 passed.gemv_geometry_refuses_wrapped_buffer_spansfails on the old code withwrapped buffer spans: (): the old check accepted a span that wrapped.dimensions,check_gemv_geometryande4m3_planesfrom the old and the new source, with stub tensor metadata and no CUDA. The old bodies fail all 3 tests (exit 101):dimensionsreturnsk-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 ingate_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 --libat 5adaf423: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 --libran again:test result: ok. 89 passedfor hf andtest result: ok. 21 passedfor model-hf. Themodelopttests cover the F32 and BF16 grid scales.cargo fmt --all --check,tools/check-unsafe.shandtools/check-ptx-names.shpass.tools/ptx-spill-check.shon thegenerate_ds41andgate_e2ebuilds (sm_121andsm_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 examplegate_e2e kq_gate_up_act_q4k_tiles spill=752 pinned=756 BELOW.Select entries' PTX on the GB10 at 08e2026c
q8_0_gemv_sel_f32is an existing entry, so its PTX was compared with the basee3ce40fd1ingenerate_ds41andgate_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...to5c3170d6f5f0...); the device code moved intoblocks_gemv_sel_bodyis not byte-identical.just canon-check ec66ae8cat 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, andq8_0_gemv_sel_f32differs in three bins by the order of independent parameter loads, register numbering and the position of the sharedretblock (one extrabra.uni). There is no arithmetic or memory-access change. The newfp8_b128_gemv_sel_f32has 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 onto87044eca:git range-diffshows all three commits as=, the one conflict was an import line incrates/gpu/src/gemm/kernels32.rs, and the gpu row oftools/unsafe-ratchet.txtholds the numbers above. No device body changed in the rebase. On82f1d060,cargo checkand the--libtests ofbloomery-gguf,bloomery-hf,bloomery-model-hfandbloomery-placementpass (42, 89, 21 and 160 tests, rc 0), andtools/check-unsafe.shpasses.Fp8B128Bytes::scale_atpassingb / 4toMxfp8Bytes::scale_at(wordb / 16for blockb) makesq8f32::tests::fp8_b128_card_decode_is_the_hostspanic atq8f32.rs:3063(rc 101) on the GB10 at08e2026c; with the real code that test andmxfp8_card_decode_is_the_hostspass.Device evidence for the f32 m-column walk
PR #511 changed the m-column walk of
f32_lane_partialsincrates/gpu/src/q8f32.rsto 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 at6c49bab0.PTX comparison,
tools/ptx-compare.sh c900efac generate_qwen3moe --features gpuOn 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.
spillandjit_localare 0 on both sides for all four, and none has a local-memory depot.f32_gemvqwen35moe_router_fusedqwen35moe_router_fused_512qwen3moe_router_fusedOn
sm_121, the production arch, the same four entries change (f32_gemvJIT 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_f32tilestops with exit 70 in the node's container for the sametools/box.shreason as above. Its recipe body ran without the wrapper on a6c49bab0tree (BLOOMERY_REF_MODELset to a Qwen3-30B-A3B-Instruct-2507 Q4_K_M file):All 16
g32_f32tilelines (rows 96, 100, 128 and 512) are PASS withbits_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 testq8f32::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 at6c49bab0and 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 baseFour 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 digesty_fnv64is 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):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 (
ptxas13.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 becausetools/box.shdoes not find the pinned cargo-oxide incargo install --list, so each gate above ran as the recipe's own body.tools/ptx-spill-check.shexits 1 on the cc 12.1 tables for kernels this PR does not touch (for examplegemm_nvfp4p unpinnedandkq_gate_up_act_q4k_tiles spill=752 pinned=756 BELOW). No FP8_B128 kernel appears in its output.f32_gemvm = 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 초안 리뷰는 제가 직접 했습니다.