Skip to content

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

Merged
meta-codesync[bot] merged 2 commits into
gh/JCNTH/147/basefrom
gh/JCNTH/147/head
Jul 24, 2026
Merged

[ExecuTorch][WebGPU] Add quantize_per_tensor op (int8 buffer path)#21187
meta-codesync[bot] merged 2 commits 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.
@exported-using-ghexport

Differential Revision: D112257614

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.

❌ 41 New Failures, 2 Unrelated Failures

As of commit bee86cb with merge base 4a26c64 (image):

NEW FAILURES - The following jobs have failed:

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

  • pull / unittest / windows / windows-job (gh) (matched win rule in flaky-rules.json)
    Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under 'C:\actions-runner\_work\executorch\executorch\test-infra\.github\actions\teardown-windows'. Did you forget to run actions/checkout before running your local action?
  • pull / unittest-editable / windows / windows-job (gh) (matched win rule in flaky-rules.json)
    Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under 'C:\actions-runner\_work\executorch\executorch\test-infra\.github\actions\teardown-windows'. Did you forget to run actions/checkout before running your local action?

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
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
JCNTH added a commit that referenced this pull request Jul 24, 2026
Pull Request resolved: #21187

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`.
ghstack-source-id: 406366809
@exported-using-ghexport

Differential Revision: [D112257614](https://our.internmc.facebook.com/intern/diff/D112257614/)
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