-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[WebGPU] Support 2-bit quantization in GatherBlockQuantized #28895
Copy link
Copy link
Closed
Labels
ep:WebGPUort-web webgpu providerort-web webgpu providerplatform:mobileissues related to ONNX Runtime mobile; typically submitted using templateissues related to ONNX Runtime mobile; typically submitted using templateplatform:webissues related to ONNX Runtime web; typically submitted using templateissues related to ONNX Runtime web; typically submitted using templatequantizationissues related to quantizationissues related to quantizationstaleissues that have not been addressed in a while; categorized by a botissues that have not been addressed in a while; categorized by a bot
Description
Activity
Metadata
Metadata
Assignees
Labels
ep:WebGPUort-web webgpu providerort-web webgpu providerplatform:mobileissues related to ONNX Runtime mobile; typically submitted using templateissues related to ONNX Runtime mobile; typically submitted using templateplatform:webissues related to ONNX Runtime web; typically submitted using templateissues related to ONNX Runtime web; typically submitted using templatequantizationissues related to quantizationissues related to quantizationstaleissues that have not been addressed in a while; categorized by a botissues that have not been addressed in a while; categorized by a bot
Describe the feature request
The
GatherBlockQuantizedop in the WebGPU backend currently only supports 4-bit and 8-bit quantization. Attempting to run a model with 2-bit weights fails with:Motivation
Google recently released Gemma 4 QAT checkpoints — Quantization-Aware Training models that use 2-bit weights while maintaining near-original quality. The
onnx-communityhas already exported these as ONNX:onnx-community/gemma-4-E4B-it-qat-mobile-ONNXonnx-community/gemma-4-E2B-it-qat-mobile-ONNXThese models are specifically designed for on-device / edge inference and would be a great fit for browser-based ML via WebGPU + transformers.js. However, they can't run because the WebGPU backend rejects the 2-bit weight format.
For context, I'm building Eloquent — an on-device AI dictation app that runs Gemma 4 entirely in the browser using transformers.js + WebGPU. The current
q4f16models work great, but they're ~4.9 GB for the E4B variant. The QAT 2-bit models would cut that roughly in half while preserving quality, which is a huge deal for browser-based inference where every MB matters.What I've tried
dtype: "q2f16"via transformers.js → fails with the error aboveSuggested behavior
Extend
GatherBlockQuantized(and any other affected ops) in the WebGPU backend to supportbits == 2, similar to how 4-bit and 8-bit are handled today.Environment
onnx-community/gemma-4-E4B-it-qat-mobile-ONNX