Skip to content

Allow transposed convolution weights with a non-default dim order#21035

Open
SuryanshSS1011 wants to merge 1 commit into
pytorch:mainfrom
SuryanshSS1011:fix/20804-transposed-conv-out-channels-1
Open

Allow transposed convolution weights with a non-default dim order#21035
SuryanshSS1011 wants to merge 1 commit into
pytorch:mainfrom
SuryanshSS1011:fix/20804-transposed-conv-out-channels-1

Conversation

@SuryanshSS1011

Copy link
Copy Markdown
Contributor

Summary

Fixes #20804.

A transposed convolution whose weight has out_channels == 1 fails in the portable kernel with Check failed (tensor_is_default_or_channels_last_dim_order(weight)) (status 18). check_convolution_args runs tensor_is_default_or_channels_last_dim_order(weight) unconditionally, but a transposed conv weight is laid out as (in_channels, out_channels / groups, kH, kW), so when out_channels == 1 the weight comes through with a dim order such as [1, 0, 2, 3], which is neither contiguous ([0,1,2,3]) nor channels-last. For out_channels > 1 the dim order is [0,1,2,3] and the check passes, which matches the report.

The transposed path in op_convolution.cpp indexes the weight through strides derived from its dim order (dim_order_to_stride_nocheck then calculate_linear_index), so it reads the correct values regardless of whether the weight is in [0,1,2,3] or [1,0,2,3]. I checked this with the exact stride/index logic: every weight lookup matches between the two layouts, so the kernel already handles this weight and only the up-front check needs to change.

This skips the weight dim-order check when transposed is true, since the kernel does not rely on that layout, rather than reordering the weight upstream. Happy to switch to normalizing the weight instead if that's preferred.

Test plan

Added TransposedWeightNonDefaultDimOrder in kernels/test/op_convolution_test.cpp: a transposed conv with a (1, 1, 2, 2) weight built in dim order [1, 0, 2, 3], checked against a reference output computed with torch.nn.ConvTranspose2d. The test fails before this change (the weight is rejected) and passes after it.

Copilot AI review requested due to automatic review settings July 18, 2026 08:31
@pytorch-bot

pytorch-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 13 Awaiting Approval

As of commit 1433bf1 with merge base 55a71e6 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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 Jul 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a portability issue in ExecuTorch’s portable CPU convolution kernel argument validation for transposed convolutions, where valid conv_transpose2d weights can arrive with a non-default dim order (not contiguous / not channels-last) when out_channels == 1.

Changes:

  • Skip the “default or channels-last dim order” validation for weight when transposed == true, since the transposed convolution implementation indexes weights via strides.
  • Add a regression test intended to cover the non-default dim-order transposed-weight scenario (issue #20804).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
kernels/portable/cpu/util/kernel_ops_util.cpp Adjusts convolution argument validation to allow non-default dim order weights for transposed convolutions.
kernels/test/op_convolution_test.cpp Adds a regression test for transposed convolution weights with a non-default dim order.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread kernels/test/op_convolution_test.cpp Outdated
Comment thread kernels/portable/cpu/util/kernel_ops_util.cpp Outdated
Copilot AI review requested due to automatic review settings July 18, 2026 08:44
@SuryanshSS1011
SuryanshSS1011 force-pushed the fix/20804-transposed-conv-out-channels-1 branch from ac4b307 to 382de05 Compare July 18, 2026 08:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@SuryanshSS1011

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: ops & kernels"

@pytorch-bot pytorch-bot Bot added the release notes: ops & kernels Changes to the opset and any new / changed kernel implementations label Jul 18, 2026
Copilot AI review requested due to automatic review settings July 18, 2026 08:52
@SuryanshSS1011
SuryanshSS1011 force-pushed the fix/20804-transposed-conv-out-channels-1 branch from 382de05 to 1433bf1 Compare July 18, 2026 08:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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. release notes: ops & kernels Changes to the opset and any new / changed kernel implementations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Edge aten.convolution with transposed=True fails when output_channels=1

3 participants