Repository navigation
perf(moe): wire qwen3_vl_moe to the fused decode-MoE kernel - #310
Merged
Merged
Conversation
SparseMoeBlock::forward in qwen3_vl_moe now gates on single-token decode (n_tokens == 1) and fused_moe_enabled(), then delegates to SwitchGLU::forward_fused_kernel (imported from qwen3_moe). The fallback path (experts.forward + moe_weighted_sum) is unchanged for prefill and any unsupported bit-width config. Activation is SwiGLU (act=0); no GeGLU/relu2 template is needed. Updates the 'Models covered' list in the fused-kernel design doc to reflect seven wired model paths, moving qwen3_vl_moe out of the unwired list.
This was referenced Jun 16, 2026
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
Wires
qwen3_vl_moe'sSparseMoeBlock::forwardto the fused single-token decode-MoE kernel, matching the pattern already used byqwen3_moe,qwen3_next,dots1,gemma4,qwen2_moe, andlfm2.What changed
src/models/qwen3_vl_moe.rs: replaced the unconditionalexperts.forward + moe_weighted_sumblock with the gated fused-kernel branch. Whenn_tokens == 1andfused_moe_enabled()returns true, the block callsSwitchGLU::forward_fused_kernel(&x_flat, &topk_indices, &scores)(signature:fn forward_fused_kernel(&self, x: &MlxArray, indices: &MlxArray, scores: &MlxArray) -> Option<UniquePtr<MlxArray>>). The kernel returnsNonefor any unsupported config (non-4/8-bit gate/up, non-4/6/8-bit down, group_size mismatch, or multi-token decode), and thematcharm falls through to the originalforward + moe_weighted_sumpath. Prefill is unaffected. Activation is SwiGLU (act=0); no GeGLU or relu2 template is needed.docs/benchmark_results/fused-moe-decode-kernel-design.md: updated the "Models covered" section, movingqwen3_vl_moefrom the unwired list to the wired list and updating the count from six to seven.Test plan
cargo check --lib --tests --features metal,accelerate: cleancargo clippy --lib --tests --features metal,accelerate -- -D warnings: cleanmlx-community/Qwen3-VL-30B-A3B-4bit(text-only decode, greedy temp-0 parity fused-on vs fused-off, tok/s measurement) is pending orchestrator.Closes #306