Skip to content

Arm backend: Add MAX_POOL2D tosa dialect op#18970

Merged
AdrianLundell merged 1 commit intopytorch:mainfrom
AdrianLundell:change-1241099
Apr 17, 2026
Merged

Arm backend: Add MAX_POOL2D tosa dialect op#18970
AdrianLundell merged 1 commit intopytorch:mainfrom
AdrianLundell:change-1241099

Conversation

@AdrianLundell
Copy link
Copy Markdown
Collaborator

@AdrianLundell AdrianLundell commented Apr 17, 2026

Change-Id: I2db9e00104174952eead47820dd28cfcd8942ff6
Signed-off-by: Adrian Lundell <adrian.lundell@arm.com>
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 17, 2026

🔗 Helpful Links

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

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

❌ 1 New Failure, 6 Cancelled Jobs, 7 Pending

As of commit 81cb360 with merge base 9d72936 (image):

NEW FAILURE - The following job has failed:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

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 Apr 17, 2026
@AdrianLundell AdrianLundell marked this pull request as ready for review April 17, 2026 09:52
Copilot AI review requested due to automatic review settings April 17, 2026 09:52
@AdrianLundell AdrianLundell added partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm ciflow/trunk release notes: none Do not include this in the release notes labels Apr 17, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for lowering 2D max pooling to a TOSA dialect MAX_POOL2D op in the Arm backend, including a rewrite pass and corresponding operator visitor updates.

Changes:

  • Introduce a new TOSA dialect fake op MAX_POOL2D with shape/dtype validation and output meta computation.
  • Add RewriteMaxPool2dPass and integrate it into the Arm pass pipelines (including SizeAdjustInputPass dependencies).
  • Update the Arm operator visitor to lower tosa.MAX_POOL2D.default, and add a new unit test covering the rewrite.

Reviewed changes

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

Show a summary per file
File Description
backends/arm/tosa/dialect/ops/max_pool2d.py Adds fake TOSA op schema + output meta for MAX_POOL2D.
backends/arm/tosa/dialect/__init__.py Ensures the new dialect op module is imported/registered.
backends/arm/_passes/rewrite_max_pool2d_pass.py New pass rewriting edge max_pool2d into backend TOSA MAX_POOL2D.
backends/arm/_passes/arm_pass_manager.py Inserts RewriteMaxPool2dPass into the TOSA pipeline.
backends/arm/_passes/size_adjust_input_pass.py Adds RewriteMaxPool2dPass to required-after passes.
backends/arm/_passes/__init__.py Exposes the new rewrite pass.
backends/arm/operators/op_tosa_max_pool2d.py Switches visitor to handle tosa.MAX_POOL2D.default and uses provided attrs directly.
backends/arm/operators/__init__.py Registers the new op_tosa_max_pool2d visitor (removes old import).
backends/arm/test/passes/test_rewrite_max_pool2d_pass.py Adds rewrite-pass test coverage.

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

Comment on lines +38 to +41
if len(args) > 2 and args[2] is not None and len(args[2]) > 0:
stride = _to_2tuple(args[2])
else:
stride = kernel
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

args[2] (stride) can be an int (e.g., max_pool2d(..., stride=2)), but this code calls len(args[2]), which will raise TypeError: object of type 'int' has no len(). Normalize stride via type checks (int/Sequence/None) before using len() and before passing it to _to_2tuple so the pass works for both scalar and tuple/list strides.

Suggested change
if len(args) > 2 and args[2] is not None and len(args[2]) > 0:
stride = _to_2tuple(args[2])
else:
stride = kernel
raw_stride = args[2] if len(args) > 2 else None
if raw_stride is None:
stride = kernel
else:
stride = _to_2tuple(raw_stride)

Copilot uses AI. Check for mistakes.
)
pipeline.pop_stage(
"run_method_and_compare_outputs"
) # Cannnot run aten graph with tosa dialect ops
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

Typo in comment: "Cannnot" should be "Cannot".

Suggested change
) # Cannnot run aten graph with tosa dialect ops
) # Cannot run aten graph with tosa dialect ops

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

@oscarandersson8218 oscarandersson8218 left a comment

Choose a reason for hiding this comment

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

Doesn't seem to need any Buck-changes. LGTM!

@AdrianLundell
Copy link
Copy Markdown
Collaborator Author

Fail unrelated

@AdrianLundell AdrianLundell merged commit 04955b2 into pytorch:main Apr 17, 2026
422 of 448 checks passed
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. partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants