embedding_q4gsw: support is_linear_weight packing#20639
Merged
Conversation
Summary: The WebGPU `embedding_q4gsw` op failed to load (`Error::DelegateInvalidCompatibility`, error 48): `WebGPUGraph::build()` threw `is_linear_weight=true is unsupported` and `WebGPUBackend.cpp` returned error 48 at `load_forward`. The `quantized_decomposed.embedding_4bit` and torchao fusions in `backends/vulkan/patterns/quantized_embedding.py` repack the embedding weight into the 4-bit linear-layer nibble convention (low nibble = even dim, high nibble = odd dim) and emit `et_vk.embedding_q4gsw.default(..., is_linear_weight=true)` — always on OSS main, and for tied (embedding/LM-head-shared) weights via `_detect_tied_linear_weight`. The Vulkan runtime supports both packings via its compile-time `_linear_weight` shader variant; the WebGPU runtime rejected `true` outright, so any model whose embedding took that path failed to delegate. This teaches the WebGPU runtime both packings. The handler now forwards `is_linear_weight` to the shader through the uniform (the spare `_pad` field is repurposed; struct size unchanged), and `embedding_q4gsw.wgsl` selects the nibble with `use_high = is_even != is_linear_weight`. The `is_linear_weight=false` path is byte-identical to before. Differential Revision: D110211746
Contributor
|
@JulianCloudNTH has exported this pull request. If you are a Meta employee, you can view the originating Diff in D110211746. |
This PR needs a
|
rascani
approved these changes
Jun 30, 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:
The WebGPU
embedding_q4gswop failed to load (Error::DelegateInvalidCompatibility, error 48):WebGPUGraph::build()threwis_linear_weight=true is unsupportedandWebGPUBackend.cppreturned error 48 atload_forward.The
quantized_decomposed.embedding_4bitand torchao fusions inbackends/vulkan/patterns/quantized_embedding.pyrepack the embedding weight into the 4-bit linear-layer nibble convention (low nibble = even dim, high nibble = odd dim) and emitet_vk.embedding_q4gsw.default(..., is_linear_weight=true)— always on OSS main, and for tied (embedding/LM-head-shared) weights via_detect_tied_linear_weight. The Vulkan runtime supports both packings via its compile-time_linear_weightshader variant; the WebGPU runtime rejectedtrueoutright, so any model whose embedding took that path failed to delegate.This teaches the WebGPU runtime both packings. The handler now forwards
is_linear_weightto the shader through the uniform (the spare_padfield is repurposed; struct size unchanged), andembedding_q4gsw.wgslselects the nibble withuse_high = is_even != is_linear_weight. Theis_linear_weight=falsepath is byte-identical to before.Differential Revision: D110211746