Repository navigation
fix(perf): speed up Jamba hybrid decode - #44
Merged
Merged
Conversation
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
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
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).
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 Jamba's hybrid (attention + Mamba) decode along both sublayer paths.
What changed
FusedQKVLinear(loaded viafrom_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 manualrepeat_kvfor GQA — with the nativeattention_from_ptrkernel that handles grouped-query attention internally.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)
jamba-v0.1-4bitRaw 100-token prompt: 215.74 tok/s.
Verification
cargo fmt --all -- --checkcleancargo clippy --all-targets --features metal,accelerate -- -D warningscleanJamba-v0.1-4bitproduces coherent text through the fused attention path and the new single-token Mamba fast path