Skip to content

[ET-VK][ops] Fuse a trailing relu into q8ta_pixel_shuffle - #25328

Merged
SS-JIA merged 1 commit into
gh/SS-JIA/740/origfrom
gh/SS-JIA/741/orig
Nov 20, 2026
Merged

SS-JIA merged 1 commit into
gh/SS-JIA/740/origfrom
gh/SS-JIA/741/orig

Conversation

@pytorchbot

Copy link
Copy Markdown
Collaborator

This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #25316 by @SS-JIA
^ Please use this as the source of truth for the PR details, comments, and reviews
ghstack PR base: https://github.com/pytorch/executorch/tree/gh/SS-JIA/741/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/741/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/SS-JIA/740/orig
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/741/orig
Differential Revision: D133330257
@diff-train-skip-merge

## Ulterior Motive

Quantized models that upsample with `PixelShuffle` followed by `ReLU` lower to `dequantize -> pixel_shuffle -> relu -> quantize`, four fp32 dispatches per upsample. This commit fuses that chain into the existing int8 `q8ta_pixel_shuffle` kernel.

## Rationale

**What**: A new overload `et_vk.q8ta_pixel_shuffle.with_activation(..., str activation)`, which the quantized pixel shuffle pattern emits when an activation sits between `pixel_shuffle` and `quantize`. `relu` is the only supported activation.

**Why**: The pattern only matched `dequantize -> pixel_shuffle -> quantize`. With a `relu` in between, nothing fused and the upsample ran in fp32.

## Details

- Pattern (`quantized_pixel_shuffle.py`)
  - **Before**: `dequantize -> [clone] -> pixel_shuffle -> [clone] -> quantize` fuses into `q8ta_pixel_shuffle.default`.
  - **After**: an optional activation (`relu`, with optional clones after it) is also matched, and the match emits `q8ta_pixel_shuffle.with_activation` with the activation name. Supported activations are listed in one table, `_ACTIVATIONS`.
- Runtime: both overloads register the same dispatch and shader, so no shader variant is added.
  - For a positive output scale, `quantize(relu(x)) == max(quantize(x), zp_out)`. The kernel therefore applies relu by raising the lower clamp bound of the requantized value from -128 to `zp_out`, passed as a new push constant `q_min`.
  - This is bit-exact with the unfused chain, because `q8ta_quantize` uses the same `round(x * inv_scale) + zp` arithmetic.
  - With an activation, the pure byte-shuffle (`passthrough`) path is disabled.
- `add_q8ta_pixel_shuffle_node` takes an `ActivationType`, reusing the enum and parser from the q8ta conv2d ops.
- Tests
  - `etvk_ops_bench`: the reference and throughput functions are registered for the new overload. `correctness.json` adds one case with 8 argument sets: 4 shapes (including odd sizes and batch 2), each with requantizing and with matching quantization params, across the 3 x 3 input/output layout sweep. `performance.json` adds one case with 3 upsample shapes.
  - `test_vulkan_passes.py`: `test_fuse_quantized_pixel_shuffle_relu` checks the fused op, its arguments, that no quant/dequant/relu nodes remain, and that the fused graph matches the eager module exactly.

Authored with Claude Code.

Differential Revision: [D133330257](https://our.internmc.facebook.com/intern/diff/D133330257/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D133330257/)!


ghstack-source-id: 478906449
Pull-Request: #25316
@pytorchbot
pytorchbot requested a review from SS-JIA as a code owner November 20, 2026 02:31
@pytorch-bot

pytorch-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⏳ No Failures, 90 Pending

As of commit c4c9058 with merge base c29858d (image):
💚 Looks good so far! There are no failures yet. 💚

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 Nov 20, 2026
@SS-JIA
SS-JIA added this pull request to stack #25329 November 20, 2026 02:47
@SS-JIA
SS-JIA merged commit 1b7cbdd into main Nov 20, 2026
217 of 224 checks passed
@SS-JIA
SS-JIA deleted the gh/SS-JIA/741/orig branch November 20, 2026 02:48

This branch was previously deployed

1 inactive deployment
cadence — c4c90588 Deployed Nov 20, 2026 by pytorchbot via hifi-op-test / hifi4 #39579
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