Skip to content

[Pipelines] Support compressed-tensors NVFP4 checkpoints - #6773

Open
lightofbaldr wants to merge 1 commit into
modular:mainfrom
lightofbaldr:clean/nvfp4-dispatch-sm121
Open

lightofbaldr wants to merge 1 commit into
modular:mainfrom
lightofbaldr:clean/nvfp4-dispatch-sm121

Conversation

@lightofbaldr

Copy link
Copy Markdown
Contributor

Summary

MAX's FP4 config parser only recognizes the modelopt NVFP4 flavor, so
compressed-tensors NVFP4 checkpoints (e.g. RedHatAI/Llama-3.1-8B-Instruct-NVFP4)
fail to load. This adds a compressed-tensors NVFP4 load path.

Two independent problems block serving these checkpoints on a DGX Spark:

  1. Loading (this PR). The checkpoint is mixed precision — an NVFP4 body with a
    bf16 lm-head — and its global scales are stored as the reciprocal of MAX's
    multiplicative dequant convention. MAX doesn't recognize the compressed-tensors
    schema, so the graph expects packed uint8 where the checkpoint ships bfloat16.
  2. Math (already merged, #91570). On consumer Blackwell (sm_120/sm_121), NVFP4
    activation scales must be emitted rank-5.

What it does

  • New shared weights/_compressed_tensors.py helper: compressed-tensors NVFP4 schema
    recognition; weight-suffix renames; one-time global-scale reciprocation keyed on the
    raw suffix
    (so it is idempotent); optional uint8→e4m3 per-group scale reinterpret.
  • weights/quant.py: recognizes quant_method == "compressed-tensors" and translates its
    targets/ignore scope into MAX's existing per-layer modelopt QuantConfig
    representation, then reuses the modelopt builder. Each MLP/attention subtree is
    quantized all-or-nothing (partial selection raises ValueError); an unquantized
    lm_head is excluded independently so it stays bf16.
  • architectures/llama3/weight_adapters.py applies the helper; the laguna architecture
    now shares it instead of mutating the HF quantization config in place.

Validation

Unit tests (//max/tests/tests/pipelines:...)

  • test_parse_quant_config: 35 passed
  • test_llama3_weight_adapters: 5 passed

Coverage: global-scale reciprocation, idempotency (canonical scale not re-inverted),
uint8→e4m3 reinterpret, Linear-targets, regex/MoE targets, all-or-nothing subtree
rejection, non-NVFP4 compressed-tensors fall-through, and a graph-level assertion that
lm_head.weight is built as bfloat16.

Hardware — DGX Spark (GB10, sm_121a), RedHatAI/Llama-3.1-8B-Instruct-NVFP4, identical command

A) upstream, pre-fix
   ValueError: 'lm_head.weight' dtype (expected=uint8, actual=bfloat16)
   -> reached generation: 0

B) this fix, WITHOUT #91570 underneath
   lm_head crash cleared; fails one bug later:
   ValueError: Both a_scales and b_scales must be rank 5 tensors   (the sm_12x NVFP4 math, = #91570)
   -> reached generation: 0

C) this fix + #91570
   prompt : "The capital of France is"
   output : "Paris."
   14.04 tok/s   ·   TTFT 1112 ms   ·   prefill 35.97 tok/s

The failure moving A→B→C shows what each fix contributes: pre-fix, MAX can't load a
mixed-precision compressed-tensors checkpoint; this fix clears that, and the very next
thing to break is the sm_12x NVFP4 math; with #91570 underneath, the math is right and
the model serves. Neither fix alone serves a RedHat/compressed-tensors NVFP4 model on a
DGX Spark; both together do. (Including the three-way trace so a reviewer on consumer
Blackwell who lands on B doesn't conclude the change is broken.)

Fixes #6600.

@lightofbaldr
lightofbaldr requested a review from a team as a code owner July 14, 2026 17:34
BEGIN_PUBLIC
[Pipelines] Support compressed-tensors NVFP4 checkpoints

MAX's FP4 config parser only recognized the modelopt NVFP4 flavor, so
compressed-tensors NVFP4 checkpoints (e.g.
RedHatAI/Llama-3.1-8B-Instruct-NVFP4) failed to load: the graph expected
packed uint8 weights while the checkpoint's BF16-preserved lm_head shipped as
bfloat16, and the global scales use the reciprocal of MAX's multiplicative
dequant convention.

Add a shared compressed-tensors normalization helper (weight suffix renames,
one-time global-scale reciprocation keyed on the raw suffix so it stays
idempotent, and optional uint8->e4m3 per-group scale reinterpretation), and
teach the FP4 parser to translate a compressed-tensors target scope into the
existing per-layer modelopt QuantConfig representation: each MLP/attention
subtree is quantized all-or-nothing (partial selection raises), and an
unquantized lm_head is excluded independently so it stays bf16. The laguna
architecture now shares this helper instead of mutating the HF quantization
config in place.

Fixes modular#6600.
END_PUBLIC

Signed-off-by: Adam Kruger <[email protected]>
@lightofbaldr
lightofbaldr force-pushed the clean/nvfp4-dispatch-sm121 branch from f9290f8 to d75b756 Compare July 14, 2026 17:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[sm_121] compressed-tensors NVFP4 produces garbage: per-tensor global scale not re-inverted + linear block-scales re-swizzled

1 participant