Add 2-bit quantization support to WebGPU GatherBlockQuantized operator#29074
Open
Shivani767 wants to merge 2 commits into
Open
Add 2-bit quantization support to WebGPU GatherBlockQuantized operator#29074Shivani767 wants to merge 2 commits into
Shivani767 wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends WebGPU-side quantized operator support to include 2-bit weights, primarily by updating the WebGPU GatherBlockQuantized shader generation and relaxing QMoE’s constructor validation to accept 2-bit expert weights.
Changes:
- Add 2-bit extraction and (attempted) signed handling branches in
GatherBlockQuantizedWGSL generation (including 2-bit zero-point sign handling). - Allow
expert_weight_bits == 2in the WebGPUQMoEkernel constructor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| onnxruntime/contrib_ops/webgpu/quantization/gather_block_quantized.cc | Adds 2-bit-specific shader logic for reading packed 2-bit values and adjusts signed zero-point handling logic. |
| onnxruntime/contrib_ops/webgpu/moe/qmoe.h | Expands accepted expert_weight_bits values to include 2-bit in the constructor validation. |
Comment on lines
+77
to
+80
| if (is_signed_) { | ||
| shader.MainFunctionBody() | ||
| << " if((quantized_data & 0x2) != 0) { quantized_data = quantized_data - 4 ;};\n"; | ||
| } |
Comment on lines
+156
to
+162
| if (is_2bit) { | ||
| shader.MainFunctionBody() | ||
| << " if((zero_point & 0x2) != 0) { zero_point = zero_point - 4 ;};\n"; | ||
| } else if (is_4bit) { | ||
| shader.MainFunctionBody() | ||
| << " if((zero_point & 0x8) != 0) { zero_point = zero_point - 16 ;};\n"; | ||
| } |
Comment on lines
+23
to
+24
| ORT_ENFORCE(expert_weight_bits_ == 8 || expert_weight_bits_ == 4 || expert_weight_bits_ == 2, | ||
| "expert_weight_bits must be 2, 4, or 8, but got ", expert_weight_bits_); |
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.
Description
Adds 2‑bit quantization support to two WebGPU operators:
GatherBlockQuantized: Handles signed 2‑bit quantized data (2's complement, range [-2, 1]) and 2‑bit zero points (including when the packed zero point dimension isn't a multiple of 4). Follows the same patterns as the existing CPU implementation and includes WebGPU‑specific test coverage.QMoE: Extends the constructor to acceptexpert_weight_bits_ == 2.Motivation and Context
Resolves #28895! INT2 quantization is a hot research/industry topic for LLM serving, and this support enables using 2‑bit quantized weights with both WebGPU's GatherBlockQuantized and QMoE operators!