Repository navigation
hf: FP8 weights of one scale a row, a tensor or a 32 by 32 E8M0 block read onto FP8_B128 and MXFP8 - #579
Merged
juliankang4 merged 1 commit intoOct 21, 2026
Conversation
… read onto FP8_B128 and MXFP8 A checkpoint's F8_E4M3 weight keeps its values on the card whatever its scale layout: each row block of the card type holds the scale of the checkpoint's block it lies in. quant_config's Format::card_type is the one rule: a scale covering whole 128-value blocks of a row (one a tensor, as ModelOpt FP8 stores it; one a row, as compressed-tensors strategy channel does; a block 128 values wide) is held as FP8_B128, an f32 a 128 values; one covering whole 32-value blocks (MXFP8, and the E8M0 32 by 32 blocks DeepSeek-V4.1-Flash stores its attention and shared experts in) as MXFP8, an E8M0 byte a 32 values. Format::held reads that type's row for every format, so the square count for other FP8 blocks goes; a block no card type holds has no held form. Format::fp8_scale_block is the one owner of a scale grid's stored shapes ([r, c], ModelOpt's [r, 1, c, 1], a channel's [rows], a tensor's []), read by the plan's layout and by modelopt's reader. modelopt::type_of reads card_type for MXFP8 and the FP8 formats, and one reader (fp8) writes all of them: MXFP8 and FP8_B128 blocks with each block's scale looked up in the grid, routed stacks of FP8_B128 for channel and tensor experts as for 128 by 128 blocks. An MXFP8 stack, an F32 or BF16 scale on an MXFP8 block and a row that is not whole blocks of the type (a tensor or row scale over 3136 values) are refused by name. The oracle reads real rows: two MiniCPM-V 4.7 FP8 experts (BF16 scale a row), a Nemotron 3 Nano 4B FP8 out_proj (one F32 scale) and a DeepSeek-V4.1-Flash shared expert block (E8M0 32 by 32), each placed by its own checkpoint's config; every row decodes to the f32 bits of its producer's rule (fp8_scales.py ref).
Contributor
There was a problem hiding this comment.
Verdict: CLEAN: The added FP8 scale layouts preserve weight values and reject unsupported inputs by name.
Checked
- Duplicates: 14 new or renamed items checked; no duplicated owner. Existing fixture helpers are reused.
- Complexity:
fp8_appendconsolidates the existing readers; scale preparation and block emission are its stages.card_typeadds format-selection cases. - Silent failure: 4 production fallbacks traced. Unsupported scale dtype, format, and grid reach named refusals. The writer's default is reachable only for FP8_B128.
- Tests: Static mutation check: table and MXFP8 assertions reject removal of the stack guard (
modelopt.rs:216); synthetic and real-row assertions reject removal of the column term (modelopt.rs:541); held-size assertions reject the former byte count (quant_config.rs:181); the Python self-test rejects removal of the finite-scale check (fp8_scales.py:125). - Verification: The Python self-test passed with temporary files held in memory, including fixture hashes, range slices, and 21 undefined-scale refusals. All 51 fixture row hashes matched the checked-in reference. The Rust test covers 50 accepted rows and one named refusal.
- Adversarial checks: Empty and misaligned dimensions, boundary scale blocks, non-finite values/products, and mismatched expert shapes reach guards or named errors.
- Gates: Both changed expectations carry dated PIN comments and reasons. The PR supplies FAIL-first mutation results.
- Escape catalog: No matching patterns.
Notes
Rust tests were not rerun under the output-only write restriction. The PR reports passing host tests. No GPU gate evidence is supplied.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
Collaborator
Author
|
The review is done and the contribution check passed, so I'm merging this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
F8_E4M3 가중치의 스케일이 행마다 하나(채널), 텐서에 하나, 32x32 블록마다 E8M0 하나인 체크포인트를 기존 카드 형식 FP8_B128과 MXFP8로 읽습니다. 값은 그대로 두고 스케일만 각 카드 블록에 복사하므로 새 커널과 새 GGUF 타입은 없습니다. 바뀐 파일은
crates/hf의 두 소스와 시험 fixture뿐입니다.Part of #495.
What and why
FP8 checkpoints store the scale of an E4M3 weight in three more layouts than the 128 by 128 block FP8_B128 already reads: one scale for each row (compressed-tensors channel), one scale for the whole tensor (ModelOpt FP8), and one E8M0 scale for each 32 by 32 block. bloomery gave none of these a card type, so a checkpoint in these layouts could not be placed. This PR reads all three onto the two types the card walks already, with the values unchanged.
Format::card_typeincrates/hf/src/quant_config.rsis the one rule from a format to its card type. A block of width 128 or more in multiples of 128 is FP8_B128, a block of width 32 or more in multiples of 32 is MXFP8, and any other FP8 block has no card type and is refused by name.Format::fp8_scale_blockis the one owner of the area a scale covers and of the stored grid shapes it accepts ([r, c], ModelOpt's[r, 1, c, 1], a one-column grid as[r], a single scale as[]). The plan'slayoutand the reader used to keep two copies of this rule.crates/hf/src/modelopt.rshas one reader,fp8, in place ofmxfp8,fp8_b128andfp8_b128_append. It finds each block's scale with(row / a) * c + (j * blck) / band writes an f32 (widened from F32, BF16 or E8M0) for FP8_B128 or the E8M0 byte for MXFP8. Routed experts of a row or a tensor scale stack as[k, rows, n_expert], as the 128 by 128 experts do.Format::heldcounts every format by the bytes of its card type, so the oldscaled_bytescount by squares is gone. A block the card cannot hold returnsNone.A row or tensor scale FP8 weight whose row length is not a multiple of 128 is refused by name (in the Nemotron shard below that is 21 of 41 weights, for example
in_proj[17504, 3136]). Also refused by name: a 32 by 32 block whose scale is F32 or BF16 (MXFP8 holds only E8M0), a grid whose shape does not match the weight, an MXFP8 expert stack, and a scale or value that is not finite.Two small behavior changes sit on the same path: an MXFP8 weight placed together with an
input_scalenow reads its first companion (the scale) and leavesinput_scalealone, as FP8_B128 does, where it used to be refused; and FP8_B128 accepts an E8M0 scale stored as U8, as MXFP8 does. No real checkpoint in the plan changes under either.Release notes: Added: FP8 weights with one scale a row, a tensor or a 32 by 32 E8M0 block load onto the FP8_B128 and MXFP8 card formats.
Code shape
Format::fp8_scale_block, the three FP8 readers becamefp8, and the format-to-card-type rule isFormat::card_type.python3 tools/dup-scan.pylists no candidate.scaled_bytes,mxfp8,fp8_b128andfp8_b128_appendare removed.checked_mul, and the block buffer usestry_reserve.heldtest's 32 by 32 value and the "no GGUF type" refusal case for a 32 by 32 block, which now has a type. Both carryPIN(2026-10-21):and the reason. Nounsafewas added.cargo fmtis clean onbloomery-hf. The lint count is checked by the PR check, not here.Duplication found or removed: the scale-grid shape rule in the plan's
layoutand in the reader, and the writersmxfp8andfp8_b128, which now live infp8andFormat::fp8_scale_block(crates/hf/src/modelopt.rs,crates/hf/src/quant_config.rs).What I ran
Host tests and a compile check on an x86 Linux host, at head
98908fe7eb26d1f920ad226db6f3577f58e5a4cf. The PR head differs from it only in the Python reference generator (crates/hf/tests/fixtures/fp8_scales.py), which now refuses non-finite scales; the Rust code and the reference file are the same bytes, and the full host suite passed again at the PR head:cargo test -p bloomery-hf -p bloomery-model-hf --lib cargo check -p bloomery-model-hf --all-targetsThe 21
bloomery-model-hftests include the pinned GLM FP4-Local plan bytes, so the MXFP8 count bycard_typeinstead ofscaled_bytesgives the same numbers.Real rows against the producer's rule
quant_config::tests::real_fp8_rows_decode_to_their_producers_ruleplaces rows of three real checkpoints by their ownconfig.json, normalizes them, decodes each row withdequant_rowand compares its sha256 withcrates/hf/tests/fixtures/fp8_scales.py ref. That script decodes from the checkpoint definition with the Python standard library only: it widens E4M3, BF16 and E8M0 in f64, multiplies, and rounds to f32 once. The fixture slices come from HTTP range reads of the pinned revisions.down_proj, one scale a rowout_proj, one scale a tensorw2, E8M0 a 32 by 32 blockAll 50 checked rows equal the producer's rule bit for bit (difference 0). The same test checks that Nemotron's
in_projrow, whose length 3136 is not a multiple of 128, is refused by name.Synthetic layouts
modelopt::tests::fp8_weights_take_their_block_s_scale_a_row_blockbuilds a 130 by 256 weight with a 128 by 128 grid (F32[2, 2], BF16[2, 1, 2, 1], E8M0), a row scale (F32[130], BF16[130, 1]), a tensor scale (F32[], BF16[1]) and a 32 by 32 E8M0 grid[5, 8]. For each it checks the type, the dims, the byte count, the scale of every block, the unchanged value bytes and adequant_rowthat matches bit for bit. It also covers the refusals above and a row scale expert stack of[256, 130, 2].The tests catch a defect
Each of seven one-line defects was planted in the test host's work tree and reverted afterwards. Before the defects, the 17 selected tests passed. Each defect made at least two of them fail with exit 101:
fp8_weights_take_their_block_s_scale_a_row_block,each_format_holds_its_values_and_plain_scales,real_fp8_rows_decode_to_their_producers_rulemxfp8_weights_move_into_the_mxfp8_block_unchanged, the real rows testthe_table_writes_each_format_as_its_typeWhat the change holds in real checkpoints [derived]
held-count.pyapplies this PR's rule to the safetensors headers of one shard of each checkpoint. Before this PR none of these weights had a card type.The end-to-end number this opens is the first decode of these checkpoints with FP8 weights on the card, once a model loader maps their tensors. The existing callers of these types (
preparefor Qwen3.8 and the GLM plan) keep their results, which the tests above show.No device code changed, so no GPU gate ran and this PR makes no speed claim. The normalized weights are the FP8_B128 and MXFP8 blocks whose card walks
gate_mxfp8already pins bit for bit against the same hostdequant_row.Hardware
Host tests ran on an x86 Linux machine. The change touches no device path.
What I ran into
This does not block the PR.
just lint(Clippy) did not run on this host. The PR check runs it.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.