Skip to content

fix(models): Gemma 4 26B A4B NVFP4 MoE exports fail to load because per-expert linears are not stacked #3197

Closed

Description

@Jaeyeong-CHOI

Summary

NVFP4 exports of Gemma 4 26B A4B (the MoE model) fail to load with Missing weight: language_model.model.layers.0.experts.switch_glu.gate_proj. ModelOpt and compressed-tensors both write each layer's experts as one linear per expert, but the Gemma 4 loader only reads them stacked (as mlx-lm stores them).

Background

sanitize_gemma4_nvfp4_weights repacks each per-expert linear, leaving 128 planes per projection under experts.{e}.{proj} with that expert's tensor scale beside each. Nothing stacks them, and SwitchLinear's fallback for unstacked experts looks under {root}.switch_mlp.{proj}, not switch_glu, so the stacked tensor the loader expects is never built.

Proposed Solution

Stack the per-expert NVFP4 linears of a Gemma 4 MoE export into the switch_glu layout the loader reads, using the per-expert stacking helper added for Qwen3.5 in #3196 (which keeps the per-expert tensor scale). This change stacks on that PR.

Implementation Notes

Acceptance Criteria

  • nvidia/Gemma-4-26B-A4B-NVFP4 and RedHatAI/gemma-4-26B-A4B-it-NVFP4 load and answer Paris, matching lmstudio-community/gemma-4-26B-A4B-it-MLX-4bit.
  • A regression test covers stacking per-expert NVFP4 linears into switch_glu.

Original Suggestion

Title: fix(models): Gemma 4 26B A4B NVFP4 exports do not load (Missing weight: …experts.switch_glu.gate_proj)

Summary

The NVFP4 exports of Gemma 4 26B A4B (the MoE model) do not load. NVIDIA ModelOpt and compressed-tensors both write a layer's experts as one linear each, and the Gemma 4 loader only reads them stacked, as mlx-lm stores them.

Reproduction steps

hf download nvidia/Gemma-4-26B-A4B-NVFP4 --revision a19cfe00b --local-dir models/Gemma-4-26B-A4B-NVFP4

mlxcel generate -m models/Gemma-4-26B-A4B-NVFP4 -n 200 --temp 0 \
  -p "What is the capital of France? Answer in one word."

Expected behavior

Paris, as lmstudio-community/gemma-4-26B-A4B-it-MLX-4bit answers.

Actual behavior

Error: Failed to load Gemma4 text model: Missing weight: language_model.model.layers.0.experts.switch_glu.gate_proj

Exit 1. The same for RedHatAI/gemma-4-26B-A4B-it-NVFP4 @ 5557756b8 (compressed-tensors nvfp4-pack-quantized).

mlxcel version

main @ 363a0ba

Install method

Built from source

Platform

Linux + CUDA (gb10)

Model checkpoint

nvidia/Gemma-4-26B-A4B-NVFP4 @ a19cfe00b (gemma4, ModelOpt NVFP4; only the experts are quantized, 11520 linears)

Relevant logs

None beyond the error above.

Additional context

The expert tensors of layer 0, from the safetensors headers:

mlx-lm (lmstudio-community/gemma-4-26B-A4B-it-MLX-4bit) nvidia/Gemma-4-26B-A4B-NVFP4 RedHatAI/gemma-4-26B-A4B-it-NVFP4
experts …layers.0.experts.switch_glu.{gate_proj, up_proj, down_proj}.{weight, scales, biases}, each [128, …] …layers.0.experts.{0..127}.{gate_proj, up_proj, down_proj}.{weight, weight_scale, weight_scale_2} …layers.0.experts.{0..127}.{gate_proj, up_proj, down_proj}.{weight_packed, weight_scale, weight_global_scale}
  • sanitize_gemma4_nvfp4_weights repacks each of those linears, which leaves 128 planes per projection under experts.{e}.{proj} with that expert's tensor scale beside each. Nothing stacks them, and SwitchLinear's own fallback for unstacked experts looks under {root}.switch_mlp.{proj}, not switch_glu.
  • The fix needs the per-expert stacking helper of fix(models): keep per-expert NVFP4 tensor scales in the Qwen3.5 MoE stacking #3196 (which does the same for Qwen3.5), so it is stacked on that PR. A fix with a test is ready.

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): Gemma 4 26B A4B NVFP4 exports do not load (`Missing weight: …experts.switch_glu.gate_proj`)[/-] [+]fix(models): Gemma 4 26B A4B NVFP4 MoE exports fail to load because per-expert linears are not stacked[/+] on Nov 20, 2026
  2. added
    status:ready
    type:bug
    priority:medium
    area:models
    platform:linux
    on Nov 20, 2026
  3. 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:modelsplatform:linuxpriority:mediumstatus:readytype:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions