Skip to content

[Bug Fix] Fix padding when running in NHWC #9729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2025

Conversation

mcr229
Copy link
Contributor

@mcr229 mcr229 commented Mar 27, 2025

Summary

There is a bug when there is a constant_pad between two convolutions. In order to minimize permutes associated with memory format changes, we sometimes compute ops in NHWC. This is the case for ConstantPad when it is between two convs:

    a = conv(a)
    a = constant_pad(a, paddings=[1, 2, 3, 4])
    a = conv(a)

in this case we need to make sure the paddings given to constant_pad are also permuted to nhwc.

Test plan

python install_executorch.py --editable

python -m unittest backends.xnnpack.test.ops.test_static_constant_pad.TestStaticConstantPad.test_fp32_static_constant_pad_nhwc

@mcr229 mcr229 requested a review from digantdesai as a code owner March 27, 2025 23:22
Copy link

pytorch-bot bot commented Mar 27, 2025

🔗 Helpful Links

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

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

❌ 1 New Failure, 2 Pending

As of commit d013b83 with merge base 65ebabb (image):

NEW FAILURE - The following job has failed:

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

@facebook-github-bot facebook-github-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 Mar 27, 2025
@mcr229 mcr229 added topic: not user facing and removed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Mar 27, 2025
@mcr229 mcr229 requested review from GregoryComer and digantdesai and removed request for digantdesai March 27, 2025 23:23
Copy link
Member

@GregoryComer GregoryComer left a comment

Choose a reason for hiding this comment

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

Nice catch.

@facebook-github-bot facebook-github-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 Mar 28, 2025
@mcr229 mcr229 force-pushed the nhwc_constant_pad branch from 3492e53 to d013b83 Compare March 28, 2025 22:34
@mcr229 mcr229 merged commit 7d35c68 into pytorch:main Mar 28, 2025
81 of 82 checks passed
@mcr229
Copy link
Contributor Author

mcr229 commented Apr 1, 2025

@pytorchbot cherry-pick --onto release/0.6 -c critical

pytorchbot pushed a commit that referenced this pull request Apr 1, 2025
### Summary
There is a bug when there is a constant_pad between two convolutions. In
order to minimize permutes associated with memory format changes, we
sometimes compute ops in NHWC. This is the case for ConstantPad when it
is between two convs:

```
    a = conv(a)
    a = constant_pad(a, paddings=[1, 2, 3, 4])
    a = conv(a)
```

in this case we need to make sure the paddings given to constant_pad are
also permuted to nhwc.

### Test plan
python install_executorch.py --editable

python -m unittest
backends.xnnpack.test.ops.test_static_constant_pad.TestStaticConstantPad.test_fp32_static_constant_pad_nhwc

(cherry picked from commit 7d35c68)
@pytorchbot
Copy link
Collaborator

Cherry picking #9729

The cherry pick PR is at #9816 and it is recommended to link a critical cherry pick PR with an issue. The following tracker issues are updated:

Details for Dev Infra team Raised by workflow job

kirklandsign pushed a commit that referenced this pull request Apr 11, 2025
### Summary
There is a bug when there is a constant_pad between two convolutions. In
order to minimize permutes associated with memory format changes, we
sometimes compute ops in NHWC. This is the case for ConstantPad when it
is between two convs:

```
    a = conv(a)
    a = constant_pad(a, paddings=[1, 2, 3, 4])
    a = conv(a)
```

in this case we need to make sure the paddings given to constant_pad are
also permuted to nhwc.

### Test plan
python install_executorch.py --editable

python -m unittest
backends.xnnpack.test.ops.test_static_constant_pad.TestStaticConstantPad.test_fp32_static_constant_pad_nhwc
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. topic: not user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants