Skip to content

fix(models): ModelOpt NVFP4 Gemma 3 generates noise because the fused MLP drops the per-tensor scale #3142

Closed

Description

@Jaeyeong-CHOI

Summary

A Gemma 3 checkpoint quantized with NVIDIA ModelOpt (NVFP4, quant_method: modelopt) loads without error but generates noise. The Gemma 1, 2 and 3 MLPs run their three projections through one fused quantized kernel, and that kernel has no argument for the per-tensor scale ModelOpt stores beside the block scales (weight_scale_2, loaded as QuantizedWeight::global_scale). The MLP therefore runs unscaled, and the model emits garbage instead of an answer.

Background

Gemma 1/2/3 MLPs route gate, up and down projections through a single fused quantized kernel whenever the three planes share a layout. The non-fused UnifiedLinear::forward applies a global_scale after the matmul, but the fused path never receives it. fused_mlp_quantized_weights gates entry on group_size, bits and mode matching across the three planes, and does not consider global_scale at all, so a ModelOpt triplet that carries one still takes the fused path and loses it. Setting MLXCEL_COMPILED_QGELU_MLP=0 does not help: the wrapper's fallback takes the same unscaled planes.

The reporter's in-memory measurements show the output diverging exactly as the per-projection global_scale moves away from 1, while outputs are themselves of order 1e-3, so the differences are not rounding.

Proposed Solution

Keep a Gemma MLP whose quantized projections carry a global_scale off the fused kernel and route it through the per-projection path that applies the scale, or extend the fused kernel to apply the per-tensor scale. Either keeps affine and plain NVFP4 Gemma checkpoints on the fast fused path while making ModelOpt NVFP4 correct.

Implementation Notes

  • MLP::forward takes the fused path at src/models/gemma3.rs:470, src/models/gemma.rs:276 and src/models/gemma2.rs:329, each guarded by mlxcel_core::layers::fused_mlp_quantized_weights.
  • fused_mlp_quantized_weights (src/lib/mlxcel-core/src/layers.rs:74) compares only group_size, bits and mode across the three QuantizedWeights; it never inspects global_scale. QuantizedWeight has a global_scale: Option<..> field that UnifiedLinear::forward applies post-matmul.
  • gemma3::ModelArgs::group_size() still falls back to 64 for a ModelOpt config, producing one quantized layout does not match declared metadata warning per linear. Since fix(quant): load ModelOpt W4A16_NVFP4 checkpoints in families without a ModelOpt group size #3026 the mode is inferred from shapes so the planes still load as NVFP4; the dropped scale is the remaining cause of the noise, but the group-size fallback is worth tidying alongside.
  • Not affected: Gemma 4 has its own scaled fused MLP (perf(gemma4): fold NVFP4 global scales into fused MLP kernel #698), and the fused QKV path splits scale-carrying planes since fix: Close NVFP4 global-scale load gaps left after #2441 #2444.

Acceptance Criteria

  • iromu/Gemma3-1B-tools-NVFP4 and APMIC/ACE-gemma-3-4b-it-nvfp4 load and answer Paris for the reproduction prompt.
  • Affine and plain NVFP4 Gemma 3 checkpoints keep their current fused path and output.
  • A regression test covers a Gemma MLP whose gate/up/down projections carry non-unit per-tensor scales (the in-memory vs loaded-from-disk divergence in the report).

Original Suggestion

Title: fix(models): a ModelOpt NVFP4 Gemma 3 checkpoint loads and generates noise

Summary

A Gemma 3 checkpoint quantized with NVIDIA ModelOpt (NVFP4, quantization_config with quant_method: modelopt) loads without an error and generates noise. The Gemma 1, 2 and 3 MLPs run their three projections through one fused kernel, and that kernel has no argument for the per-tensor scale ModelOpt stores beside the block scales (weight_scale_2, loaded as QuantizedWeight::global_scale). The MLP runs unscaled.

Reproduction steps

hf download iromu/Gemma3-1B-tools-NVFP4 --revision ec7bf1aee6d438527ee2ee14f537c912273fedb9 \
  --local-dir models/Gemma3-1B-tools-NVFP4

mlxcel generate -m models/Gemma3-1B-tools-NVFP4 -n 64 --temp 0 \
  -p "What is the capital of France? Answer in one word."

Expected behavior

Paris.

Actual behavior

Chor démontréne-secầnन्न اقدامات FAాడు επίσης j beeswax Nun “ Dzreg commun de lauta ricerchera leo fier serv …

The load itself takes the ModelOpt route: Repacking 182 ModelOpt NVFP4 weight groups (source mode nvfp4) to MLX native NVFP4 via direct triplet transcode. APMIC/ACE-gemma-3-4b-it-nvfp4 @ d8d6d7db9203 (4B, the same layout) does the same: The three given non-zero twinnings have to be worked in a. ….

mlxcel version

main @ fab141b

Install method

Built from source

Platform

Linux + CUDA (gb10)

Model checkpoint

iromu/Gemma3-1B-tools-NVFP4 @ ec7bf1aee6d4 (gemma3_text, ModelOpt 0.46.0, NVFP4, group size 16, lm_head excluded); APMIC/ACE-gemma-3-4b-it-nvfp4 @ d8d6d7db9203

Relevant logs

The MLP alone, on a synthetic NVFP4 MLP (64 wide, intermediate 128) whose three projections carry a global_scale, MLP::forward against the same three projections run one after the other (measured on an earlier base with the same fused path):

global_scale of gate / up / down in memory: largest difference through load_text_weights from a ModelOpt triplet on disk
1, 1, 1 0 4.8e-7
0.5, 1, 1 1.9e-4 3.58
1, 2, 1 3.7e-4 6.39
1, 1, 3.25 8.3e-4 14.37
0.5, 2, 3.25 8.0e-4 11.86

The in-memory outputs are themselves of the order of 1e-3, so those differences are not rounding.

Additional context

Pre-submission checks

  • I searched existing issues and did not find a duplicate
  • This is not a security vulnerability (those go to SECURITY.md instead)

Activity

  1. changed the title [-]fix(models): a ModelOpt NVFP4 Gemma 3 checkpoint loads and generates noise[/-] [+]fix(models): ModelOpt NVFP4 Gemma 3 generates noise because the fused MLP drops the per-tensor scale[/+] on Nov 17, 2026
  2. added
    status:ready
    type:bug
    priority:medium
    area:models
    on Nov 17, 2026
  3. added 3 commits that reference this issue on Nov 19, 2026
    9d05c3a
    ec5fcaf
    45ee317
  4. added this to the 0.9 milestone on Nov 30, 2026
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

    area:modelspriority:mediumstatus:readytype:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions