Repository navigation
perf(models): keep quantized models bf16 to fix M1 Ultra decode regression (#289) - #290
Merged
Merged
Conversation
…ssion (#289) #260 added a blanket bf16->f16 promotion of quant scales/biases for all quantized models (convert_quant_scales_bf16_to_f16 in load_text_weights). Promoting only the scales while activations stay bf16 creates a bf16-activation x f16-scale dtype mismatch in quantized_matmul/gather_qmm that regressed decode 33-41% on M1 Ultra for every bf16-scale checkpoint: qwen3-30b-a3b 70->46, nemotron-h 91->53, plus qwen3-0.6b, gpt-oss-120b, solar-100b, minimax, hunyuan-large, jamba, dots. f16-scale checkpoints (mixtral, llama-3.1, qwen2.5, phi-4) were unaffected. Bisected to d80f787 (#260); not the fused-MoE kernel and not the MLX pin. The promotion was unnecessary for correctness. Apertus-2509 and Seed-OSS decode correctly with bf16 scales; the blank output once attributed to their bf16 scales was the separate xIELU read_scalar bf16 bug, fixed in the apertus loader. Promoting every tensor to f16 instead corrupts Apertus (xIELU x^2 overflows f16, like BitNet's relu^2). Leave quantized models fully bf16 (the pre-#260 fast path). On M1 Ultra this restores qwen3-30b-a3b to ~84 and nemotron-h to ~92 tok/s; the apertus_parity real-model test still passes and Seed-OSS / dots.llm1 / granite hybrid / lfm2 decode correctly. Also reflow a doc comment in granitemoehybrid_tests.rs so a wrapped '+' is not at a line start (pre-existing clippy::doc_lazy_continuation under --all-targets; unrelated to the fix, needed for a green lint gate).
7 tasks
inureyes
added a commit
that referenced
this pull request
Jun 15, 2026
Full M1 Ultra + M5 Max text/VLM re-benchmark on mlxcel 0.2.1 (post #289 bf16-scale fix and #291 quantized-embedding fix). Regenerates model_tests_m1ultra.md, model_tests_m5max.md, and the shared cross-hardware index from the new CSVs; adds the 2026-06-15 M1 Ultra and M5 Max CSVs plus the pre-#290 regression-evidence sweep. Both Apple Silicon now on 0.2.1 + MLX pin a6ec712; M5 Max ~1.76x faster than M1 Ultra (avg) on the selected rows.
8 tasks done
inureyes
added a commit
that referenced
this pull request
Jun 22, 2026
Characterizes the per-model dense decode overhead for apertus and seed_oss versus mlx-lm and recovers the one cheap, bit-exact lever found, satisfying the acceptance criteria for #269. Characterization (M1 Ultra, mlxcel-bench-decode warmup harness, temp-0, --no-chat-template, 100 decode tokens, mlx-lm 0.31.3 baselines from the issue). The bulk of the gap reported in #269 was the bf16-scale quantized decode regression (#289), which was fixed by #290 after this issue was filed. Both families ship bf16 quant scales and were in the regressed set, so current main already closes most of the gap: apertus is ~83.5 tok/s vs mlx-lm ~85 (~0.98x, was 0.83x at filing) and seed_oss is ~20.4 tok/s vs mlx-lm ~20.3 (~1.0x, was 0.84x at filing). The remaining apertus delta is diffuse per-op / kernel-launch overhead with no single high-value host-side lever: MLXCEL_PROFILE_FORWARD shows steady-state decode is GPU-eval-bound (~0.7ms host graph-build vs ~13ms GPU eval per token, host build is ~5% of the step), and MLXCEL_PROFILE_BLOCKS attributes the forced-serialized per-layer time as attn ~45% / xIELU MLP ~55% for apertus and attn ~38% / SwiGLU MLP ~62% for seed_oss. seed_oss is a vanilla Llama dense and carries no model-specific lever beyond what #290 already recovered. Adds an env-gated, default-off forward profiling hook to apertus and seed_oss, mirroring the existing hooks in nemotron_h.rs and qwen3_moe.rs. MLXCEL_PROFILE_BLOCKS attributes single-token decode wall-clock to the attention vs MLP sub-blocks; MLXCEL_PROFILE_FORWARD splits the step into graph-build vs GPU-eval. Both flags are read once and cached in a OnceLock, and array_shape is only queried when a flag is set, so the steady-state decode path is unchanged (two atomic loads per token, no extra FFI calls or eval()). Recovers one cheap, bit-exact op in apertus xIELU: both branches end in `+ beta * x`, so that shared term is now added once after the per-element select instead of inside each branch. This drops one elementwise add (and its kernel launch) per layer per token. The select only chooses which value beta*x is added to, so the arithmetic is unchanged. Verified greedy temp-0 output is byte-identical to the pre-change baseline for both apertus (500 bytes) and seed_oss (308 bytes); the decode delta is within run-to-run noise (~83.3 -> ~83.5 tok/s on apertus), consistent with the GPU-eval-bound profile. A fused/compiled xIELU activation (single kernel over the elementwise graph) is the only remaining real lever and is left as a documented follow-up, since it touches the C++ FFI bridge and risks f16 jitter. Adds a CPU-only unit test (xielu_factored_beta_x_matches_branch_local) asserting the factored form equals the branch-local reference bit-for-bit in f32 across positive, negative, and zero inputs.
This was referenced Jun 23, 2026
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
…ssion (lablup#289) (lablup#290) lablup#260 added a blanket bf16->f16 promotion of quant scales/biases for all quantized models (convert_quant_scales_bf16_to_f16 in load_text_weights). Promoting only the scales while activations stay bf16 creates a bf16-activation x f16-scale dtype mismatch in quantized_matmul/gather_qmm that regressed decode 33-41% on M1 Ultra for every bf16-scale checkpoint: qwen3-30b-a3b 70->46, nemotron-h 91->53, plus qwen3-0.6b, gpt-oss-120b, solar-100b, minimax, hunyuan-large, jamba, dots. f16-scale checkpoints (mixtral, llama-3.1, qwen2.5, phi-4) were unaffected. Bisected to d80f787 (lablup#260); not the fused-MoE kernel and not the MLX pin. The promotion was unnecessary for correctness. Apertus-2509 and Seed-OSS decode correctly with bf16 scales; the blank output once attributed to their bf16 scales was the separate xIELU read_scalar bf16 bug, fixed in the apertus loader. Promoting every tensor to f16 instead corrupts Apertus (xIELU x^2 overflows f16, like BitNet's relu^2). Leave quantized models fully bf16 (the pre-lablup#260 fast path). On M1 Ultra this restores qwen3-30b-a3b to ~84 and nemotron-h to ~92 tok/s; the apertus_parity real-model test still passes and Seed-OSS / dots.llm1 / granite hybrid / lfm2 decode correctly. Also reflow a doc comment in granitemoehybrid_tests.rs so a wrapped '+' is not at a line start (pre-existing clippy::doc_lazy_continuation under --all-targets; unrelated to the fix, needed for a green lint gate).
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
) Full M1 Ultra + M5 Max text/VLM re-benchmark on mlxcel 0.2.1 (post lablup#289 bf16-scale fix and lablup#291 quantized-embedding fix). Regenerates model_tests_m1ultra.md, model_tests_m5max.md, and the shared cross-hardware index from the new CSVs; adds the 2026-06-15 M1 Ultra and M5 Max CSVs plus the pre-lablup#290 regression-evidence sweep. Both Apple Silicon now on 0.2.1 + MLX pin a6ec712; M5 Max ~1.76x faster than M1 Ultra (avg) on the selected rows.
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
…up#399) Characterizes the per-model dense decode overhead for apertus and seed_oss versus mlx-lm and recovers the one cheap, bit-exact lever found, satisfying the acceptance criteria for lablup#269. Characterization (M1 Ultra, mlxcel-bench-decode warmup harness, temp-0, --no-chat-template, 100 decode tokens, mlx-lm 0.31.3 baselines from the issue). The bulk of the gap reported in lablup#269 was the bf16-scale quantized decode regression (lablup#289), which was fixed by lablup#290 after this issue was filed. Both families ship bf16 quant scales and were in the regressed set, so current main already closes most of the gap: apertus is ~83.5 tok/s vs mlx-lm ~85 (~0.98x, was 0.83x at filing) and seed_oss is ~20.4 tok/s vs mlx-lm ~20.3 (~1.0x, was 0.84x at filing). The remaining apertus delta is diffuse per-op / kernel-launch overhead with no single high-value host-side lever: MLXCEL_PROFILE_FORWARD shows steady-state decode is GPU-eval-bound (~0.7ms host graph-build vs ~13ms GPU eval per token, host build is ~5% of the step), and MLXCEL_PROFILE_BLOCKS attributes the forced-serialized per-layer time as attn ~45% / xIELU MLP ~55% for apertus and attn ~38% / SwiGLU MLP ~62% for seed_oss. seed_oss is a vanilla Llama dense and carries no model-specific lever beyond what lablup#290 already recovered. Adds an env-gated, default-off forward profiling hook to apertus and seed_oss, mirroring the existing hooks in nemotron_h.rs and qwen3_moe.rs. MLXCEL_PROFILE_BLOCKS attributes single-token decode wall-clock to the attention vs MLP sub-blocks; MLXCEL_PROFILE_FORWARD splits the step into graph-build vs GPU-eval. Both flags are read once and cached in a OnceLock, and array_shape is only queried when a flag is set, so the steady-state decode path is unchanged (two atomic loads per token, no extra FFI calls or eval()). Recovers one cheap, bit-exact op in apertus xIELU: both branches end in `+ beta * x`, so that shared term is now added once after the per-element select instead of inside each branch. This drops one elementwise add (and its kernel launch) per layer per token. The select only chooses which value beta*x is added to, so the arithmetic is unchanged. Verified greedy temp-0 output is byte-identical to the pre-change baseline for both apertus (500 bytes) and seed_oss (308 bytes); the decode delta is within run-to-run noise (~83.3 -> ~83.5 tok/s on apertus), consistent with the GPU-eval-bound profile. A fused/compiled xIELU activation (single kernel over the elementwise graph) is the only remaining real lever and is left as a documented follow-up, since it touches the C++ FFI bridge and risks f16 jitter. Adds a CPU-only unit test (xielu_factored_beta_x_matches_branch_local) asserting the factored form equals the branch-local reference bit-for-bit in f32 across positive, negative, and zero inputs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #289. The full M1 Ultra benchmark refresh (v0.1.4 → v0.2.1) surfaced a real, model-specific decode regression. Root cause: commit
d80f78721(#260 "add Apertus") addedconvert_quant_scales_bf16_to_f16inload_text_weights, which promotes bf16.scales/.biases→ f16 for all quantized models. Promoting only the scales while activations stay bf16 creates a bf16-activation × f16-scale dtype mismatch inquantized_matmul/gather_qmm, regressing decode 33-41% on M1 Ultra for every checkpoint shipping bf16 scales.Evidence (M1 Ultra, decode tok/s)
Control-gated, median-of-3 bisect (mixtral as a thermal control; M1 Ultra throttles under sustained load) — clean step at #260:
926f9a45a(#259)d80f78721(#260)Run-over-run regressions (all bf16-scale): qwen3-30b-a3b 70→46, qwen3-moe 70→46, qwen3-0.6b 290→247, nemotron-h 91→53, nemotron-nas 90→51, gpt-oss-120b, solar-100b, minimax-m2, hunyuan-large, jamba, dots.llm1. Controls (f16 scales) unchanged: mixtral 54→54, llama-3.1-8b 107→109, qwen2.5-7b 110→112, phi-4, starcoder2. The split matches the safetensors
.scalesdtype exactly. Not the fused-MoE kernel (MLXCEL_FUSED_MOEon/off identical) and not MLX (pin a6ec712 across the range).Fix
Leave quantized models fully bf16 (the pre-#260 fast path). The promotion was not needed for correctness:
read_scalarbf16 bug, fixed in the apertus loader (kept).Validation (M1 Ultra, this branch)
tests/apertus_parity.rs(real-model greedy " Paris,") passes; Seed-OSS, dots.llm1, granite-4.0-h hybrid, and lfm2 decode correctly under the fix.cargo fmt --check,cargo clippy --release --all-targets -- -D warnings, andcargo test --release --lib sanitize(83 passed) all green.Notes
granitemoehybrid_tests.rsso a wrapped+is not at a line start (pre-existingclippy::doc_lazy_continuationsurfaced by--all-targets; unrelated to the fix, included to keep the lint gate green).