Skip to content

fix(perf): speed up Jamba hybrid decode - #44

Merged
inureyes merged 1 commit into
mainfrom
fix/jamba-hybrid-decode
May 20, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/jamba-hybrid-decode

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Speeds up Jamba's hybrid (attention + Mamba) decode along both sublayer paths.

What changed

  • Attention: drops the three separate q/k/v projections for a single FusedQKVLinear (loaded via from_weights_separate, since Jamba stores the projections as separate tensors), and replaces the hand-rolled SDPA — explicit transpose, matmul, scale, mask-add, softmax, matmul, plus a manual repeat_kv for GQA — with the native attention_from_ptr kernel that handles grouped-query attention internally.
  • Mamba mixer single-token fast path: for seq_len == 1 (decode) it now does the selective-state update and output projection directly on the squeezed tensors, skipping the general sequential scan loop that had been doing per-timestep bookkeeping for a single step.

Benchmarks (M5 Max)

Model Before After vs mlx-lm
jamba-v0.1-4bit 182.50 215.84 tok/s 83% → 98%

Raw 100-token prompt: 215.74 tok/s.

Verification

  • cargo fmt --all -- --check clean
  • cargo clippy --all-targets --features metal,accelerate -- -D warnings clean
  • Greedy generation on Jamba-v0.1-4bit produces coherent text through the fused attention path and the new single-token Mamba fast path

Speed up Jamba's hybrid (attention + Mamba) decode along both sublayer paths.

The attention block drops its three separate q/k/v projections in favour of a single `FusedQKVLinear` (loaded via `from_weights_separate`, since Jamba stores the projections as separate tensors), and replaces the hand-rolled scaled-dot-product attention — explicit transpose, matmul, scale, mask-add, softmax, matmul, plus a manual `repeat_kv` for GQA — with the native `attention_from_ptr` kernel, which handles grouped-query attention internally.

The Mamba mixer gains a single-token fast path. For `seq_len == 1` (the decode case) it now performs the selective-state update and output projection directly on the squeezed tensors instead of running the general sequential scan loop, which had been doing per-timestep bookkeeping for a single step.

On M5 Max this lifts `jamba-v0.1-4bit` from 182.50 to 215.84 tok/s decode (83% to 98% of mlx-lm), with the raw 100-token prompt at 215.74 tok/s. A greedy generation on `Jamba-v0.1-4bit` confirms the fused attention path and the new single-token Mamba path still produce coherent text.
@inureyes inureyes added type:performance Performance improvements area:core mlxcel-core: MLX FFI, primitives, KV cache, layers area:models Model architectures, weights, loading, metadata labels May 20, 2026
@inureyes
inureyes merged commit 9b0af86 into main May 20, 2026
3 checks passed
@inureyes
inureyes deleted the fix/jamba-hybrid-decode branch May 20, 2026 15:56
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).
@inureyes inureyes added this to the 0.1 milestone Jun 21, 2026
@inureyes inureyes self-assigned this Aug 31, 2026
@inureyes inureyes added the status:done Completed label Sep 6, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
Speed up Jamba's hybrid (attention + Mamba) decode along both sublayer paths.

The attention block drops its three separate q/k/v projections in favour of a single `FusedQKVLinear` (loaded via `from_weights_separate`, since Jamba stores the projections as separate tensors), and replaces the hand-rolled scaled-dot-product attention — explicit transpose, matmul, scale, mask-add, softmax, matmul, plus a manual `repeat_kv` for GQA — with the native `attention_from_ptr` kernel, which handles grouped-query attention internally.

The Mamba mixer gains a single-token fast path. For `seq_len == 1` (the decode case) it now performs the selective-state update and output projection directly on the squeezed tensors instead of running the general sequential scan loop, which had been doing per-timestep bookkeeping for a single step.

On M5 Max this lifts `jamba-v0.1-4bit` from 182.50 to 215.84 tok/s decode (83% to 98% of mlx-lm), with the raw 100-token prompt at 215.74 tok/s. A greedy generation on `Jamba-v0.1-4bit` confirms the fused attention path and the new single-token Mamba path still produce 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers area:models Model architectures, weights, loading, metadata status:done Completed type:performance Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant