Skip to content

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

Open

Description

@lightofbaldr

Follow-up to #6570 / #6597. On consumer Blackwell (GB10, sm_121), compressed-tensors NVFP4 models produce garbage output end-to-end via max generate (e.g. RedHatAI/Llama-3.1-8B-Instruct-NVFP4). Both the CUDA-core naive path and a warp-level tensor-core path produce byte-identical garbage, so the defect is in the scale preparation/loading, upstream of the matmul kernel — not the kernel itself.

Using the NVFP4 dequant convention value = fp4 × block_scale × global_scale, there appear to be two issues in MAX's compressed-tensors NVFP4 handling:

1. Per-tensor global scale is not re-inverted

compressed-tensors stores weight_global_scale / input_global_scale as divisors (i.e. 1/scale; observed e.g. weight_global_scale = 3584 ≈ 1 / 0.00028 ≈ amax/(6·448)). MAX's quantized_matmul → _matmul_float4 consumes weight_scale_2 / input_scale as direct multipliers (the modelopt convention) without re-inverting, so the per-tensor magnitude is applied as its reciprocal → wrong magnitudes → garbage.

vLLM's compressed_tensors_w4a4_nvfp4 scheme handles this by reciprocating at load: "CT stores as divisors, i.e. 1/scale" → 1.0 / weight_global_scale, then alpha = input_global_scale * weight_global_scale.

2. Already-linear block scales are re-swizzled

compressed-tensors stores the per-group block scales in linear layout, but MAX's NVFP4 path applies the modelopt/TCGEN swizzled-scale interleave unconditionally, corrupting the already-linear scales.

Independent confirmation

Avarok's dgx-vllm (fix_nvfp4_emulation_backend.py) documents and fixes both of these for compressed-tensors on GB10: it detects an inverted weight_global_scale (< 1.0) and re-inverts it, and uses the linear scales directly instead of swizzle-converting.

Repro

max generate --model-path <compressed-tensors NVFP4 model> --devices gpu on sm_121 → unicode/garbage tokens.

Note on fix location

A Python-level reciprocal in the Llama weight adapter had no effect — these scales are consumed by the compiled weight loader, not the adapter's state dict. The fix belongs in MAX's compressed-tensors process_weights_after_loading (or equivalent), distinguishing compressed-tensors (divisor + linear scales) from modelopt (direct + swizzled).

Activity

  1. tbraun96 commented on Jun 3, 2026

    @tbraun96

    Disclosure: I work on Atlas and we hit both of these NVFP4 scale-prep gotchas during GB10 bring-up, so your "byte-identical garbage from both kernel paths, therefore it is upstream of the matmul" diagnosis matches exactly how we cornered it too.

    You have the first one nailed: compressed-tensors stores weight_global_scale / input_global_scale as divisors (the 1/scale form, your 3584 ≈ 1/0.00028 ≈ amax/(6·448) is the giveaway), so the dequant has to re-invert before applying value = fp4 × block_scale × global_scale. Consume it as a multiplier directly and you get stable garbage, which is precisely the deterministic, both-paths-identical failure you are seeing.

    The second gotcha that got us after we fixed the global scale: the per-block (1x16) scales are often stored swizzled, not linear. compressed-tensors / ModelOpt checkpoints interleave the block-scale factors in a 128x4-ish layout for the tensor-core path, and if you load them as a plain row-major [rows, cols/16] array the dequant lines up for the first tile and then walks off into garbage. We needed an explicit de-interleave (or to consume them in the swizzled order the kernel expects) before the block-scale multiply was correct.

    # NVFP4 dequant order that finally worked for us:
    #   1. global_scale = 1.0 / stored_global_scale     (re-invert the divisor)
    #   2. de-swizzle block scales (128x4 interleave) -> linear, OR read in swizzled order
    #   3. value = fp4_e2m1 * block_scale * global_scale
    

    @lightofbaldr once you re-invert the global scale, do your block-scales come out of the checkpoint linear or swizzled? If de-swizzling is also needed, that is likely the second source of corruption hiding behind the first, and it is easy to miss because fixing only the global scale makes the very first few values look right before it diverges.

  2. added 2 commits that reference this issue on Jul 14, 2026
    f9290f8
    d75b756
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions