Repository navigation
feat(quant): load compressed-tensors NVFP4 text checkpoints - #3170
Merged
inureyes merged 1 commit intoNov 19, 2026
Merged
Conversation
A compressed-tensors (llm-compressor) nvfp4-pack-quantized checkpoint holds ModelOpt's NVFP4 triplet under other names: the packed codes in weight_packed, the block scales unchanged, and the tensor scale as its reciprocal in weight_global_scale. Its config declares quant_method compressed-tensors, so the text route did not recognize it and the load failed with Weight not found. The declaration is now read as the ModelOpt one it is equivalent to, and the linears are renamed to ModelOpt's triplet (with the global scale inverted and the activation scale dropped) before the existing repack. Laguna, which reads this layout in its own sanitizer, is left as it was.
Member
|
Hardening review: no code changes needed. What was checked:
Validation (ROCm gfx1151, main plus this PR plus #3107): the five new tests pass, including the ModelOpt twin test, which runs on ROCm rather than skipping. 807 focused tests pass across |
This was referenced Nov 20, 2026
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.
Summary
Loads NVFP4 checkpoints written by llm-compressor (compressed-tensors,
format: "nvfp4-pack-quantized") on the text route. The layout is ModelOpt's NVFP4 triplet under other tensor names, so the declaration is read as the ModelOpt one and the linears are renamed to that triplet ahead of the existing repack. No new transcode.Related issues
Closes #3169.
Type of change
feat— new user-visible featureWhy this is a rename
compressed-tensors' own converter from ModelOpt (
src/compressed_tensors/entrypoints/convert/converters/modelopt_nvfp4.py) mapsweighttoweight_packedwith the bytes unchanged, keepsweight_scale, and writesweight_global_scale = 1 / weight_scale_2andinput_global_scale = 1 / input_scale.laguna_sanitizealready reads this layout for Laguna's experts (#1347) with the same reciprocal.I also checked it without mlxcel: decoding three layers of
mgoin/Qwen3-0.6B-NVFP4in numpy (E2M1 codes, low nibble first, times the E4M3 block scale, divided byweight_global_scale) and comparing with the unquantizedQwen/Qwen3-0.6Bweights gives a relative L2 error of 0.094 to 0.095, the size of 4-bit quantization error. The other readings are not close: high nibble first gives 1.41, and multiplying by the global scale gives about 2e7.Change
All in
src/models/sanitize.rs:compressed_tensors_nvfp4_as_modelopt(new): aquantization_configwithquant_method: "compressed-tensors"andformat: "nvfp4-pack-quantized"is rewritten to the ModelOpt-shaped declaration, carrying itsconfig_groupsover, sogemma4::is_modelopt_nvfp4stays the one judge (4-bit float weights at group size 16 in every group).modelopt_quantization_configalready rewrites thehf_quant_config.jsonshape the same way.compressed_tensors_nvfp4_to_modelopt_triplets(new, first step ofsanitize_modelopt_nvfp4_weights): for each linear withweight_packedandweight_global_scale, renameweight_packedtoweight, store1 / weight_global_scaleasweight_scale_2, dropinput_global_scale. A global scale that is not one finite non-zero number fails the load with the layer named. Aweight_packedwithout a global scale (compressed-tensors' integerpack-quantized, Kimi K3'smxfp4-pack-quantized) is not touched.modelopt_nvfp4_group_sizereturns 16 for the compressed-tensors declaration too, so the families that read their NVFP4 group size fromquantization_config(Qwen3, Qwen3-MoE, Llama/Qwen2.5, PhiMoE, Mistral 4) load these planes without a layout warning.load_text_weightsleaves a Laguna checkpoint with this declaration alone, as before:laguna_sanitizestacks the per-expertweight_packedplanes itself and would not find them after the rename.Activations: these exports also declare 4-bit input activations (
input_global_scale). mlxcel does not quantize activations, for ModelOpt NVFP4 either, so the weights run as W4A16.Before / after
GB10 (sm_121, CUDA 13.0), release builds of
5288442b3(main, the base of this branch) and of this PR's tree,generate -n 200 --temp 0,MLXCEL_SDPA_DETERMINISTIC=1.main, all three promptsmgoin/Qwen3-0.6B-NVFP4@545def2ddError: Weight not found: model.layers.0.self_attn.o_proj.weight, exit 1Paris/4/The ocean breathes with the rhythm of the earth, a vast, ever-shifting tapestry of life and mystery.Minguinho-zeze/Qwen3-1.7B-NVFP4A16-RTN@e0e3c03ad(weights only)Paris/4/The sea, an endless expanse of water, teems with life and mystery, its waves crashing against shores and depths that reach into the unknown.llmat/Qwen3-4B-Instruct-2507-NVFP4@3b387679aParis/4/The sea stretches endlessly, a vast, shimmering expanse of blue that whispers secrets to the wind and cradles the rhythm of the tides.The two smaller ones are thinking models and spend 125 to 167 tokens before the answer; with
--show-reasoningthe 0.6B one reasons in ordinary English, as the unquantizedQwen/Qwen3-0.6Bdoes. None of the runs prints a layout warning.Checkpoints that load today answer the first prompt byte for byte as on
main:Qwen/Qwen3-0.6B(bf16), the ModelOpt NVFP4 exportsiromu/Gemma3-1B-tools-NVFP4andnvidia/Qwen2.5-VL-7B-Instruct-NVFP4, and the MLX exports gemma-3-270m-it-4bit, gemma-3-4b-it-4bit and Qwen2.5-VL-3B-Instruct-4bit.Test plan
Run on this PR's commit (one commit on
5288442b3, tree28c734a4e432) on a DGX Spark (GB10).cargo fmt --all -- --checkcargo clippy --workspace --all-targets --features cuda -- -D warningscargo build --release --features cudasrc/models/sanitize_tests.rs):a_compressed_tensors_nvfp4_checkpoint_loads_as_its_modelopt_twin(a compressed-tensors linear with global scale 2.0 and the ModelOpt fixture withweight_scale_20.5 load throughload_text_weightsto byte-identical forward outputs; global scale 4.0 does not),other_compressed_tensors_declarations_are_not_read_as_nvfp4(pack-quantized,mixed-precision, and an NVFP4 declaration with 8-bit weights keep their tensors),a_compressed_tensors_global_scale_that_cannot_be_inverted_fails_the_load(0, NaN, infinity),a_compressed_tensors_nvfp4_config_declares_the_nvfp4_group_size, andload_text_weights_leaves_laguna_compressed_tensors_planes_to_its_sanitizer: passcargo test --profile test-fast --features cuda --lib -- models::sanitize modelopt nvfp4 fp8_ct compressed loading::vlm: 424 passed;… -- laguna kimi_k3 inkling: 241 passedmake verify-test-cuda(cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1): 15948 passed, 0 failed, 499 ignoredci.ymljobs a fork PR does not get, by hand:clippy(cargo clippy -p mlxcel --lib --tests -- -D warnings, default features); license headers, env-var docs, kernel dtype keys, kernel port dispatch, cross-repo refsxla-compile: not run (no IREE on this host); no XLA file is touchedcargo deny check: not applicable (no manifest or lockfile change)Notes for reviewers
load_text_weightsalready special-cases Gemma 4 for the same reason (its own sanitizer). I found no other family that readsweight_global_scaleitself (grep -rn weight_global_scale src:laguna_sanitize.rsand comments inswitch_layers.rs).JEILDLWLRMA/Qwen3-VL-4B-Instruct-NVFP4still fails withWeight not foundon this branch; that loader does not call the repack at all), Gemma 4 (validate_quantization_schemedoes not acceptcompressed-tensors, by reading the code), and per-expert MoE planes outside Laguna. I can follow up on the Qwen3-VL route.modelopt_quantization_config,is_modelopt_nvfp4_text_checkpointandmodelopt_nvfp4_group_sizekeep their names though they now also answer for the compressed-tensors spelling; the doc comments say so. Renaming them would touch every family's accessor and seemed out of scope.Checklist
docs/: not updated. I did not find a page listing supported external quantization formats; tell me where it belongs and I will add it// Used by: ...comments: on the two new functions; the callers of the three existing ones are unchanged