Skip to content

[ExecuTorch][WebGPU] Add quantize_per_tensor op (int8 buffer path)#21187

Open
JCNTH wants to merge 1 commit into
gh/JCNTH/147/basefrom
gh/JCNTH/147/head
Open

[ExecuTorch][WebGPU] Add quantize_per_tensor op (int8 buffer path)#21187
JCNTH wants to merge 1 commit into
gh/JCNTH/147/basefrom
gh/JCNTH/147/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Problem: The WebGPU delegate has no per-tensor quantization — the C0 gate for the int8 activation path that the Vulkan delegate's q8ta quantized ops build on. Without it, no int8-input/output op can be served.

Solution: Port quantized_decomposed.quantize_per_tensor.default (fp32 -> int8), the backend's first non-fp32 storage-buffer op. The int8 output is packed 4 elements per 32-bit word and bound as array<u32> (the landed q4gsw idiom), since WebGPU always allocates buffers and ignores the serialized memory_layout.

Implementation: QuantizePerTensor.cpp registers only .default (mirrors Vulkan), reads scale/zero_point at fixed arg indices with out = args.back() (robust to the overload's arg count), and guards int8 output / numel % 4 == 0 (the array<u32> binding) / fp32 input / non-null buffers, all fail-loud. quantize_per_tensor.wgsl computes round(x * inv_scale) + zero_point, clamps to [-128, 127], and packs; inv_scale is the reciprocal taken in double then cast to f32, bit-matching torch's round(input * (1.0 / scale)). WebGPUTensor gains an is_int8 flag (distinguishes int8 from uint8/bool, which share a 1-byte size) so the handler can reject a non-int8 output. Mirrors Vulkan runtime/graph/ops/glsl/q8ta_quantize.glsl + impl/QuantizeDequantize.cpp.

Differential Revision: D112257614

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (1 Unrelated Failure)

As of commit bef151e with merge base 266e0dc (image):

BROKEN TRUNK - The following job 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.

@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.

This was referenced Jul 22, 2026
@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 Jul 22, 2026
This was referenced Jul 22, 2026
@JCNTH
JCNTH requested a review from psiddh July 23, 2026 02:06

@psiddh psiddh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving full WebGPU stack

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants