Skip to content

fix(models): load Qwen3.5's float32 GDN tensors in the model dtype - #1

Merged
jason-fxz merged 1 commit into
mainfrom
fix/qwen35-f32-alog
Nov 16, 2026
Merged

jason-fxz merged 1 commit into
mainfrom
fix/qwen35-f32-alog

Conversation

@jason-fxz

@jason-fxz jason-fxz commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Qwen3.5 stores linear_attn.A_log in float32 (the original release also stores linear_attn.norm.weight that way). load_state requires an exact dtype match, so every Qwen3.5 checkpoint except NVIDIA's NVFP4 exports fails to load:

ValueError: model.layers.0.linear_attn.A_log: checkpoint (64,) mlx.core.float32 vs model (64,) mlx.core.bfloat16

Fix

WeightRules.casts names the parameters that load in the model's dtype. load_weights casts float tensors under those names, then runs the strict load_state as before. Only qwen3_5_moe uses it, for A_log and linear_attn.norm.weight.

  • A_log: the cast is lossless. All 16,512 float32 values across 7 Qwen3.5 checkpoints are bf16-exact.
  • linear_attn.norm.weight: rounded to bf16, which is what mlx-lm's own conversions already store.

Now loads

Checked with a header-only dry run (configs plus safetensors headers, zero tensors in place of weights). These 7 repos go from FAIL to PASS, and nothing else changes across 67 candidate repos:

  • Qwen/Qwen3.5-122B-A10B
  • mlx-community/Qwen3.5-{35B-A3B-4bit, 122B-A10B-4bit, 122B-A10B-bf16, 397B-A17B-nvfp4}
  • lmstudio-community/Qwen3.5-397B-A17B-MLX-{4bit, 8bit}

Tested

Apple M4, 24 GB, macOS 15.3.

  • New parity test: float32 and bf16 GDN tensors give bit-identical logits and greedy tokens, in both the MLX and HF layouts. A float32 dt_bias, and an int32 tensor under a cast name, are still refused.
  • uv run pytest tests/ -q (1845 passed, 66 skipped) and uv run pre-commit run --all-files pass.
  • Real load of mlx-community/Qwen3.5-35B-A3B-4bit with ftm serve --model <dir> --max-seq-len 4096:
    • On main, loading fails with the A_log error above.
    • On this branch, the server starts under MoE offload. A greedy chat request returns "The capital of France is Paris." at 29 tok/s decode.

@jason-fxz
jason-fxz merged commit fb33599 into main Nov 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant