Repository navigation
Description
Problem / Background
Two architectures decode at roughly a third of mlx-lm on M5 Max while sitting at parity on M1 Ultra. Decode tok/s from the 2026-09-06 sweeps, with the percentage being mlxcel against mlx-lm on that same machine:
| Checkpoint | Architecture | M1U mlxcel | M1U mlx-lm | M1U | M5 mlxcel | M5 mlx-lm | M5 |
|---|---|---|---|---|---|---|---|
falcon-h1-tiny-90m-instruct-4bit |
FalconH1ForCausalLM | 330.7 | 305.3 | 108% | 160.7 | 520.1 | 31% |
granite-4.0-h-350m-4bit |
GraniteMoeHybridForCausalLM | 266.2 | 264.9 | 100% | 132.6 | 572.9 | 23% |
granite-4.0-h-tiny-4bit |
GraniteMoeHybridForCausalLM | 109.1 | 117.2 | 93% | 76.5 | 235.4 | 33% |
M1 Ultra ran mlxcel 0.7.0-beta.1 at 30ab5a39, M5 Max the same version at a50ff440, both on MLX pin 9a795735, both at pp512/tg128 (512-token synthetic prompt, exactly 128 generated tokens, --ignore-eos), both against same-day mlx-lm 0.31.3 on the same host.
The absolute numbers matter as much as the ratios: mlxcel on M5 Max runs these at roughly half the throughput it reaches on M1 Ultra, on hardware that is otherwise faster. mlx-lm on the same M5 Max is 1.7x to 2.2x faster than mlx-lm on M1 Ultra, which is the expected direction, so the hardware is fine and the runtime is not exploiting it.
Every other SSM or hybrid family is healthy on M5 Max, which is what makes this specific rather than a property of recurrent models:
| Checkpoint | Architecture | M1U | M5 |
|---|---|---|---|
nemotron-h-30b-4bit |
NemotronHForCausalLM | 103% | 100% |
qwen3-next-80b-a3b-instruct-4bit |
Qwen3NextForCausalLM | 118% | 115% |
falcon-mamba-7b-4bit |
FalconMambaForCausalLM | 113% | 101% |
jamba-v0.1-4bit |
JambaForCausalLM | 100% | 98% |
lfm2-350m-8bit |
Lfm2ForCausalLM | 105% | 98% |
Expressed per token, the M5 shortfall is close to a fixed additive cost rather than a proportional slowdown: falcon-h1-tiny-90m-instruct-4bit 6.22 ms/token against mlx-lm's 1.92 (delta 4.30), granite-4.0-h-350m-4bit 7.54 against 1.75 (delta 5.80), granite-4.0-h-tiny-4bit 13.07 against 4.25 (delta 8.82). That shape is what a fixed number of per-layer stalls per decode step looks like, and it is why the smallest checkpoints are hit hardest.
This is not a recent regression. M5 Max decode for these rows has been flat across every sweep back to 0.2.1: falcon-h1-tiny-90m-instruct-4bit 154.84 (2026-06-15) / 154.71 (2026-07-12) / 154.82 (2026-09-03) / 160.70 (2026-09-06), and granite-4.0-h-tiny-4bit 75.14 / 73.19 / 75.05 / 76.54. What is new is the comparison that surfaces it.
Why it went unnoticed. The aggregate hides it. Median mlxcel-against-mlx-lm parity is 100% on both hosts, and the median across all SSM and hybrid checkpoints is 1.61x M5-over-M1, above the 1.43x of everything else. These three only surface when the same-machine ratio is computed on both machines and the two are compared. A cross-hardware table alone reads them as "M1 Ultra is faster on these models", which is the wrong conclusion, and docs/benchmark_results/model_tests.md:90-102 already had to carve them out of its own hardware aggregate for exactly that reason.
Current Behavior
Each SSM mixer forward ends with an M5-gated materialization of its output, one per Mamba layer per decode token:
src/models/falcon_h1.rs:416-423, at the end ofFalconH1Mamba2Mixer::forward.src/models/granitemoehybrid.rs:451-458, at the end of the Granite Mamba2 mixerforward.src/models/plamo2.rs:398-405, same position.src/models/nemotron_h.rs:643-652, same position.
The gate is mlxcel_core::hardware::is_m5_neural_accelerator() (src/lib/mlxcel-core/src/hardware.rs:173, has_neural_accelerator && macos_supports_na). It evaluates false on M1 Ultra, so the eval is skipped there, and true on M5 Max, so the eval runs on every mixer of every decode step. Those four sites are the only callers of is_m5_neural_accelerator() in the tree.
nemotron_h is the control, and it does not behave the same way at runtime. NemotronHMamba2Mixer::forward returns early at src/models/nemotron_h.rs:522-527 into forward_fused (src/models/nemotron_h.rs:900) whenever seq_len == 1 && mlxcel_core::ssm_kernel_available() and both cache states are populated, which is every decode token on a quantized checkpoint. forward_fused calls the single mlxcel_core::fused_mamba2_forward bridge (src/lib/mlxcel-core/src/lib.rs:1865) and returns without reaching the eval at line 650. So nemotron_h's healthy M5 number is explained by that early return, not by the gate that #267 added to it. FalconH1, GraniteMoeHybrid and PLaMo 2 have no equivalent early return: they run the full mixer body and hit the eval on every layer of every token.
Leading hypothesis (unverified)
The M5-side cost of that per-mixer eval is the leading suspect. It is a hypothesis, not a diagnosis: no A/B has been run on M5 Max, and confirming it is the first task.
What supports it:
- Magnitude match. PR perf(models): gate Mamba2 mixer eval boundary to M5 Max #266 measured the same eval, unconditional at the time, costing 3-5x decode on M1 Ultra for these exact files, moving
falcon-h1-tiny-90m57 to 180 tok/s andgranite-4.0-h-tiny36 to 92 tok/s once it was gated off there. The present M5 shortfalls are 3.2x, 4.3x and 3.1x, the same magnitude, on the one machine where the gate leaves the eval on. - The M1 Ultra data controls for the missing fused kernel. FalconH1 and GraniteMoeHybrid reach 93-108% of mlx-lm on M1 Ultra without any
forward_fusedequivalent, so lacking that kernel cannot by itself explain an M5-only collapse. The variable that flips between the two hosts for these two families is the eval gate. - The per-token deltas above are additive and scale with depth rather than with parameter count, which is the signature of a per-layer stall, not of a slower kernel.
Relation to #267. #267 (closed) is the precedent this extends, not a duplicate. PR #266 introduced is_m5_neural_accelerator() and gated the eval in falcon_h1.rs, granitemoehybrid.rs and plamo2.rs; #267 carried the same gate into nemotron_h.rs and analysed its interaction with the needs_chunked_eval / eval_interval path. Both issues were framed as recovering non-M5 throughput, and both left the M5 arm of the gate switched on and unmeasured. This issue is the other half: the eval is still paid in full on M5 Max, on the three families that never gained a fused decode path, and nobody has benchmarked that arm against mlx-lm on M5 hardware. Do not re-litigate the non-M5 side; it is already correct.
What would falsify it. If forcing is_m5_neural_accelerator() to false on M5 leaves decode within noise of the current numbers, the eval is not the cost and the investigation moves to the mixer body itself (conv1d, the ssm_update_kernel call at falcon_h1.rs:613 / granitemoehybrid.rs:645, or the gated RMSNorm) profiled against the same op sequence in mlx-lm.
The A/B that decides it
There is no environment override on the gate, so the A/B is a local, uncommitted edit on an M5 Max host: make is_m5_neural_accelerator() return false at src/lib/mlxcel-core/src/hardware.rs:173, rebuild, and re-measure the three checkpoints. Because those four mixer evals are the function's only callers, that flip isolates exactly this change and nothing else. Record both arms before writing any fix. Expect the arm with the eval disabled to produce NaN or degenerate output on at least some inputs (that is why the boundary exists), so treat it as a measurement, not a candidate patch.
Proposed Solution
Recover the throughput without losing the numerical boundary the eval provides on M5. Three candidate designs, in the order they should be tried, all of which must preserve finite non-degenerate output on M5:
- Amortize the boundary across layers. Materialize once every K mixers instead of every mixer, mirroring the
eval_interval = 8shape already used in thenemotron_hprefill loop (src/models/nemotron_h.rs:1994-1995,2046). Cheapest change, and it directly tests whether the boundary needs to be per-layer or merely periodic. Sweep K and report the throughput-against-correctness curve rather than picking a value silently. - Split the command buffer instead of syncing the host. Per PR perf(models): gate Mamba2 mixer eval boundary to M5 Max #266 the failure the eval prevents is a lazy float32/float16 graph fusing into NaN inside a single Metal command buffer. Capping
MLX_MAX_OPS_PER_BUFFERon M5 would break the buffer without a host round trip.metal_ops_per_buffer_default(src/lib/mlxcel-core/src/hardware.rs:203) currently returnsNonefor M5 and is applied once frommainbyapply_metal_ops_per_buffer_default(hardware.rs:222); an operator-set value always wins. Any change here is process-global, so it must be validated against at least two non-hybrid families for a throughput regression before being made a default. - Give these families the fused decode path. Route single-token decode through
mlxcel_core::fused_mamba2_forwardasnemotron_hdoes. The bridge is already architecture-generic (it takesintermediate_size,conv_dim,conv_kernel_size,num_heads,head_dim,n_groups,ssm_state_size,time_step_min/max,norm_eps,group_size,bitsas parameters), but two divergences block a straight reuse: it takesnorm_weightunconditionally, while Falcon-H1's default (mamba_rms_norm == false) gates withcompiled_swiglu_activationand has no norm at all (src/models/falcon_h1.rs:409-412), and it requires quantizedin_proj/out_proj. This is the largest change and should only be taken if 1 and 2 fail.
Whichever lands, update the // Used by: comment on fused_mamba2_forward and on any shared helper touched, per docs/code-guidelines.md.
Scope
In scope: src/models/falcon_h1.rs and src/models/granitemoehybrid.rs (the two families with measured mlx-lm baselines on both hosts); src/models/plamo2.rs if the same mechanism is confirmed, since it carries the identical construct at plamo2.rs:403 and docs/benchmark_results/model_tests.md:115 records it at 0.81x M5-over-M1 with the same signature but no mlx-lm baseline on either host to place it; src/lib/mlxcel-core/src/hardware.rs if the fix takes the ops-per-buffer route; the CSV and doc updates listed under Acceptance Criteria.
Out of scope: the non-M5 arm of the gate, which #266 and #267 already settled; src/models/nemotron_h.rs, which is at 100% on both hosts and is the control here; forward_fused's panic!("fused_mamba2_forward requires quantized in_proj") on a non-quantized checkpoint, reachable because the guard at nemotron_h.rs:522-527 checks only ssm_kernel_available() and cache population, which is a separate defect and should be filed on its own if confirmed; the dots.llm1 and apertus / seed_oss gaps PR #266 noted in passing.
Implementation Notes
- Reuse.
is_m5_neural_accelerator()stays the gate for anything M5-specific, per CLAUDE.md "Apple Silicon precision". Do not reintroduce acfg(target_arch)test or a second hardware probe. - Constraints. The boundary exists for correctness on M5 NAx kernels, so no design may remove it outright. The non-M5 path must stay exactly as it is: byte-identical greedy output and no new sync on M1 Ultra.
- Edge cases. Prefill (
seq_len > 1) takes a different path from decode in all three files and must be checked separately for both correctness and prefill throughput. A batch greater than 1 and a long generation (well beyond 128 tokens) are where a NaN introduced by a relaxed boundary would first appear, so neither can be skipped.granite-4.0-h-tiny-4bitis a hybrid MoE, so it also exercises the MoE decode path; if a reference diff is needed there, setMLXCEL_FUSED_MOE=0first. - Error handling. A NaN reached through a relaxed boundary is silent: it produces fluent-looking or degenerate text with no error. Assert finiteness of the logits explicitly in the test rather than reading the output.
- Host. This needs an M5 Max. M1 Ultra cannot reproduce it, because the gate is false there and the eval never runs.
Acceptance Criteria
- The A/B above is run on M5 Max and both arms are recorded in the PR, before any fix is written.
-
falcon-h1-tiny-90m-instruct-4bitand bothgranite-4.0-h-*-4bitcheckpoints reach at least 90% of same-day mlx-lm 0.31.3 decode on M5 Max at pp512/tg128, or the PR states the measured ceiling and why it is a ceiling. - M1 Ultra decode for the same three checkpoints is unchanged within run-to-run noise, and greedy temp-0 output there is byte-identical before and after.
- Greedy output on M5 Max is finite and non-degenerate over a generation of at least 512 tokens for every family the PR touches, asserted on the logits rather than judged by reading the text.
- A unit test covers whichever boundary policy replaces the per-mixer eval (the interval selection, the ops-per-buffer default, or the fused dispatch predicate), so a later change cannot silently revert it.
-
cargo test --workspace --profile test-fast --features metal,acceleratepasses, pluscargo clippy --workspace --all-targets -- -D warningsandcargo fmt --all -- --check. - The fix is integrated into the real decode path used by
mlxcel generateandmlxcel-server, not behind an off-by-default flag.
Measurement artifacts that must be updated
No committed CSV may keep a number this fix invalidates.
-
benchmarks/metal_m5max_2026-09-06.csv, rowsfalcon-h1-tiny-90m-instruct-4bit(line 24),granite-4.0-h-350m-4bit(line 60) andgranite-4.0-h-tiny-4bit(line 61), plus theplamo-2-1brow if the fix reaches PLaMo 2. Replaceprefill_ms,prefill_tok_s,decode_ms,decode_tok_sand, in the same edit,dateandmlxcel_commitfor those rows. The per-rowmlxcel_commitanddatecolumns are what mark the build boundary inside the file, so updating a number without updating them is the failure mode to avoid: the file would then mix two builds with nothing distinguishing them. - Any later M5 Max text CSV that exists at fix time and carries those rows, under the same rule.
-
docs/benchmark_results/model_tests_m5max.mdlines 287, 324 and 325, which quote the prefill and decode numbers directly. -
docs/benchmark_results/model_tests.md, section "2. Where that advantage does not carry over" (lines 90-102), whose whole premise is these three rows, and section "3. Machine against machine" (lines 104-116), whose n, median, quartiles and range are computed with these three excluded and whose note onplamo-2-1bat 0.81x becomes answerable once the mechanism is known. - Re-measurement uses the same conditions as the rows it replaces: pp512/tg128,
--cooldown 30 --big-cooldown 30,--ignore-eos(thebench_decode.shdefault), Time Machine stopped for the whole run.
The mlx-lm side does not need re-running: benchmarks/pylm_m5max_2026-09-06.csv is unaffected by this change and the ratios are recomputed against it.
Verification
# All of this runs on the M5 Max host. Stop Time Machine first: tmutil stopbackup
cargo build --release --features metal,accelerate
cargo test --workspace --profile test-fast --features metal,accelerate
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --all -- --check
# Confirm the measured binary is the committed one (a no-op rebuild must do nothing).
cargo build --release --features metal,accelerate 2>&1 | grep -q 'Compiling' && echo 'STALE BINARY' || echo 'binary matches tree'
# Re-measure, one checkpoint per invocation, same conditions as the rows being replaced.
for m in falcon-h1-tiny-90m-instruct-4bit granite-4.0-h-350m-4bit granite-4.0-h-tiny-4bit; do
scripts/bench_decode.sh "./models/$m/" --prompt-tokens 512 --max-tokens 128 \
--cooldown 30 --big-cooldown 30 --suffix m5eval
doneSingle-model mode writes benchmarks/metal_m5max_<date>_m5eval_single_<model>.csv and does not touch the sweep CSV, so copy each fresh row's measured fields, date and mlxcel_commit into benchmarks/metal_m5max_2026-09-06.csv by hand and commit both.
A pass is: the three decode_tok_s values land at or above 90% of the corresponding benchmarks/pylm_m5max_2026-09-06.csv rows (468, 516 and 212 tok/s respectively), with finite logits over a 512-token generation.
Technical Considerations
mlxcel list reports these as FalconH1ForCausalLM and GraniteMoeHybridForCausalLM. The three checkpoints are named exactly as their models/ directories in the CSVs above (falcon-h1-tiny-90m-instruct-4bit, granite-4.0-h-350m-4bit, granite-4.0-h-tiny-4bit); resolve each to its mlx-community id from the M5 Max host's existing models/ tree rather than guessing, and fetch anything missing with ./target/release/mlxcel download. Prior art worth reading before starting: PR #266 for the original M1 Ultra measurement and the NaN mechanism, #267 for the nemotron_h chunked-eval analysis, and docs/benchmark_results/gemma3n-decode-profile-m5max.md (#358) for the earlier M5 finding that larger command buffers are slower there, which bears directly on candidate 2.
Activity
perf(models): drop the M5 per-mixer eval in the Mamba2 hybrids
bench: refresh the three Mamba2 hybrid rows after the eval removal
test(mamba2): report not-applicable instead of a vacuous pass
test(mamba2): keep the M5-only decode tests out of CI
inureyes commentedon Sep 7, 2026
Removing
plamo-2-1bfrom this issue. It was listed as a fourth candidate on my evidence, and the evidence was the wrong kind.The 0.81x I cited is the M5 Max over M1 Ultra ratio of mlxcel against itself. That is a hardware comparison. This issue is about mlxcel falling behind mlx-lm on one machine, which is a different quantity, and the two cannot corroborate each other.
plamo-2-1bhad no mlx-lm row on either host, so there was no runtime comparison to draw on at all, and I used the number that existed instead of the number that was relevant.Measurement since then settles it in both directions. The missing baseline was an environment gap, not a performance one: plamo2's remote code needs
numba, which was absent from.venv-mlxlm, so the model landed asFAIL:warmupon both hosts. With it installed,plamo-2-1bmeasures 86.83 tok/s against mlx-lm's 82.10 on M5 Max at 512/128, which is 106%. Separately, removing the eval boundary fromplamo2.rs:403measures 1.00x, so the code path this issue is about does not cost it anything.So the candidate was wrong twice over, and neither error needed new measurement to catch. The ratio was the wrong axis and could have been read off the column header; the missing baseline was a dependency, and a
FAIL:warmuprow is a statement about the harness environment rather than about mlxcel.plamo2keeps its gate for the reason already in the fix commit: it measures no gain from removal.Adding
numbato the baseline environment is a separate follow-up. The M1 Ultra document records the.venv-mlxlmpackage set, and it will namenumbaonce the plamo2 rows are re-measured there.bench: measure the plamo-2-1b baseline and fold in the M5 hybrid fix
perf(models): drop the ssm_step eval boundary in the Mamba2 hybrids
bench: refresh the three Mamba2 hybrid rows after the eval removal
inureyes commentedon Sep 8, 2026
Fixed on
bench/0.7.0-refresh, which has not merged yet, so theCloses #1685in c07826d has not fired. Closing by hand rather than leaving astatus:readyissue whose numbers no longer reproduce.Two changes did it, both on that branch. c07826d removed the M5-gated
evalafter every Mamba2 mixer, the one this issue describes: on M5 Max with MLX pin 9a795735 it cost 3.31x decode on Falcon-H1 and 2.24x on GraniteMoeHybrid, and greedy output stayed byte-identical without it. bb29d17 then removed two unconditionalevalcalls at the end ofssm_stepthat arrived with the original port in 926f9a4 with no recorded reason. Those only fire on the graph path, which serves prefill and the first token, so they moved prefill and left decode flat, which is what the dispatch atgranitemoehybrid.rs:430predicts.Measured at pp512/tg128 on M5 Max against
benchmarks/pylm_m5max_2026-09-06.csv, decode then prefill, against what this issue records:falcon-h1-tiny-90m-instruct-4bit31% to 115.4% decode, 137.9% prefillgranite-4.0-h-350m-4bit23% to 82.4% decode, 97.5% prefillgranite-4.0-h-tiny-4bit33% to 88.5% decode, 102.3% prefilltests/mamba2_hybrid_decode_finite.rsguards the NaN this issue's workaround was protecting against. Both tests are#[ignore]d because the CI runner pool is M1 and M4, where the guarded failure cannot occur and they would pass vacuously; run them on an M5 host withcargo test --release --features metal,accelerate --test mamba2_hybrid_decode_finite -- --ignored.What remains is a different problem with a different cause, so it belongs in #1713 rather than here. The two Granite rows sit at 82.4% and 88.5% because host graph build is serial with device execution and costs 0.284 and 0.517 ms per token against device steps of 1.790 and 4.247 ms. That is 13.7% and 10.8% of the token, and it is graph size rather than the arithmetic this issue was about: the first decode step builds 9257 graph edges on
granite-4.0-h-tiny-4bitagainst 3207 onqwen3-8b-4bit, at similar layer counts.