Repository navigation
Description
Summary
Commit d80f78721 ("feat(models): add Apertus (xIELU, QK-norm, llama3 RoPE scaling) (#260)") added convert_quant_scales_bf16_to_f16() in src/models/sanitize.rs::load_text_weights, which promotes bf16 .scales/.biases to f16 for all quantized models. This regresses decode throughput by ~33-41% on M1 Ultra for every quantized checkpoint that ships bf16 quant scales, while checkpoints shipping f16 scales are unaffected.
Evidence (M1 Ultra, 128GB, MLX pin a6ec712, decode tok/s)
Confirmed by a control-gated, median-of-3 git bisect (mixtral as a thermal control, since the M1 Ultra throttles under sustained load and naive measurement is noisy). The clean step is at #260:
| commit | qwen3-30b-a3b decode | verdict |
|---|---|---|
0b1606c31 (#257 plamo2) |
71.1 | good |
926f9a45a (#259 granitemoehybrid) |
69.1 | good |
d80f78721 (#260 Apertus) |
44.4 | bad (first) |
Run-over-run (06-12 build efa2c37bd v0.1.4 -> v0.2.1), decode tok/s, all bf16-scale:
- qwen3-30b-a3b 70 -> 47, qwen3-moe 70 -> 47, qwen3-0.6b 290 -> 247, nemotron-h-30b 91 -> 51, nemotron-nas-30b 90 -> 51, plus gpt-oss-120b, solar-open-100b, minimax-m2, hunyuan-large, jamba, dots.llm1.
Controls (f16 scales) unchanged: mixtral-8x7b 54 -> 54, llama-3.1-8b 107 -> 109, qwen2.5-7b 110 -> 112, phi-4, starcoder2.
The split is exactly by scales dtype (safetensors headers): regressed models = BF16 scales; clean models = F16 scales. The one BF16 exception that did NOT regress is gemma-4-26b-a4b, because it also gained the GeGLU fused-MoE kernel (#281) which offsets the regression for that model.
It is not the fused-MoE kernel (MLXCEL_FUSED_MOE on vs off is identical for the affected models) and not an MLX change (pin a6ec712 across the whole range).
Mechanism
For quantized models the promotion converts only .scales/.biases to f16 but leaves embeddings/norms (the compute dtype) bf16. This creates a dtype mismatch (bf16 activations x f16 scales) in quantized_matmul/gather_qmm, forcing per-step conversion on M1 Ultra. Before #260, quantized models were left fully bf16 (the established fast path; the prior code comment noted the quant kernel "handles bf16 natively"). qwen3-30b decoded correctly and fast with bf16 scales before #260, proving bf16 scales are NOT inherently broken.
Fix direction
The #260 PR also fixed a separate xIELU read_scalar bf16 bug, which is the likely real correctness fix for Apertus's blank output. Proposed:
- Verify whether
Apertus-8B-Instruct-2509-4bitandSeed-OSS-36B-Instruct-4bitstill produce correct output with the blanket scale promotion removed (xIELU fix kept). If yes, removeconvert_quant_scales_bf16_to_f16entirely. - If they still need it, either gate the promotion to only those model_types, or (cleaner) convert ALL bf16 tensors to f16 for quantized models (consistent f16 compute path, no mismatch) and confirm it recovers perf without breaking correctness.
- Add a regression guard so a bf16-scale model's decode is checked against its f16-scale-equivalent expectation.
Acceptance Criteria
- Root cause confirmed: dtype mismatch from
convert_quant_scales_bf16_to_f16on bf16-scale quantized models. - Decode throughput on the regressed bf16-scale models recovered to the pre-feat(models): add Apertus (xIELU, QK-norm, llama3 RoPE scaling) #260 baseline (e.g. qwen3-30b-a3b back to ~70 tok/s).
- Apertus and Seed-OSS still produce correct (non-blank) output.
- Greedy temp-0 output unchanged for the previously-unaffected f16-scale controls.
- Regression guard added so a bf16-scale model's decode is checked against its f16-scale-equivalent expectation.
Notes
Environment note: discovered during a full M1 Ultra benchmark refresh (v0.1.4 06-12 -> v0.2.1). Likely affects other Apple Silicon too (the promotion fires on all Apple Silicon), magnitude may differ by generation.
Related: #269 (Apertus/Seed-OSS dense decode gap vs mlx-lm, also touches #260).
Activity
perf(models): keep quantized models bf16 to fix M1 Ultra decode regre…
docs(benchmarks): refresh M1 Ultra + M5 Max for mlxcel 0.2.1 (#295)
docs(readme): refresh text performance tables for v0.3.0
docs(readme): refresh performance tables for v0.3.0
docs(readme): refresh performance tables for v0.3.0 (#300)
fix(sampling): cast selected-token logprob to f32 before item_f32 (#340)
perf(advisor): recommend Turbo KV-cache modes per family and context (#…
perf(models): profile apertus/seed_oss decode and trim xIELU op (#399)
perf(models): keep quantized models bf16 to fix M1 Ultra decode regre…
docs(benchmarks): refresh M1 Ultra + M5 Max for mlxcel 0.2.1 (lablup#295
docs(readme): refresh performance tables for v0.3.0 (lablup#300)
perf(advisor): recommend Turbo KV-cache modes per family and context (l…
perf(models): profile apertus/seed_oss decode and trim xIELU op (labl…