Skip to content

embedding_q4gsw: support is_linear_weight packing#20639

Merged
JulianCloudNTH merged 1 commit into
pytorch:mainfrom
JulianCloudNTH:export-D110211746
Jun 30, 2026
Merged

embedding_q4gsw: support is_linear_weight packing#20639
JulianCloudNTH merged 1 commit into
pytorch:mainfrom
JulianCloudNTH:export-D110211746

Conversation

@JulianCloudNTH

Copy link
Copy Markdown
Contributor

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

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
@pytorch-bot

pytorch-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20639

Note: Links to docs will display an error until the docs builds have been completed.

❌ 5 New Failures, 4 Pending, 24 Unrelated Failures

As of commit a45d9ba with merge base e095c57 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 30, 2026
@meta-codesync

meta-codesync Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

@JulianCloudNTH has exported this pull request. If you are a Meta employee, you can view the originating Diff in D110211746.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@JulianCloudNTH JulianCloudNTH merged commit 6d0b933 into pytorch:main Jun 30, 2026
164 of 198 checks passed
@JulianCloudNTH JulianCloudNTH deleted the export-D110211746 branch June 30, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants