feat(mlx-lm): add Qwen3.5 hybrid attention model support - #335
Open
Ogilthorp3 wants to merge 1 commit into
Open
Conversation
Implements the Qwen3.5 architecture — a hybrid model combining Mamba-style linear attention (SSM) with standard full attention (GQA + RoPE) in a 48:16 ratio across 64 layers. Key components: - ModelArgs with nested RopeParameters and layer_types dispatch - LinearAttention: conv1d, SSM discretization (A_log, dt_bias), causal attention with B-scaled weighting, output gating - FullAttention: GQA with partial RoPE (0.25 factor), q/k norms - DecoderLayer enum dispatching between layer types - Quantized weight loading (4-bit affine, group_size=64) - Weight prefix stripping for VL-extracted checkpoints - load_qwen3_5_model / load_qwen3_5_tokenizer functions Tested with Qwen3.5-27B-4bit-text (64 layers, 5120 hidden, 248K vocab). Model loads in ~3s on M4 Pro. SSM scan uses causal attention approximation — full exponential decay recurrence marked TODO for production accuracy. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Adds Qwen3.5 (hybrid Mamba + Transformer) model support to mlx-lm.
Qwen3.5 is a novel architecture mixing linear attention (Mamba-style SSM) with standard full attention (GQA + RoPE) in a 48:16 ratio across 64 layers. This is the first Rust implementation.
Changes
Tested with
Notes
Built for Sanctum — a home AI platform running on Apple Silicon.