Repository navigation
hf: a ModelOpt NVFP4 shard opens, its U8 weights and F8_E4M3 scales held as stored bytes - #489
Merged
juliankang4 merged 1 commit intoOct 19, 2026
Conversation
…eld as stored bytes safetensors holds U8 and F8_E4M3 as stored bytes, so a ModelOpt shard opens; until now every shard of such a checkpoint was refused at open by its first U8 entry. raw returns both with their dtype and shape, and the f32 read refuses both by name, as it refuses I64 and BOOL. The test fixture is a small ModelOpt-layout shard: the first four rows of layer 0's gate_proj of experts 0 and 1 of nvidia/Qwen3.8-Flash-Next-NVFP4, range-read from shard 1 at fc694b54, plus one synthetic triple, each under its own header entries.
Contributor
There was a problem hiding this comment.
Verdict: CLEAN: Both new dtypes use the validated raw-byte path and return named errors from unsupported typed reads.
Checked
- Duplicates: 1 new test checked, none duplicated; both enum variants extend the existing dtype owner.
- Complexity: the dtype matches gain ordinary cases.
- Silent failure: 2 existing
.ok()sites followed; failed conversions becomeError::Format. U8 and F8_E4M3 typed reads propagateDtypeorKinderrors to callers. - Tests: static mutation check of crates/hf/src/safetensors.rs:63, crates/hf/src/safetensors.rs:87, and crates/hf/src/safetensors.rs:302: removing either parser arm or using size 2 fails the parse unwrap; returning f32 fails the error assertion.
- Bounds: malformed lengths, overlap and shape overflow reach existing errors. The fixture's 12 tensor ranges have valid sizes and do not overlap.
- Gates: no existing gate or pin changed. The PR reports the fixture failing on base with
Error::Dtypefor U8. - Escape catalog: no C1–C4 patterns matched. The change touches load-time parsing, with no hot-path work added.
Notes
Rust tests were not rerun during this review. The fixture was checked independently. The PR reports 6 passing safetensors tests; its t0 result remains TBD.
🔨 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 was referenced Oct 19, 2026
Qwen3.8-Flash-Next-FP4-Local on one DGX Spark (TP=1): format support, speed and efficiency plan
#493
Closed
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.
NVIDIA가 배포하는 NVFP4 체크포인트(ModelOpt) 파일을 bloomery의 safetensors 리더가 열 수 있게, U8과 F8_E4M3 tensor를 저장된 바이트 그대로 읽도록 하는 작업입니다.
Part of #458, section 7 (weight formats).
What and why
With this PR,
hf::safetensorsopens the shards of a ModelOpt NVFP4 checkpoint, such as NVIDIA's NVFP4 checkpoint of Qwen3.8-Flash-Next. ModelOpt stores the packed 4-bit weights as U8 and the block scales as F8_E4M3. On main the header parser knows neither dtype, so one such entry makes it refuse the whole file at open. 10 of the checkpoint's 11 safetensors files hold them.The change is in
crates/hf/src/safetensors.rs:DtypegainsU8andF8E4M3(header namesU8andF8_E4M3), each 1 byte wide, so the open-time checks of shape, byte range and overlap cover them like every other dtype.rawreturns them as stored bytes with their dtype and shape. It slices the entry's byte range the same way for every dtype.tensorrefuses both by name withError::Dtype, as it already refuses I64 and BOOL.Nothing decodes NVFP4 here. No GGUF code, GPU crate or engine path changes.
Release notes: Added: Safetensors files with U8 and F8_E4M3 tensors, such as ModelOpt NVFP4 checkpoints, now open, and those tensors read as stored bytes.
Code shape
Dtypematches; no new function or type.Dtype::U8andDtype::F8E4M3are whatDtype::parsereturns for the two header names.Error::Dtype, never a widened value.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.cargo fmtruns in the t0 check below; clippy is not part of that check.Duplication found or removed (
path:line), or "none": none.What I ran
All results are on head
39d65073, based onb5ddb224.The new test
a_modelopt_shard_slice_opens_with_u8_and_f8_e4m3_held_rawopens the fixturecrates/hf/tests/fixtures/modelopt-nvfp4.safetensors(14,216 bytes). The fixture holds the first 4 rows of layer 0'sgate_projfor experts 0 and 1, taken by HTTP range reads frommodel-00001-of-00010.safetensorsofnvidia/Qwen3.8-Flash-Next-NVFP4at revisionfc694b54fb0174e0913e6adf86691ef85a4ead47and kept under their own header names, plus one small synthetic triple. The reference is the fixture's own header: for each entry the test reads, the stored dtype, shape and byte range.experts.0.gate_proj.weight: U8, shape [4, 1280], 5,120 bytesrawreturns U8, [4, 1280], 5,120 bytes;tensorrefuses it as U8experts.0.gate_proj.weight_scale: F8_E4M3, shape [4, 160], 640 bytesrawreturns F8_E4M3, [4, 160], 640 bytes;tensorrefuses it as F8_E4M3A ModelOpt NVFP4 shard now opens: its U8 and F8_E4M3 entries read back as stored, and the f32 read refuses them by name.
Checks:
cargo test -p bloomery-hf --lib safetensors:test result: ok. 6 passed; 0 failed. That is the new test and the five existing safetensors tests.Dtype { name: "model.language_model.layers.0.mlp.experts.0.gate_proj.weight", dtype: "U8" }.crates/hf/src/safetensors.rsand adds the fixture. In that file it changes three existing lines: the module comment, theDtype::sizearm that now lists the two 1-byte dtypes beside BOOL, and thetensorrefusal arm that now lists them beside I64 and BOOL. The five existing safetensors tests pass unedited. No code outsidesafetensors.rsmatches onDtype, andgit diff upstream/main -- crates/ggufis empty.just contrib-check --tier t0on this head: TBD(t0 /DONE tier=t0/)To reproduce, from the repository root:
cargo test -p bloomery-hf --lib safetensors git diff --stat upstream/main...HEADNo GPU check was run, because no GPU crate, kernel or engine path changes, and the PR makes no speed claim.
Hardware (if the change is for a machine)
The change is not machine specific. The tests ran on macOS.
What I ran into
This does not block the PR. One ModelOpt triple can span two shard files:
model-00002-of-00010.safetensorsholds 9,643 U8 entries and 9,642 F8_E4M3 entries, and the expert stacks of layers 8, 14, 21, 27, 33, 40 and 46 cross a shard boundary. Code that reads a whole triple has to resolve each name throughmodel.safetensors.index.jsoninstead of reading one shard at a time.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.