Repository navigation
[ET-VK][ops] Fuse a trailing relu into q8ta_pixel_shuffle - #25328
Merged
Merged
Conversation
## 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
🔗 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 PendingAs of commit c4c9058 with merge base c29858d ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
SS-JIA
approved these changes
Nov 20, 2026
This branch was previously deployed
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.
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