Skip to content

fix(perf): improve Gemma3n bf16 prefill path - #28

Merged
inureyes merged 1 commit into
mainfrom
fix/gemma3n-bf16-prefill
May 18, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/gemma3n-bf16-prefill

Conversation

@inureyes

@inureyes inureyes commented May 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Materialize full-precision bf16 casts in the Gemma3n prefill path and preserve the language MLP bf16 path so the bf16 build no longer collapses to a much slower mixed graph.
  • Result on M5 Max with gemma-3n-E4B-it (bf16): decode 11.16 → 38.81 tok/s (~3.0x), output stays coherent.

Changes

  • src/models/gemma3n.rs — preserve bf16 along the language MLP, restructure dtype handling in prefill.
  • src/models/sanitize.rs — materialize full-precision bf16 casts where the previous shortcut left tensors in a slow mixed-dtype state.
  • src/loading/vlm.rs, src/models/mod.rs — wiring for the above.

Test plan

  • cargo check --features metal,accelerate
  • Manual: gemma-3n-E4B-it (bf16) decode tok/s on M5 Max matches the reported ~38.8 tok/s.
  • Manual: 4-bit Gemma3n (E2B / E4B) and other Gemma family variants unchanged.

Materialize full-precision bf16 casts and preserve the Gemma3n language MLP bf16 path to improve gemma3n-e4b-bf16 decode from 11.16 to 38.81 tok/s while keeping coherent output.
@inureyes inureyes self-assigned this May 18, 2026
@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions type:performance Performance improvements priority:high High priority area:models Model architectures, weights, loading, metadata labels May 18, 2026
@inureyes
inureyes merged commit ced8d24 into main May 18, 2026
3 checks passed
inureyes added a commit that referenced this pull request May 18, 2026
This release focuses on Apple Silicon decode performance for VLM and linear-attention model families, plus a CLI fix for `mlxcel list`.

Performance:

- Gemma3n bf16 prefill path: gemma3n-e4b-bf16 decode 11.16 to 38.81 tok/s on M5 Max (#28).
- Qwen3-VL text-only decode: QKV fusion + `forward_text_only` fast path. Qwen3-VL-30B-A3B-Instruct-4bit decode 56.00 to 146.29 tok/s (2.61x, 99% of mlx-lm parity); Qwen3-VL-32B-Instruct-4bit decode 18.79 to 27.33 tok/s (1.45x, 94% parity); image-in-prompt and DeepStack paths unchanged (#29).
- GatedDeltaNet fast RMSNorm in Qwen3.5 / Qwen3-Next / KimiLinear: `mlx::fast::rms_norm` replaces the expanded square / mean / sqrt / divide graph for Q/K and gated output. qwen3.5-0.8b-4bit decode 425.16 to 535.43 tok/s on M5 Max (+25.9%, 96% parity); Qwen3.5 speculative-decoding verify pass updated alongside prefill / decode to preserve draft / verify dtype agreement (#30).

Fixed:

- Rewrite `mlxcel list` output to drive from the `ModelType` registry: fixes stale count, missing VLM family, missing ~30 model types, and removes a broken docs link (#27).

Docs:

- Refresh README performance snapshot and `docs/benchmarks.md` to match the latest M5 Max sweep.
@inureyes
inureyes deleted the fix/gemma3n-bf16-prefill branch May 23, 2026 05:57
@inureyes inureyes added this to the 0.1 milestone Jun 21, 2026
sjswerdloff added a commit to sjswerdloff/mlxcel that referenced this pull request Jul 10, 2026
…truction] msa_fetch/fp16_gathered (Clement seat closed: approve, no must-fixes; Xander's seat open at his wake)

Env instruments demote to default seeds; store is single source of
truth at every dispatch site. Runtime msa_core makes the G core axis
boot-free for the morning A/B leg (task lablup#28); construction keys are
boot-frozen with warn-on-divergence. Header echo: path=..; core=..;
v=N. Both gathered cores carry first-dispatch witnesses.

Latch-order property (review note a): init_and_watch's boot-time file
load precedes first dispatch on the server path; TOML-less processes
latch env-seeded defaults at first touch by design.

Verification (sharded per lablup#29 convention, isolated target):
decode_config 26, server::routes 77, m3 50, core cache 480, bins
build. Full-suite SIGTRAP reproduced on BASE without this change —
pre-existing, lablup#29 updated with the datum.
sjswerdloff added a commit to sjswerdloff/mlxcel that referenced this pull request Jul 11, 2026
…, 64GiB server serving; far-side pickup = golden harness with verified preconditions

Co-Authored-By: clement-7074f29f <[email protected]>
sjswerdloff added a commit to sjswerdloff/mlxcel that referenced this pull request Jul 11, 2026
The gate's record (2026-07-11, Violet's verdict 20:06): completions
BIT-IDENTICAL to blocked across kernel schedules at 295K (1,500 greedy
tokens, diff empty), sdpa +3.4–8.1% tok/s. Safe everywhere by
construction — the masked SDPA core consumes fp16 compact windows
regardless of source (fp16-gathered or kvarn-dequanted).

Env instrument keeps switch semantics against the NEW default:
MLXCEL_MSA_CORE=blocked selects the non-default; anything else
(including parse garbage) means sdpa. The two default-pinning tests
flipped WITH the default, deliberately, citing the gate — exactly the
red a default flip owes.

Evidence: decode_config 26/26, msa 29/29, C contracts 2/2 (their
gathered reference now runs the sdpa core live — still 1e-3-matched,
consistent with the gate's bit-identical finding), root lib 1,876
passed / 0 failed before the known lablup#29 teardown SIGTRAP.

Co-Authored-By: clement-7074f29f <[email protected]>
@inureyes inureyes added status:done Completed and removed status:review Under review type:performance Performance improvements labels Sep 6, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
Materialize full-precision bf16 casts and preserve the Gemma3n language MLP bf16 path to improve gemma3n-e4b-bf16 decode from 11.16 to 38.81 tok/s while keeping coherent output.
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
This release focuses on Apple Silicon decode performance for VLM and linear-attention model families, plus a CLI fix for `mlxcel list`.

Performance:

- Gemma3n bf16 prefill path: gemma3n-e4b-bf16 decode 11.16 to 38.81 tok/s on M5 Max (lablup#28).
- Qwen3-VL text-only decode: QKV fusion + `forward_text_only` fast path. Qwen3-VL-30B-A3B-Instruct-4bit decode 56.00 to 146.29 tok/s (2.61x, 99% of mlx-lm parity); Qwen3-VL-32B-Instruct-4bit decode 18.79 to 27.33 tok/s (1.45x, 94% parity); image-in-prompt and DeepStack paths unchanged (lablup#29).
- GatedDeltaNet fast RMSNorm in Qwen3.5 / Qwen3-Next / KimiLinear: `mlx::fast::rms_norm` replaces the expanded square / mean / sqrt / divide graph for Q/K and gated output. qwen3.5-0.8b-4bit decode 425.16 to 535.43 tok/s on M5 Max (+25.9%, 96% parity); Qwen3.5 speculative-decoding verify pass updated alongside prefill / decode to preserve draft / verify dtype agreement (lablup#30).

Fixed:

- Rewrite `mlxcel list` output to drive from the `ModelType` registry: fixes stale count, missing VLM family, missing ~30 model types, and removes a broken docs link (lablup#27).

Docs:

- Refresh README performance snapshot and `docs/benchmarks.md` to match the latest M5 Max sweep.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:models Model architectures, weights, loading, metadata priority:high High priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant