You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1b7cbdd
Browse filesBrowse the repository at this point in the historyBrowse files
[ET-VK][ops] Fuse a trailing relu into q8ta_pixel_shuffle
## 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
0 commit comments