Skip to content

Comments

[ET-VK][qconv] Fix depthwise weight_sums sum dimension#17573

Merged
SS-JIA merged 6 commits intomainfrom
gh/SS-JIA/432/orig
Feb 20, 2026
Merged

[ET-VK][qconv] Fix depthwise weight_sums sum dimension#17573
SS-JIA merged 6 commits intomainfrom
gh/SS-JIA/432/orig

Conversation

@pytorchbot
Copy link
Collaborator

This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #17504 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/432/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/432/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/main
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/432/orig
Differential Revision: D93511635
@diff-train-skip-merge

Pull Request resolved: #17504

The weight_sums tensor stores per-output-channel sums of quantized weight values, used to apply activation zero point correction during integer accumulation. For depthwise convolutions, the weight tensor is reshaped to (H, W, OC), but the sum was unconditionally computed along dim=1 (the W dimension). This produced a tensor of shape (H, OC) instead of (OC,), causing incorrect zero point correction and corrupted depthwise conv output.

Fix by branching on is_depthwise_conv to sum over dims (0, 1) for the (H, W, OC) layout.
ghstack-source-id: 342806069
@exported-using-ghexport

Differential Revision: [D93511635](https://our.internmc.facebook.com/intern/diff/D93511635/)
@pytorchbot pytorchbot requested a review from SS-JIA as a code owner February 20, 2026 01:13
@pytorch-bot
Copy link

pytorch-bot bot commented Feb 20, 2026

🔗 Helpful Links

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

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

⏳ No Failures, 125 Pending

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

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@github-actions
Copy link

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.

@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 Feb 20, 2026
ssjia added 5 commits February 19, 2026 20:17
Pull Request resolved: #17505

The q8ta convolution shaders read weight_sums via ivec4 loads (4 int32 values at once), requiring the buffer to have at least align_up_4(OC) elements. The weight tensor, weight_scales, and bias are all padded via align_width_and_update_state_dict, but weight_sums was created as a 1D tensor of shape (OC,) without any padding.

For OC values that are not a multiple of 4 (e.g. OC=1 in the final pointwise conv of MetaNet GreenScreen), this results in out-of-bounds GPU buffer reads. On host testing with ASAN, this manifests as a heap-buffer-overflow.

Fix by padding sum_per_output_channel to align_up_4(OC) before creating the constant placeholder. Also fix the C++ test utility compute_weight_sums() which was incorrectly shrinking a pre-allocated aligned buffer.
ghstack-source-id: 342806075
@exported-using-ghexport

Differential Revision: [D93511633](https://our.internmc.facebook.com/intern/diff/D93511633/)
Pull Request resolved: #17506

The quantized convolution pattern detector correctly identifies ReLU nodes between conv output and the output quantize node, but the pattern replacement did not pass this information to the fused q8ta operator. When the pattern replaced `dequant → conv → relu → quant` with `q8ta_conv2d`, the relu node was removed from the graph but its effect was not preserved. This silently removed all conv-relu non-linearity from int8 quantized models.

Add an `apply_relu` parameter throughout the full pipeline:
- Custom op schemas and reference implementations (custom_ops_lib.py)
- Pattern replacement (quantized_convolution.py)
- C++ dispatch logic extracts apply_relu and passes it as a spec constant (Q8taConv2d.cpp, Q8taConv2dDW.cpp, Q8taConv2dPW.cpp, Q8taConv2dIm2Col.cpp)
- GLSL shaders apply conditional max(value, 0) after dequantization and before requantization (q8ta_conv2d.glsl, q8ta_conv2d_dw.glsl, q8ta_conv2d_pw.glsl)
- Test operator wrappers updated with proper legacy path handling (TestQ8taConv2d.cpp)
ghstack-source-id: 342806070
@exported-using-ghexport

Differential Revision: [D93511632](https://our.internmc.facebook.com/intern/diff/D93511632/)
Pull Request resolved: #17507

This adds a fused quantized unary operator (ReLU) that operates directly on int8x4 packed buffer tensors, avoiding the overhead of separate dequantize-relu-requantize dispatches.

The implementation follows the same pattern as q8ta_binary: a single GLSL compute shader dequantizes int8x4 blocks to float, applies the unary operation, and requantizes back to int8x4 in one dispatch. The shader uses the OPERATOR macro for parameterization so additional unary ops can be added as YAML variants without new shader code.

Components added:
- GLSL shader (q8ta_unary.glsl) and YAML config with relu variant
- C++ operator implementation (Q8taUnary.cpp/h) registering et_vk.q8ta_relu.default
- Export graph fusion pattern (quantized_unary.py) that detects dequant->relu->quant sequences and replaces them with the fused op
- Custom op definition (q8ta_relu in custom_ops_lib.py) for the export pipeline
- Test harness (TestQ8taUnary.cpp, test_q8ta_unary.cpp) with reference implementation and coverage across multiple shapes and quantized layouts

This diff was authored with Claude.
ghstack-source-id: 342806073
@exported-using-ghexport

Differential Revision: [D93511629](https://our.internmc.facebook.com/intern/diff/D93511629/)
Pull Request resolved: #17508

The batch norm operator registration had a check_batch_norm_node guard that restricted partitioning to 4D input tensors only. Since batch norm is always fused with adjacent operations during graph compilation, this restriction is unnecessary and prevents valid models from being partitioned to the Vulkan backend. Remove the guard so batch norm is always eligible for Vulkan partitioning regardless of input dimensionality.
ghstack-source-id: 342806074
@exported-using-ghexport

Differential Revision: [D93511630](https://our.internmc.facebook.com/intern/diff/D93511630/)
Previously, the q8ta_binary operator required both inputs to use the same memory layout. This was enforced by using a single `in_layout` specialization constant for both input buffers. However, some models may have inputs with different layouts (e.g., 4W4C and 4C1W) that share the same packed dimension and block size, which should be compatible for binary operations. This change introduces a separate `other_layout` specialization constant for the second input, allowing the shader to correctly load from input_b using its actual layout while input_a continues to use `in_layout`. The C++ side now passes both layout hashes as separate specialization constants to the shader.

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

ghstack-source-id: 342806076
Pull Request resolved: #17563
@SS-JIA SS-JIA merged commit 2cad5db into main Feb 20, 2026
137 of 139 checks passed
@SS-JIA SS-JIA deleted the gh/SS-JIA/432/orig branch February 20, 2026 01:29
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