Skip to content

Arm backend: Fix avg_pool2d divisor_override with ceil_mode and no padding - #24894

Open
EylonKrause wants to merge 1 commit into
pytorch:mainfrom
EylonKrause:fix/avgpool-divisor-override-ceil-mode
Open

EylonKrause wants to merge 1 commit into
pytorch:mainfrom
EylonKrause:fix/avgpool-divisor-override-ceil-mode

Conversation

@EylonKrause

@EylonKrause EylonKrause commented Nov 11, 2026 •

Copy link
Copy Markdown

Summary

DecomposeAvgPool2dPass lowers avg_pool2d with a divisor_override to avg_pool2d(count_include_pad=False) on a zero padded input, followed by a multiplication by kernel_size / divisor_override. That is only exact when every window is full. _compute_post_pad returned early for padding=0, so with ceil_mode=True the last, partial window was averaged over its valid elements only.

Example: avg_pool2d(kernel=(1, 2), stride=(1, 2), padding=0, ceil_mode=True, divisor_override=2) on [1, 2, 3, 4, 5]: PyTorch gives [1.5, 3.5, 2.5] (5 / 2), the decomposition gave [1.5, 3.5, 5.0]. This is a silent numerical error in the lowered model.

This change computes the post padding for ceil_mode with a divisor_override also when padding=0, and inserts the pad whenever any pad value is non-zero rather than only when the symmetric pre-padding is. Behaviour only changes when padding=0, ceil_mode=True and divisor_override are all set.

Independent of #24893 (it touches a different function in the same file; the two branches merge cleanly).

Release notes: arm

Test plan

  • New cases divisor_override_ceil_mode_no_padding and divisor_override_ceil_mode_no_padding_count_include_pad in test_avg_pool2d.py; they fail on main in the TOSA FP and INT variants and pass with this change.
  • Sweep over kernel 2-3, stride 1-3, padding 0-1, ceil_mode, count_include_pad, divisor_override in {None, 1, 2, 4, 7}, input height 4-15: 176 configurations with padding=0 fail on main (all with ceil_mode and a divisor_override), 0 with this change.
  • test_avg_pool2d.py, test_decompose_avg_pool2d_pass.py, test_rewrite_avg_pool2d_pass.py, test_adaptive_avg_pool2d.py, test_mean_dim.py (excluding u55/u85/vgf): no new failures.
  • Not run locally: the u55/u85/vgf variants (no Corstone FVP / Vela installed here), so those rely on CI.
  • ufmt check and flake8 clean on the changed files.

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani @nil-is-all

…dding

DecomposeAvgPool2dPass lowers avg_pool2d with a divisor_override to
avg_pool2d(count_include_pad=False) on a zero padded input, followed by
a multiplication by kernel_size / divisor_override. That is only exact
when every window is full. _compute_post_pad returned early for
padding=0, so with ceil_mode=True the last, partial window was averaged
over its valid elements only.

For avg_pool2d(kernel=(1, 2), stride=(1, 2), padding=0, ceil_mode=True,
divisor_override=2) on [1, 2, 3, 4, 5], PyTorch gives
[1.5, 3.5, 2.5] (5 / 2) and the decomposition gave [1.5, 3.5, 5.0].

Compute the post padding for ceil_mode with a divisor_override also when
padding=0, and insert the pad whenever any pad value is non-zero rather
than only when the symmetric pre-padding is.

Test plan: Ran the decomposition on the example above, and lowered
avg_pool2d configurations with ceil_mode and divisor_override through
TosaPipelineFP. Added test cases to test_avg_pool2d.py.

Signed-off-by: Eylon Eliyahu Krause <64223519+EylonKrause@users.noreply.github.com>
@pytorch-bot

pytorch-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 2 New Failures, 1 Pending, 4 Unrelated Failures

As of commit e6c7ba9 with merge base 81acbc1 (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@linux-foundation-easycla

Copy link
Copy Markdown

CLA Not Signed

@github-actions github-actions Bot added ciflow/trunk module: arm Issues related to arm backend labels Nov 11, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@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 Nov 11, 2026
@github-actions

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.

@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Nov 11, 2026
@zingo zingo added the partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm label Nov 11, 2026
@zingo

zingo commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Thanks a lot for this PRs :) I kicked of some extended testing here also. This job also ask you for EasyCLA but you onl;y need to to it once and I think the CI will pick it up automatically if not a simple rebase will usually help, lets see.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. community: contribution PRs coming from community (excluding hardware partners) module: arm Issues related to arm backend partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants