Repository navigation
[WebGPU] Add block-scaled FP8 QMoE #32794
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
Merged
+878
−49
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4596b55
Add WebGPU block-scaled FP8 QMoE
e4b8a5a
Correct WebGPU block-FP8 QMoE dispatch and validation
sayanshaw24 b4ec969
Handle unaligned block-FP8 expert slices and test scale tiles
sayanshaw24 1dd47db
Merge main and regenerate FP8 QMoE operator documentation
sayanshaw24 33bd8e2
Avoid repeated FP8 scale loads and cache dequant LUT
sayanshaw24 f305380
Validate canonical FP8 expert layouts and numerical decoding
sayanshaw24 d436f36
Preserve QMoE source file permissions
sayanshaw24 b68ad95
Cover block-FP8 QMoE separate FC3 decode
sayanshaw24 b3cd79c
Merge remote-tracking branch 'origin/main' into sync-qmoe-fp8-32794
sayanshaw24 a1c04af
Clarify QMoE packed alignment dimensions
sayanshaw24 40cebde
Merge main and guard WebGPU block-FP8 projection addressing
sayanshaw24 09737a3
Reject orphan FP8 FC3 scales and refresh QMoE docs
sayanshaw24 eb51a28
Reject unused activation scales for WebGPU block-FP8 QMoE
sayanshaw24 6030cc6
Merge current main with CUDA GQA build fix
sayanshaw24 fdf7f9d
Merge main with ONNX materialized-node test fix
sayanshaw24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
53 changes: 53 additions & 0 deletions
53
onnxruntime/contrib_ops/webgpu/moe/block_fp8_expert_matmul.wgsl.template
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #use .getByOffset .setByOffset | ||
|
|
||
| #param has_bias | ||
| #param has_indirect_experts | ||
| #param broadcast_input | ||
|
|
||
| $MAIN { | ||
| let row = global_id.y; | ||
| let col = global_id.x; | ||
| if (row >= uniforms.rows || col >= uniforms.cols) { | ||
| return; | ||
| } | ||
|
|
||
| #if has_indirect_experts | ||
| let expert_idx = indirect_experts.getByOffset(row); | ||
| let weight_base = (expert_idx * uniforms.cols + col) * uniforms.inner; | ||
| let scale_base = expert_idx * uniforms.scale_n_blocks * uniforms.scale_k_blocks + | ||
| (col / 128u) * uniforms.scale_k_blocks; | ||
| #else | ||
| let weight_base = uniforms.weight_byte_offset + col * uniforms.inner; | ||
| let scale_base = (col / 128u) * uniforms.scale_k_blocks; | ||
| #endif | ||
| #if broadcast_input | ||
| let input_row = 0u; | ||
| #else | ||
| let input_row = row; | ||
| #endif | ||
|
|
||
| var value = 0.0; | ||
| for (var k_block = 0u; k_block < uniforms.scale_k_blocks; k_block++) { | ||
| let scale = f32(scales.getByOffset(scale_base + k_block)); | ||
| let start = k_block * 128u; | ||
| let end = min(start + 128u, uniforms.inner); | ||
| for (var inner = start; inner < end; inner++) { | ||
| let weight_offset = weight_base + inner; | ||
| let packed_word = u32(weights.getByOffset(weight_offset / 4u)); | ||
| let weight_code = unpack4xU8(packed_word)[weight_offset % 4u]; | ||
| let weight = bitcast<f32>(kFp8DequantLutBits[weight_code]); | ||
| value += f32(input.getByOffset(input_row * uniforms.inner + inner)) * weight * scale; | ||
| } | ||
| } | ||
| #if has_bias | ||
| #if has_indirect_experts | ||
| value += f32(bias.getByOffset(expert_idx * uniforms.cols + col)); | ||
| #else | ||
| value += f32(bias.getByOffset(col)); | ||
| #endif | ||
| #endif | ||
| output.setByOffset(row * uniforms.cols + col, output_element_t(value)); | ||
| } // MAIN | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.