Skip to content

Add pass to replace some ops with channels last variants.#20788

Open
MartinPavella wants to merge 2 commits into
pytorch:mainfrom
nxp-upstream:nxg01483/EIEX-992-create-tocontiguouschannelslastpass
Open

Add pass to replace some ops with channels last variants.#20788
MartinPavella wants to merge 2 commits into
pytorch:mainfrom
nxp-upstream:nxg01483/EIEX-992-create-tocontiguouschannelslastpass

Conversation

@MartinPavella

Copy link
Copy Markdown
Collaborator

Summary

Add a transformation pass to replace some operators with their channels last variant. Currently only convolution and avg_pool2d are implemented, as those are the only operators with a channels last variant. In the future, the pass can be easily extended to support more operators.

Test plan

Tested by pytest backends/transforms/test/test_replace_ops_with_channels_last_variants.py.

When replacing aten.avg_pool2d` with `channels_last.avg_pool2d`, some attributes of the aten operator can be left out, and must be replaced by default values. This can either be done in the "to channels last" transformation pass, or in the definition of the operator. Adding the default attributes of the aten operator to the channels_last operator seems cleaner to me.
The pass currently supports `convolution` and `avg_pool2d`, as those are the only 2 operators with a channels last variant. The pass can be easily extended to more ops in the future.
@MartinPavella MartinPavella self-assigned this Jul 8, 2026
@MartinPavella MartinPavella added the python Pull requests that update python code label Jul 8, 2026
@pytorch-bot

pytorch-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 41d0b63 with merge base 6018283 (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 Jul 8, 2026
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Not Signed

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

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.

@MartinPavella

Copy link
Copy Markdown
Collaborator Author

@AdrianLundell this is the first part of #20094. I am planning on introducing the second part (a pass which makes the graph contiguous) separately.

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. python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant