Repository navigation
Fused softmax_topk kernel - #2054
Draft
pierreablin wants to merge 1 commit into
Draft
pierreablin wants to merge 1 commit into
pierreablin wants to merge 1 commit into
Conversation
…groups - kernels/softmax_topk.py: the softmax routing after the router matmul (softmax, top-k, optional renormalization) in one kernel, one simdgroup per token, weights in the logits' dtype. - expert_routing takes DeepSeek-V3's group-limited selection: n_group, topk_group, and the score of the masked groups' experts. - 32 models route with them on Metal outside training, each only under the conditions where the kernel computes its routing; otherwise the existing path. On ties at the k-th place the kernels pick the lowest expert index. - Tests: softmax_topk and the groups against mlx ops, a Qwen3-MoE decode step, and 35 MoE blocks against their generic routing.
Contributor
Author
|
re ping @nastya236 ! ;) |
This branch has not been deployed
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.
Independent of Fused Metal kernels for swiglu experts combination, faster single-token MoE experts #2053
kernels/softmax_topk.py: softmax routing after the router matmul (softmax + top-k with an optional renormalization) in one fused kernel.expert_routing now also takes DeepSeek-V3's group-limited selection: n_group, topk_group, and the score of the masked groups' experts.
We use these new kernels for the models that route with them, each only under the conditions where the kernel computes its routing; otherwise we use the previous path. To break ties, the router picks the lowest index expert.
Tests: softmax_topk and the groups against mlx ops, a Qwen3-MoE decode step, and 34 MoE blocks against their generic routing.
LFM2: routing weights are now in float32 instead of bf16 in order to route it through the
expert_routingkernelBenchmark
mlx_lm.benchmark --model <MODEL> -p 128 -g 256 -n 3 -b 1gives the following headlines on m5 ultra:
Headline numbers
mlx-community/Ling-mini-2.0-4bit: 330.8 → 412.3 (1.25×)LiquidAI/LFM2.5-8B-A1B-MLX-4bit: 328.1 → 388.4 (1.18×)mlx-community/Qwen3-30B-A3B-4bit: 156.3 → 166.1 (1.06×)There is also a mild speedup at batch size 8.