Skip to content

perf: bf16->f16 quant-scale promotion (#260) regresses bf16-scale quantized model decode ~33-41% on M1 Ultra #289

Closed

Description

@inureyes

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:

  1. Verify whether Apertus-8B-Instruct-2509-4bit and Seed-OSS-36B-Instruct-4bit still produce correct output with the blanket scale promotion removed (xIELU fix kept). If yes, remove convert_quant_scales_bf16_to_f16 entirely.
  2. 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.
  3. 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_f16 on 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

  1. added
    type:performance
    priority:high
    status:ready
    area:models
    area:inference
    platform:macos
    on Jun 15, 2026
  2. added this to the 0.3 milestone on Jun 21, 2026
  3. self-assigned this
    on Jun 21, 2026
  4. added
    status:done
    and removed
    status:ready
    on Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:inferencearea:modelsplatform:macospriority:highstatus:donetype:performance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions