Skip to content

feat(quant): load compressed-tensors NVFP4 text checkpoints - #3170

Merged
inureyes merged 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:feat/compressed-tensors-nvfp4
Nov 19, 2026
Merged

inureyes merged 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:feat/compressed-tensors-nvfp4

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

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 feature

Why this is a rename

compressed-tensors' own converter from ModelOpt (src/compressed_tensors/entrypoints/convert/converters/modelopt_nvfp4.py) maps weight to weight_packed with the bytes unchanged, keeps weight_scale, and writes weight_global_scale = 1 / weight_scale_2 and input_global_scale = 1 / input_scale. laguna_sanitize already 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-NVFP4 in numpy (E2M1 codes, low nibble first, times the E4M3 block scale, divided by weight_global_scale) and comparing with the unquantized Qwen/Qwen3-0.6B weights 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): a quantization_config with quant_method: "compressed-tensors" and format: "nvfp4-pack-quantized" is rewritten to the ModelOpt-shaped declaration, carrying its config_groups over, so gemma4::is_modelopt_nvfp4 stays the one judge (4-bit float weights at group size 16 in every group). modelopt_quantization_config already rewrites the hf_quant_config.json shape the same way.
  • compressed_tensors_nvfp4_to_modelopt_triplets (new, first step of sanitize_modelopt_nvfp4_weights): for each linear with weight_packed and weight_global_scale, rename weight_packed to weight, store 1 / weight_global_scale as weight_scale_2, drop input_global_scale. A global scale that is not one finite non-zero number fails the load with the layer named. A weight_packed without a global scale (compressed-tensors' integer pack-quantized, Kimi K3's mxfp4-pack-quantized) is not touched.
  • modelopt_nvfp4_group_size returns 16 for the compressed-tensors declaration too, so the families that read their NVFP4 group size from quantization_config (Qwen3, Qwen3-MoE, Llama/Qwen2.5, PhiMoE, Mistral 4) load these planes without a layout warning.
  • load_text_weights leaves a Laguna checkpoint with this declaration alone, as before: laguna_sanitize stacks the per-expert weight_packed planes 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.

Checkpoint main, all three prompts This PR: capital of France / 2 + 2 / one sentence about the sea
mgoin/Qwen3-0.6B-NVFP4 @ 545def2dd Error: Weight not found: model.layers.0.self_attn.o_proj.weight, exit 1 Paris / 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) same error 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 @ 3b387679a same error Paris / 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-reasoning the 0.6B one reasons in ordinary English, as the unquantized Qwen/Qwen3-0.6B does. 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 exports iromu/Gemma3-1B-tools-NVFP4 and nvidia/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, tree 28c734a4e432) on a DGX Spark (GB10).

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --features cuda -- -D warnings
  • cargo build --release --features cuda
  • The five new tests by name (src/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 with weight_scale_2 0.5 load through load_text_weights to 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, and load_text_weights_leaves_laguna_compressed_tensors_planes_to_its_sanitizer: pass
  • cargo test --profile test-fast --features cuda --lib -- models::sanitize modelopt nvfp4 fp8_ct compressed loading::vlm: 424 passed; … -- laguna kimi_k3 inkling: 241 passed
  • Negative controls: the global scale not inverted (the twin test fails); the declaration not recognized (the twin, group-size and bad-scale tests fail); the Laguna exemption removed (the Laguna test fails)
  • make verify-test-cuda (cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1): 15948 passed, 0 failed, 499 ignored
  • Self-hosted ci.yml jobs 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 refs
  • Validated with real checkpoints: the table above, and the numpy cross-check
  • xla-compile: not run (no IREE on this host); no XLA file is touched
  • cargo deny check: not applicable (no manifest or lockfile change)
  • Metal and ROCm: not built or run here. The twin test skips where the backend has no native NVFP4 kernel; the other four run everywhere
  • A real Laguna compressed-tensors checkpoint: not run. The exemption is covered by the new test and the existing Laguna tests only

Notes for reviewers

  • The Laguna exemption is by model type. load_text_weights already special-cases Gemma 4 for the same reason (its own sanitizer). I found no other family that reads weight_global_scale itself (grep -rn weight_global_scale src: laguna_sanitize.rs and comments in switch_layers.rs).
  • Routes that now also recognize the declaration, without a checkpoint to prove them: the Qwen3.5 VLM route and the Qwen2.5-VL route call the same detector and repack, so a compressed-tensors NVFP4 export of those would take this path. I had none to run.
  • Not covered: the Qwen3-VL route (JEILDLWLRMA/Qwen3-VL-4B-Instruct-NVFP4 still fails with Weight not found on this branch; that loader does not call the repack at all), Gemma 4 (validate_quantization_scheme does not accept compressed-tensors, by reading the code), and per-expert MoE planes outside Laguna. I can follow up on the Qwen3-VL route.
  • Naming. modelopt_quantization_config, is_modelopt_nvfp4_text_checkpoint and modelopt_nvfp4_group_size keep 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

  • PR title uses a Conventional Commits prefix
  • One logical change per PR
  • Updated docs/: not updated. I did not find a page listing supported external quantization formats; tell me where it belongs and I will add it
  • Updated // Used by: ... comments: on the two new functions; the callers of the three existing ones are unchanged

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.
@inureyes

Copy link
Copy Markdown
Member

Hardening review: no code changes needed.

What was checked:

  • The rename and reciprocal match compressed-tensors' ModelOpt converter, and laguna_sanitize already reads this layout. A weight_packed plane without a global scale (pack-quantized, Kimi K3's mxfp4-pack-quantized) is left alone, and a layer with both weight and weight_packed fails the load.
  • No route conflicts. compressed_tensors_fp8_quantization returns None for any top-level format other than float-quantized, so the FP8 requantize path never claims an NVFP4 export. Gemma 4 still refuses compressed-tensors in validate_quantization_scheme before the shared repack runs.
  • Only the top-level format is matched. compressed-tensors always writes it, and a mixed-precision export contains non-NVFP4 groups that is_modelopt_nvfp4 rejects anyway, so the per-group fallback that fp8_ct has is not needed here.
  • The global scale is read once per linear, at load time, so there is no per-token cost.

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 models::sanitize, modelopt, nvfp4, compressed, laguna and qwen3_5. make verify-rocm-held passed versions, kernel checks, overlay, fmt, workspace clippy and the ROCm smoke. Its test stage passed 11,878 tests before the host ran low on memory and the run was stopped. The two failures in that stage come from #3107's missing registry row (now fixed there) and from a load-profile test that also fails on main on ROCm since #3172; neither involves this PR.

@inureyes
inureyes merged commit a825a00 into lablup:main Nov 19, 2026
32 checks passed
@inureyes inureyes added status:done Completed type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:models Model architectures, weights, loading, metadata area:core mlxcel-core: MLX FFI, primitives, KV cache, layers area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Nov 30, 2026
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers area:inference Generation, sampling, decoding (incl. speculative, DRY) area:models Model architectures, weights, loading, metadata priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(quant): load compressed-tensors NVFP4 (nvfp4-pack-quantized) text checkpoints

2 participants