Skip to content

[BUG] MLX export/runtime pass transformers-5 rope_parameters to mlx-lm, which ignores it: exported Llama/Qwen2/Gemma run with rope_theta=10000 and no rope scaling #4607

Closed

Description

@Qubitium

Found on main @ 4b65923, CPU only (Linux, mlx-cpu 0.32.4, mlx-lm 0.32.2, transformers 5.22.1).

What is wrong

Any checkpoint that GPT-QModel saves under transformers 5 has its RoPE settings in the transformers-5 layout: config.json holds "rope_parameters": {"rope_theta": ..., "rope_type": "llama3", ...}, with no top-level rope_theta/rope_scaling. The MLX paths pass that config.json to mlx-lm unchanged:

  • GPTQModel.export(..., "mlx"): convert_gptq_to_mlx_weights -> _packed_mlx_weights builds mlx_config = deepcopy(load_config(model_path)) (gptqmodel/utils/mlx.py:340), and auto.py:1255 save_config(mlx_config, ...) writes it out as is;
  • the Apple-Silicon runtime (GPTQModel.load(backend=MLX)) builds the MLX model from the same dict (utils/mlx.py:351, model_args_class.from_dict(mlx_config); the requant path is the same at :623-624).

Most mlx-lm architectures do not read rope_parameters: llama, qwen2, qwen3_moe, gemma2, gemma3_text, phi3, olmo2 and granite only know rope_theta (default 10000) and rope_scaling. Only a few, such as qwen3, understand the nested form. For those models, the exported or loaded MLX model silently runs with rope_theta=10000 and without the Llama-3 / YaRN scaling. That is a different positional encoding from the one the checkpoint was trained with. The packed weights themselves transfer exactly (per-layer dequantized max |dW| = 0), so the error comes entirely from the config.

Repro

Llama-3.2-1B-Instruct-AWQ-bit4-g128-symFasle-descFalse, a GPT-QModel AWQ checkpoint saved with transformers 5.5.3, whose config.json has rope_parameters:

from gptqmodel import GPTQModel
GPTQModel.export(src, "out", "mlx")
from mlx_lm import load
m, _ = load("out"); print(m.args.rope_theta, m.args.rope_scaling)
10000 None                          # checkpoint: rope_theta 500000, rope_type llama3, factor 32

After moving rope_parameters to top-level rope_theta / rope_scaling in the exported config.json (no other change):

500000.0 {'factor': 32.0, 'high_freq_factor': 4.0, 'low_freq_factor': 1.0, 'original_max_position_embeddings': 8192, 'rope_type': 'llama3'}

Logits on a 13-token prompt, fp32 on both sides, compared with the same checkpoint in torch (GPTQModel.load(src, device="cpu", dtype=torch.float32)):

exported as-is (rope_parameters)            max|diff| = 1.73   argmax agreement 0.923
Llama-3.2-1B-Instruct-GPTQ-4bits-gp32
  (config written by transformers 4.57, top-level rope_theta/rope_scaling)  max|diff| = 0.097  argmax 1.000

The error grows with position, because RoPE frequency is the thing that is wrong.

Suggested fix

Before building the MLX model or writing the MLX config.json, normalize the RoPE fields to the layout mlx-lm reads: copy rope_parameters["rope_theta"] to top-level rope_theta, and the remaining non-default rope_parameters to rope_scaling (including per-layer-type dicts such as Gemma's {"full_attention": ..., "sliding_attention": ...}, which need model-specific mapping or a refusal). Keep rope_parameters for the models that read it. Add a test that exports a transformers-5-saved Llama and checks load(out)[0].args.rope_theta.

Severity: high for MLX users. Every Llama/Qwen2/Gemma checkpoint quantized by current GPT-QModel and then exported to MLX, or served by the MLX backend, gets the wrong positional encoding without any error.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions