Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the QMoE (Quantized Mixture of Experts) operator for WebGPU by introducing a fast path for single-token inference, which avoids GPU-to-CPU data copies and reduces the number of shader dispatches. The optimization achieves approximately 15% improvement in token generation performance for gpt-oss-20b.
Changes:
- Added
weight_index_indirecttensor parameter to enable indirect expert indexing on GPU - Introduced specialized shaders (
gate_1token.wgsl.template,final_mix_1token.wgsl.template) for the 1-token case - Modified all matmul_nbits shader variants to support indirect weight indexing via
has_weight_idx_indirectparameter - Increased max_tokens from 512 to 2048 for better batching performance
- Cleaned up QMoEFinalMixProgram by removing redundant
used_byuniform variable
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/contrib_ops/webgpu/moe/qmoe.cc | Added 1-token optimization path and updated multi-token path |
| onnxruntime/contrib_ops/webgpu/moe/gate_1token.wgsl.template | New shader for computing top-k experts for single token |
| onnxruntime/contrib_ops/webgpu/moe/final_mix_1token.wgsl.template | New shader for mixing expert outputs for single token |
| onnxruntime/contrib_ops/webgpu/moe/gate.wgsl.template | Renamed input from hidden_state to router_logits for clarity |
| onnxruntime/contrib_ops/webgpu/moe/final_mix.wgsl.template | Updated comment to reflect uniform variable changes |
| onnxruntime/contrib_ops/webgpu/quantization/subgroup_matrix_matmul_nbits_apple.wgsl.template | Added support for indirect weight indexing |
| onnxruntime/contrib_ops/webgpu/quantization/matmul_nbits_wide_tile.wgsl.template | Added support for indirect weight indexing |
| onnxruntime/contrib_ops/webgpu/quantization/matmul_nbits.wgsl.template | Added support for indirect weight indexing |
| onnxruntime/contrib_ops/webgpu/quantization/dp4a_matmul_small_m.wgsl.template | Added support for indirect weight indexing |
| onnxruntime/contrib_ops/webgpu/quantization/dp4a_matmul.wgsl.template | Added support for indirect weight indexing |
| onnxruntime/contrib_ops/webgpu/quantization/subgroup_matrix_matmul_nbits.h/cc | Added has_weight_idx_indirect parameter and weight_index_indirect input |
| onnxruntime/contrib_ops/webgpu/quantization/matmul_nbits.h/cc | Added has_weight_idx_indirect parameter and weight_index_indirect input |
| onnxruntime/contrib_ops/webgpu/quantization/dp4a_matmul_nbits.h/cc | Added has_weight_idx_indirect parameter and weight_index_indirect input |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
fs-eire
approved these changes
Feb 26, 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.
avoids gpu -> cpu copy in qmoe and removes 1 of 6 shaders in qmoe.
This improves token generation on gpt-oss-20b by ~15%