Repository navigation
fix(perf): speed up Phi-3.5 SuScaledRoPE decode - #42
Merged
Merged
Conversation
Collapse the Phi-3 / Phi-3.5 longrope (SuScaledRoPE) attention prologue into a single fused bridge call for quantized weights. The new `fused_qkv_project_split_su_scaled_rope` MLX bridge runs the concatenated QKV projection, the Q/K/V split, the reshape and transpose to `[B, H, T, D]`, and the SuScaledRoPE rotation in one shot, replacing the previous chain of separate `slice` / `reshape` / `transpose` / `multiply` / `fast_rope_with_freqs` graph nodes. The per-token allocation and dispatch overhead of that chain dominated decode for these small models. The Rust side keeps a faithful fallback. `Phi3Attention::forward` takes the fused path only when SuScaledRoPE frequencies are present and the fused-QKV weights are quantized, and otherwise routes through the new `prepare_qkv_with_rope`, which preserves the original step-by-step behaviour for regular (non-quantized) weights. SuScaledRoPE semantics are unchanged: both paths scale only the rotary prefix before applying the custom-frequency RoPE, matching mlx-lm / mlx-vlm. On M5 Max the change lifts `phi-3.5-mini-4bit` from 164.03 to 204.63 tok/s decode (79% to 98% of mlx-lm) and the `phi-3.5-vision-4bit` VLM path from 123.07 to 168.77 tok/s (77% to 106% of mlx-vlm), with `phi-3-mini`, `phi-3.5-moe`, and `phi-4` held within measurement noise as guardrails. A short greedy generation on `phi-3.5-mini-4bit` confirms the fused quantized branch still produces coherent text.
inureyes
added a commit
that referenced
this pull request
May 23, 2026
Bump version to 0.0.30. Highlights: unified pre-load memory estimator with the new mlxcel inspect subcommand and --estimate-memory preflight (#64, #65, #66, #67), Molmo v1 and InternVL VLM architectures (#41, #37), Gemma 3n / Phi-3.5 / Gemma / Jamba decode performance work (#42, #43, #44, #60, #62), and server --ctx-size as a shared parallel context budget (#57).
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
Collapse the Phi-3 / Phi-3.5 longrope (SuScaledRoPE) attention prologue into a single fused bridge call for quantized weights. The new `fused_qkv_project_split_su_scaled_rope` MLX bridge runs the concatenated QKV projection, the Q/K/V split, the reshape and transpose to `[B, H, T, D]`, and the SuScaledRoPE rotation in one shot, replacing the previous chain of separate `slice` / `reshape` / `transpose` / `multiply` / `fast_rope_with_freqs` graph nodes. The per-token allocation and dispatch overhead of that chain dominated decode for these small models. The Rust side keeps a faithful fallback. `Phi3Attention::forward` takes the fused path only when SuScaledRoPE frequencies are present and the fused-QKV weights are quantized, and otherwise routes through the new `prepare_qkv_with_rope`, which preserves the original step-by-step behaviour for regular (non-quantized) weights. SuScaledRoPE semantics are unchanged: both paths scale only the rotary prefix before applying the custom-frequency RoPE, matching mlx-lm / mlx-vlm. On M5 Max the change lifts `phi-3.5-mini-4bit` from 164.03 to 204.63 tok/s decode (79% to 98% of mlx-lm) and the `phi-3.5-vision-4bit` VLM path from 123.07 to 168.77 tok/s (77% to 106% of mlx-vlm), with `phi-3-mini`, `phi-3.5-moe`, and `phi-4` held within measurement noise as guardrails. A short greedy generation on `phi-3.5-mini-4bit` confirms the fused quantized branch still produces coherent text.
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
Bump version to 0.0.30. Highlights: unified pre-load memory estimator with the new mlxcel inspect subcommand and --estimate-memory preflight (lablup#64, lablup#65, lablup#66, lablup#67), Molmo v1 and InternVL VLM architectures (lablup#41, lablup#37), Gemma 3n / Phi-3.5 / Gemma / Jamba decode performance work (lablup#42, lablup#43, lablup#44, lablup#60, lablup#62), and server --ctx-size as a shared parallel context budget (lablup#57).
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
Speeds up Phi-3 / Phi-3.5 longrope (SuScaledRoPE) decode by collapsing the attention prologue into a single fused MLX bridge call for quantized weights.
What changed
fused_qkv_project_split_su_scaled_rope(mlx_cxx_bridge.{cpp,h}, exposed viamlxcel-corelib FFI +UnifiedLinear::forward_fused_qkv_split_su_scaled_rope): runs the concatenated QKV projection, Q/K/V split, reshape + transpose to[B, H, T, D], and the SuScaledRoPE rotation in one shot. This replaces the previous chain of separateslice/reshape/transpose/multiply/fast_rope_with_freqsgraph nodes, whose per-token allocation and dispatch overhead dominated decode for these small models.Phi3Attention::forwardtakes the fused path only when SuScaledRoPE frequencies are present and the fused-QKV weights are quantized; otherwise it routes through the extractedprepare_qkv_with_rope, preserving the original step-by-step behaviour for regular (non-quantized) weights. SuScaledRoPE semantics are unchanged — both paths scale only the rotary prefix before the custom-frequency RoPE, matching mlx-lm / mlx-vlm.Benchmarks (M5 Max)
phi-3.5-mini-4bit(text)phi-3.5-vision-4bit(VLM)phi-3-mini,phi-3.5-moe, andphi-4are held within measurement noise as guardrails.Verification
cargo fmt --all -- --checkcleancargo clippy --all-targets --features metal,accelerate -- -D warningsclean (rebuilds the C++ bridge)phi-3.5-mini-4bitproduces coherent text through the new fused quantized branch