Skip to content

Fuse Qwen GDN input projections - #572

Merged
davidkoski merged 4 commits into
ml-explore:mainfrom
aleroot:four_GDN
Aug 28, 2026
Merged

davidkoski merged 4 commits into
ml-explore:mainfrom
aleroot:four_GDN

Conversation

@aleroot

@aleroot aleroot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Proposed changes

Qwen 3.5’s Gated Delta Network currently runs four separate quantized projections over the same input. Each projection starts another GPU operation, adding overhead during text generation.

This PR combines those four projections into one operation and then splits the result into the expected outputs. It applies to both text-only and vision-language Qwen 3.5 models.

The optimization is enabled only when the projections use compatible standard quantization. Models using adapters, custom quantizers, or mixed quantization settings automatically keep the existing path. Checkpoint parameter names remain unchanged.

On my Apple M2 16GB RAM running Qwen3.5-9B-4bit, using alternating same-process comparisons:

  • Prompt processing improved by approximately 3.3%.
  • Token generation improved from 16.62 to 17.39 tokens/second, approximately 4.6%.
  • Both paths generated identical output tokens.

The optimization can be disabled with MLX_QWEN_FOUR_GDN=0 if needed.

Checklist

Comment thread Libraries/MLXLLM/Models/Qwen35.swift Resolved
Comment thread Libraries/MLXLLM/Models/Qwen35.swift Resolved

@davidkoski davidkoski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See questions about mutation.

@davidkoski davidkoski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good -- new prepare lifecycle looks good! Thank you!

@davidkoski
davidkoski merged commit 37688d2 into ml-explore:main Aug 28, 2026
2 of 3 checks passed
djandrewgibbons pushed a commit to djandrewgibbons/mlx-swift-lm that referenced this pull request Sep 1, 2026
* Fuse Qwen GDN input projections
* Move inference preparation to LanguageModel lifecycle
* Use prepare overload for inference lifecycle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants