You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Regression from #4617: MLX export/load of every Gemma 3 model now raises (per-layer rope_parameters rejected), although mlx-lm gemma3_text reads rope_theta + rope_local_base_freq #4678
Found on main @ 12c1273 (host-independent config path; Linux, transformers 5.22, mlx-lm 0.32.2 source).
What is wrong
#4617 (fix for #4607) added gptqmodel/utils/mlx_rope.py::normalize_mlx_rope_config, which runs before every MLX export, requant, and backend=MLX load (utils/mlx.py:341, :624, via _mlx_model_config). For per-layer-type rope_parameters, _flatten_rope_parameters collapses them only when every layer type has the same values. Otherwise it raisesValueError: ... per-layer-type RoPE parameters that mlx-lm cannot represent.
That is exactly the layout of every Gemma 3 checkpoint: sliding_attention uses theta 10 000 and full_attention uses theta 1 000 000 (4B and larger also put linear scaling on full_attention). mlx-lm can represent it. mlx_lm/models/gemma3_text.pyModelArgs has:
rope_theta: float=1_000_000.0# global / full-attention layersrope_local_base_freq: float=10_000.0# sliding-window layersrope_scaling: Dict=None# applied to the global rope only
and builds the sliding layers with base=args.rope_local_base_freq and the full layers with base=args.rope_theta, scaling_config=args.rope_scaling.
So #4617 turns Gemma 3 MLX export and MLX load into a hard error. Before #4617, gemma-3-1b-it got the right encoding through mlx-lm's defaults (1e6 / 1e4, no scaling). Only the 4B+ models were wrong, because they lost the full_attention linear factor 8. Now none of them can be exported. The per-layer test (tests/test_mlx_rope_parameters_4607.py::test_conflicting_per_layer_rope_parameters_are_rejected) uses model_type="gemma3_text" and asserts the rejection, so the regression is pinned by a test.
gemma3_text {'sliding_attention': {'rope_type': 'default', 'rope_theta': 10000}, 'full_attention': {'rope_type': 'default', 'rope_theta': 1000000}}
ValueError: MLX: `gemma3_text` uses per-layer-type RoPE parameters that mlx-lm cannot represent; refusing to export a config that would silently fall back to rope_theta=10000. Got ['full_attention', 'sliding_attention'].
_mlx_model_config is the first thing GPTQModel.export(..., "mlx") and the MLX loader do with the config, so a quantized Gemma 3 checkpoint can no longer reach MLX at all. The same rejection applies to model_type="gemma3" VLM configs through the text_config recursion. Llama-3.2, Qwen2.5 and Phi-3.5 configs translate correctly; I checked those with the same function.
Suggested fix
Map per-layer-type RoPE per architecture instead of refusing it:
gemma3_text / gemma3 text_config: rope_theta = full_attention.rope_theta, rope_local_base_freq = sliding_attention.rope_theta, rope_scaling = full_attention minus rope_theta, only when non-default (for example {"rope_type": "linear", "factor": 8.0} on 4B+). Reject only if sliding_attention has scaling, which mlx-lm cannot express.
Keep the refusal for architectures that have no local/global split.
Update test_conflicting_per_layer_rope_parameters_are_rejected to use a model type without such a mapping. Add a gemma-3 1B / 4B config fixture that checks rope_theta, rope_local_base_freq and rope_scaling.
Severity
Medium-high: a regression that makes MLX export and MLX serving of a whole supported family (Gemma 3) fail. Before #4617 the 1B model worked correctly.
Claimed. Investigating the #4617 regression: per-layer-type RoPE for Gemma 3 should map to mlx-lm's rope_theta / rope_local_base_freq rather than being refused. Fix PR to follow.
Claiming this. Confirmed on 7395b40e0: _mlx_model_config({"model_type": "gemma3_text", ...}) raises ValueError: ... per-layer-type RoPE parameters that mlx-lm cannot represent, so MLX export and backend=MLX load of every Gemma 3 checkpoint fail before any weights are written.
Scope of the fix I'm taking:
gptqmodel/utils/mlx_rope.py: add an explicit per-architecture table mapping a per-layer-type rotary split onto the keys the target mlx-lm ModelArgs actually reads, instead of refusing every split. gemma3_text and gemma3n_text map to rope_theta (global/full-attention), rope_local_base_freq (sliding-attention) and rope_scaling (global only). Keep the refusal for a sliding-attention scaling config, which mlx-lm builds from a bare rope_local_base_freq and cannot represent, and for layer-type keys a mapping does not cover.
gemma4_text also emits per-layer-type rope_parameters in transformers 5 and is a second instance of this regression: mlx-lm's gemma4_text.ModelArgs reads rope_parameters[layer_key] natively, so it must be added to the native-passthrough set rather than flattened.
Tests: replace the gemma3_text fixture that pins the rejection with one that pins the mapping, add Gemma 3 1B (no scaling) and 4B+ (full_attention linear factor 8) fixtures, a gemma3n text_config case, a sliding-attention-scaling rejection, and a gemma4_text passthrough case. Red evidence is the current ValueError; green evidence is the consumer-level assertion that an mlx-lm-shaped ModelArgs receives rope_theta=1e6 / rope_local_base_freq=1e4.
Also auditing the other recently-closed MLX reports against 7395b40e0 so this pass does not leave a second incomplete kernel fix behind: #4548's beta boundary correction is present in mlx_foem (_apply_group_boundary_beta), and #4537's FP32 input narrowing is gone (_quantization_dtype keeps fp32). I'll report if either is only partially wired.
gemma3_text, gemma3n_text and gemma4_text are the only three architectures transformers 5.17 emits a per-layer-type split for, so this covers the family rather than just the reported one. The refusal still fires for a sliding-attention scaling entry (mlx-lm builds those layers from a bare rope_local_base_freq) and for any layer-type key a mapping does not cover.
Red evidence: with only gptqmodel/utils/mlx_rope.py reverted, pytest tests/test_mlx_rope_parameters_4607.py -q → 8 failed, 11 passed, every failure the _flatten_rope_parameters per-layer ValueError from the repro. Green: 19 passed, including an assertion against the real mlx_lm.models.gemma3_text.ModelArgs (rope_theta=1e6, rope_local_base_freq=1e4, rope_scaling={'rope_type': 'linear', 'factor': 8.0}).
Follow-up on the other closed MLX reports, as promised: #4548's boundary beta correction is wired in mlx_foem and its dedicated suite (test_mlx_foem_block_boundary_4548.py) passes; #4537's FP32 narrowing is gone and test_mlx_qqq_dtype_decision_4221.py passes; #4534's wide epilogue is covered by test_mlx_qqq_wide_epilogue_4534.py and passes (fp16 and bf16). No further incomplete kernel fix found.
Activity
Qubitium commentedon Nov 17, 2026
Claimed. Investigating the #4617 regression: per-layer-type RoPE for Gemma 3 should map to mlx-lm's
rope_theta/rope_local_base_freqrather than being refused. Fix PR to follow.Qubitium commentedon Nov 17, 2026
Claiming this. Confirmed on
7395b40e0:_mlx_model_config({"model_type": "gemma3_text", ...})raisesValueError: ... per-layer-type RoPE parameters that mlx-lm cannot represent, so MLX export andbackend=MLXload of every Gemma 3 checkpoint fail before any weights are written.Scope of the fix I'm taking:
gptqmodel/utils/mlx_rope.py: add an explicit per-architecture table mapping a per-layer-type rotary split onto the keys the target mlx-lmModelArgsactually reads, instead of refusing every split.gemma3_textandgemma3n_textmap torope_theta(global/full-attention),rope_local_base_freq(sliding-attention) andrope_scaling(global only). Keep the refusal for a sliding-attention scaling config, which mlx-lm builds from a barerope_local_base_freqand cannot represent, and for layer-type keys a mapping does not cover.gemma4_textalso emits per-layer-typerope_parametersin transformers 5 and is a second instance of this regression: mlx-lm'sgemma4_text.ModelArgsreadsrope_parameters[layer_key]natively, so it must be added to the native-passthrough set rather than flattened.gemma3_textfixture that pins the rejection with one that pins the mapping, add Gemma 3 1B (no scaling) and 4B+ (full_attentionlinear factor 8) fixtures, agemma3ntext_config case, a sliding-attention-scaling rejection, and agemma4_textpassthrough case. Red evidence is the currentValueError; green evidence is the consumer-level assertion that an mlx-lm-shapedModelArgsreceivesrope_theta=1e6/rope_local_base_freq=1e4.Also auditing the other recently-closed MLX reports against
7395b40e0so this pass does not leave a second incomplete kernel fix behind: #4548'sbetaboundary correction is present inmlx_foem(_apply_group_boundary_beta), and #4537's FP32 input narrowing is gone (_quantization_dtypekeeps fp32). I'll report if either is only partially wired.Qubitium commentedon Nov 17, 2026
Fix is up: #4684.
Mapping as described above, plus the second instance I found while auditing transformers 5's per-layer-type emitters:
model_typegemma3_textValueErrorrope_theta= full theta,rope_local_base_freq= sliding theta,rope_scaling= full scaling (4B+ keeps linear ×8)gemma3n_textValueErrortext_configrecursiongemma4_textValueErrorrope_parameters[layer_key]itselfgemma3_text,gemma3n_textandgemma4_textare the only three architectures transformers 5.17 emits a per-layer-type split for, so this covers the family rather than just the reported one. The refusal still fires for a sliding-attention scaling entry (mlx-lm builds those layers from a barerope_local_base_freq) and for any layer-type key a mapping does not cover.Red evidence: with only
gptqmodel/utils/mlx_rope.pyreverted,pytest tests/test_mlx_rope_parameters_4607.py -q→ 8 failed, 11 passed, every failure the_flatten_rope_parametersper-layerValueErrorfrom the repro. Green: 19 passed, including an assertion against the realmlx_lm.models.gemma3_text.ModelArgs(rope_theta=1e6,rope_local_base_freq=1e4,rope_scaling={'rope_type': 'linear', 'factor': 8.0}).Follow-up on the other closed MLX reports, as promised: #4548's boundary
betacorrection is wired inmlx_foemand its dedicated suite (test_mlx_foem_block_boundary_4548.py) passes; #4537's FP32 narrowing is gone andtest_mlx_qqq_dtype_decision_4221.pypasses; #4534's wide epilogue is covered bytest_mlx_qqq_wide_epilogue_4534.pyand passes (fp16 and bf16). No further incomplete kernel fix found.fix(mlx): map per-layer-type RoPE onto mlx-lm's local/global pair (#4678