Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block sparse MM MoEs #782

Merged
merged 12 commits into from
May 21, 2024
Merged

Block sparse MM MoEs #782

merged 12 commits into from
May 21, 2024

Conversation

angeloskath
Copy link
Member

@angeloskath angeloskath commented May 16, 2024

Implements all MoEs with the new mx.block_sparse_mm and mx.block_sparse_qmm (the latter is at ml-explore/mlx#1124 ).

One notable change is in the quantization predicate which accepts modules that define to_quantized() and delegates the check for the existence of quantized weights to the module using is_quantized(). This allows us to define SwitchMLP for each model and a quantized equivalent and auto convert to the quantized one.

Performance comparison at 4bits

Before

Qwen1.5-MoE-A2.7B-Chat     : 56.3 tps
Mixtral-8x7B-Instruct-v0.1 : 40.3 tps
phixtral-4x2_8             : 47.2 tps

After

Qwen1.5-MoE-A2.7B-Chat     : 121.7 tps
Mixtral-8x7B-Instruct-v0.1 :  59.3 tps
phixtral-4x2_8             :  92.8 tps

@angeloskath
Copy link
Member Author

@awni I think this is ready for a review. I didn't implement the DoRASwitchLinear but it can easily be added in a later PR that also adds quantization to DoRA layers.

Comment on lines 66 to 67
elif isinstance(layer, (SwitchLinear, QuantizedSwitchLinear)):
LoRALayer = LoRASwitchLinear
Copy link
Member

Choose a reason for hiding this comment

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

Should we add use_dora to the condition here? Or throw if trying to DoRA-fy a switch linear layer (until we support Dora)?

Copy link
Member

@awni awni left a comment

Choose a reason for hiding this comment

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

🚀 thanks for fixing the quantized models!

@angeloskath angeloskath merged commit 9f67122 into main May 21, 2024
2 checks passed
@angeloskath angeloskath deleted the block_mask_moe branch May 21, 2024 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants