Repository navigation
Description
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
sanitize_gemma4_nvfp4_weightsdoes the per-expert repack; the stacking step and theswitch_glu/switch_mlpfallback live insrc/models/switch_layers.rs(seerefuse_unstacked_expert_sidecarsat:1131and theswitch_mlpfallback around:729-:744).- Layer-0 expert tensor names differ across sources: mlx-lm stores
experts.switch_glu.{gate_proj,up_proj,down_proj}.{weight,scales,biases}each[128, ...]; ModelOpt and compressed-tensors storeexperts.{0..127}.{gate_proj,up_proj,down_proj}.*. - Depends on the per-expert stacking helper of fix(models): keep per-expert NVFP4 tensor scales in the Qwen3.5 MoE stacking #3196 (fix(models): Qwen3.5 MoE NVFP4 stacking drops the per-expert tensor scale, so the export is refused at load #3195).
Acceptance Criteria
nvidia/Gemma-4-26B-A4B-NVFP4andRedHatAI/gemma-4-26B-A4B-it-NVFP4load and answerParis, matchinglmstudio-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_weightsrepacks each of those linears, which leaves 128 planes per projection underexperts.{e}.{proj}with that expert's tensor scale beside each. Nothing stacks them, andSwitchLinear's own fallback for unstacked experts looks under{root}.switch_mlp.{proj}, notswitch_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
[-]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[/+]