Skip to content

Add structure for use of TOSA CUSTOM ops#18837

Merged
robell merged 7 commits intopytorch:mainfrom
robell:custom
Apr 14, 2026
Merged

Add structure for use of TOSA CUSTOM ops#18837
robell merged 7 commits intopytorch:mainfrom
robell:custom

Conversation

@robell
Copy link
Copy Markdown
Collaborator

@robell robell commented Apr 13, 2026

TOSA custom ops allow for wrapped custom operators of their own dialect. This adds the tosa op and recognition in partitioning to enable custom torch.library operators to be passed into the arm backend and mapped to backend provided implementations.

The broader implementation using these mechanisms will follow.

  • Enables operators to be registered in the partitioner
  • add tosa.CUSTOM fake op registration in the dialect
  • for backend passes (in tree or registed) to create+use tosa.custom only within partition
  • register a TOSA CUSTOM node visitor for serialization
  • as custom wraps an operator, adds support for register_fake_tosa to register the shape-only operator in tosa

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson

robell added 2 commits April 13, 2026 09:32
- Enables operators to be registered in the partitioner
- it's expected that custom dialects are registered in this way
- These should be paird with an ArmBackend pass

Signed-off-by: Rob Elliott <Robert.Elliott@arm.com>
Change-Id: If48fd1a0031b91ef0b0d442939557c23df4bf00a
- add tosa.CUSTOM fake op registration in the dialect
- for backend passes to create+use tosa.custom only within partition
- register a TOSA CUSTOM node visitor for serialization
- needing shape for the wrapped op, adding a decorator for tosa shape

Signed-off-by: Rob Elliott <Robert.Elliott@arm.com>
Change-Id: I085ffe8656ffc1edf22d70c92bfc80aa2e602694
Copilot AI review requested due to automatic review settings April 13, 2026 08:56
@robell robell requested a review from digantdesai as a code owner April 13, 2026 08:56
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Apr 13, 2026

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 4 New Failures, 1 Cancelled Job, 3 Unrelated Failures

As of commit a3b7ee1 with merge base 2eaa16c (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOB - The following job was cancelled. Please retry:

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.

@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 13, 2026
@robell robell added the partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm label Apr 13, 2026
@robell robell added release notes: arm Changes to the ARM backend delegate ciflow/trunk labels Apr 13, 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 initial infrastructure for representing and plumbing backend-defined custom operators through the Arm TOSA pipeline, including partitioning support, fake-op propagation, and serialization.

Changes:

  • Extend the TOSA partitioner to treat explicitly registered custom ops as supported and to prevent their decomposition.
  • Add a generic tosa.CUSTOM fake op plus a registry mechanism to plug in per-wrapped-op fake implementations.
  • Add a TOSA CUSTOM node visitor to serialize tosa.CUSTOM into the TOSA serializer graph, and update metadata extraction to better handle list-valued meta["val"].

Reviewed changes

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

Show a summary per file
File Description
backends/arm/tosa/partitioner.py Adds custom-op registration and integrates custom-op support into partitioning and decomposition policy.
backends/arm/tosa/mapping.py Extends extract_tensor_meta to handle meta["val"] as a non-empty list (multi-output cases).
backends/arm/tosa/dialect/ops/custom.py Introduces tosa.CUSTOM fake op plus registry/dispatch for wrapped custom-op fake implementations.
backends/arm/tosa/dialect/init.py Ensures the new custom dialect ops module is imported/registered.
backends/arm/operators/op_tosa_custom.py Adds serializer lowering for tosa.CUSTOM.default via a new node visitor.
backends/arm/operators/init.py Registers the new custom node visitor module for import side effects.

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

Signed-off-by: Rob Elliott <Robert.Elliott@arm.com>
Change-Id: I2a99c32db6abd0e6c0781cccf10920887340a2a6
@pytorch pytorch deleted a comment from Copilot AI Apr 13, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 13, 2026 09:35
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

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


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

Signed-off-by: Rob Elliott <Robert.Elliott@arm.com>
Change-Id: I49be3aaeb79c2a0b0124dc1267626e7e9098f8a5
Signed-off-by: Rob Elliott <Robert.Elliott@arm.com>
Change-Id: I8f12a57d6781266c6a3cbd43b1d5310d7c4ba4e2
Copilot AI review requested due to automatic review settings April 13, 2026 10:30
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

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

Comments suppressed due to low confidence (2)

backends/arm/ethosu/partitioner.py:37

  • torch is referenced in the type annotation for _custom_partition_ops, but this module does not import torch. Because annotations are evaluated at import time (no from __future__ import annotations here), importing this module will raise NameError: name 'torch' is not defined. Add import torch (or quote the annotation) to fix the import-time failure.
        )
        self.additional_checks = additional_checks
        self.tosa_spec = compile_spec.tosa_spec
        self._custom_partition_ops: set[torch._ops.OpOverload] = set()

backends/arm/vgf/partitioner.py:37

  • torch is referenced in the type annotation for _custom_partition_ops, but this module does not import torch. Because annotations are evaluated at import time (no from __future__ import annotations here), importing this module will raise NameError: name 'torch' is not defined. Add import torch (or quote the annotation) to fix the import-time failure.
        )
        self.additional_checks = additional_checks
        self.tosa_spec = compile_spec.tosa_spec
        self._custom_partition_ops: set[torch._ops.OpOverload] = set()


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

Signed-off-by: Rob Elliott <Robert.Elliott@arm.com>
Change-Id: I1454152695a91030e88fb4ede612e15a701561da
@robell robell merged commit a6e4ade into pytorch:main Apr 14, 2026
412 of 422 checks passed
jpiat pushed a commit to jpiat/executorch that referenced this pull request Apr 14, 2026
TOSA custom ops allow for wrapped custom operators of their own dialect.
This adds the tosa op and recognition in partitioning to enable custom
torch.library operators to be passed into the arm backend and mapped to
backend provided implementations.

The broader implementation using these mechanisms will follow.

- Enables operators to be registered in the partitioner
- add tosa.CUSTOM fake op registration in the dialect
- for backend passes (in tree or registed) to create+use tosa.custom
only within partition
- register a TOSA CUSTOM node visitor for serialization
- as custom wraps an operator, adds support for register_fake_tosa to
register the shape-only operator in tosa

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils
@Sebastian-Larsson

---------

Signed-off-by: Rob Elliott <Robert.Elliott@arm.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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: arm Changes to the ARM backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants