Skip to content

Build custom portable ops#17642

Merged
meta-codesync[bot] merged 1 commit intomainfrom
lfq.build-portable-custom-ops
Mar 1, 2026
Merged

Build custom portable ops#17642
meta-codesync[bot] merged 1 commit intomainfrom
lfq.build-portable-custom-ops

Conversation

@lucylq
Copy link
Copy Markdown
Contributor

@lucylq lucylq commented Feb 23, 2026

Summary

Build custom portable ops, allow for easy import in python. This is mostly for testing but it does allow us to run memory planning tests (and potentially others) in OSS.

  • Build portable_custom_ops_aot_lib shared library (registers allclose.out and allclose.Tensor custom ops into PyTorch) in CMake, following the same pattern as quantized_ops_aot_lib
  • Make test_memory_planning.py importable outside Buck by replacing the Buck-only load_library("//executorch/...") with import executorch.kernels.portable
  • Add kernels/portable/init.py that discovers and loads the built shared library, mirroring kernels/quantized/init.py

Test plan

Confirm memory planning can be tested in python

python -m unittest exir.tests.test_memory_planning

Confirm buck test still works

buck test @fbcode//mode/dev fbcode//executorch/exir/tests:memory_planning 

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Feb 23, 2026

🔗 Helpful Links

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

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

❌ 4 New Failures

As of commit 0d07e8e with merge base 19de115 (image):

NEW FAILURES - The following jobs have failed:

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 Feb 23, 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.

@lucylq lucylq force-pushed the lfq.build-portable-custom-ops branch 13 times, most recently from b1eb06c to b2c40cb Compare February 26, 2026 19:31
Comment thread .lintrunner.toml Outdated
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Feb 26, 2026

@lucylq has imported this pull request. If you are a Meta employee, you can view this in D94555555.

@lucylq lucylq force-pushed the lfq.build-portable-custom-ops branch 3 times, most recently from 3c5b9ae to d40a142 Compare February 26, 2026 22:26
@lucylq lucylq marked this pull request as ready for review February 26, 2026 22:27
@lucylq lucylq requested a review from larryliu0820 as a code owner February 26, 2026 22:27
Copilot AI review requested due to automatic review settings February 26, 2026 22:27
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 build + Python import support for portable custom ops (AOT) so OSS Python tests (e.g., memory planning) can load the shared library without Buck-specific mechanisms.

Changes:

  • Introduces EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT CMake option and Torch discovery at root scope.
  • Builds portable_custom_ops_aot_lib in kernels/portable for registering custom ops into PyTorch.
  • Updates test_memory_planning.py to import executorch.kernels.portable and adds a loader kernels/portable/__init__.py.

Reviewed changes

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

Show a summary per file
File Description
tools/cmake/preset/pybind.cmake Enables a new overridable build option in the pybind preset.
tools/cmake/preset/default.cmake Defines the new EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT option.
src/executorch/kernels/portable Adds a symlink-like entry pointing to kernels/portable.
kernels/quantized/CMakeLists.txt Fixes/rewraps a formatting instruction comment.
kernels/portable/init.py Adds runtime discovery + torch.ops.load_library for the custom ops AOT library.
kernels/portable/CMakeLists.txt Builds portable_custom_ops_aot_lib and sets RPATH for runtime loading.
exir/tests/test_memory_planning.py Replaces Buck-only load with importing executorch.kernels.portable.
CMakeLists.txt Finds Torch at root scope when custom AOT is enabled.
.lintrunner.toml Excludes kernels/portable and kernels/quantized from lintrunner.
Comments suppressed due to low confidence (1)

src/executorch/kernels/portable:1

  • This appears to be a symlink-style entry. Git symlinks can degrade into plain text files on some Windows configurations/checkout modes, which can break imports/packaging. If this is part of the Python package layout, consider replacing it with a real package directory (e.g., src/executorch/kernels/portable/__init__.py that re-exports) or adjust packaging configuration to include kernels/portable without relying on symlinks.

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

Comment thread CMakeLists.txt
set_target_properties(
portable_custom_ops_aot_lib PROPERTIES BUILD_RPATH ${RPATH} INSTALL_RPATH
${RPATH}
)
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

This adds the portable_custom_ops_aot_lib target but does not add any install(TARGETS ...) rule (or otherwise ensure the built shared library ends up inside the Python package/wheel). Since kernels/portable/__init__.py tries to discover and load the library at runtime, missing installation/packaging will prevent import executorch.kernels.portable from actually registering ops in an installed environment. Add an install rule consistent with the quantized AOT library pattern and align it with the loader’s expected search location.

Suggested change
)
)
install(
TARGETS portable_custom_ops_aot_lib
EXPORT ExecuTorchTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/executorch/extensions/pybindings
)

Copilot uses AI. Check for mistakes.
Comment thread kernels/portable/__init__.py
Comment thread kernels/portable/__init__.py Outdated
Comment thread exir/tests/test_memory_planning.py Outdated
Comment thread exir/tests/test_memory_planning.py Outdated
Comment thread .lintrunner.toml Outdated
@lucylq lucylq force-pushed the lfq.build-portable-custom-ops branch from d40a142 to cbc0f54 Compare February 26, 2026 22:46
Copilot AI review requested due to automatic review settings February 26, 2026 22:51
@lucylq lucylq force-pushed the lfq.build-portable-custom-ops branch from cbc0f54 to 0029e05 Compare February 26, 2026 22:51
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 7 out of 7 changed files in this pull request and generated 3 comments.


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

Comment thread kernels/portable/__init__.py Outdated
Comment thread kernels/portable/__init__.py Outdated
Comment thread CMakeLists.txt Outdated
@lucylq lucylq force-pushed the lfq.build-portable-custom-ops branch from 0029e05 to 363b81e Compare February 26, 2026 22:57
Copilot AI review requested due to automatic review settings February 26, 2026 22:58
@lucylq lucylq force-pushed the lfq.build-portable-custom-ops branch from 363b81e to 003983e Compare February 26, 2026 22:58
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 7 out of 7 changed files in this pull request and generated 3 comments.


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

Comment thread kernels/portable/CMakeLists.txt Outdated
Comment thread kernels/portable/CMakeLists.txt Outdated
Comment thread exir/tests/test_memory_planning.py
@lucylq lucylq force-pushed the lfq.build-portable-custom-ops branch from 003983e to db0252d Compare February 26, 2026 23:01
Copilot AI review requested due to automatic review settings February 26, 2026 23:03
@lucylq lucylq force-pushed the lfq.build-portable-custom-ops branch from db0252d to a433fb8 Compare February 26, 2026 23:03
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 7 out of 7 changed files in this pull request and generated 1 comment.


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

Comment thread kernels/portable/__init__.py Outdated
@lucylq lucylq force-pushed the lfq.build-portable-custom-ops branch from a433fb8 to 0301fa3 Compare February 28, 2026 00:05
Copilot AI review requested due to automatic review settings February 28, 2026 00:25
@lucylq lucylq force-pushed the lfq.build-portable-custom-ops branch from 0301fa3 to 0d07e8e Compare February 28, 2026 00:25
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 8 out of 8 changed files in this pull request and generated no new comments.


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

@meta-codesync meta-codesync Bot merged commit cfb8383 into main Mar 1, 2026
298 of 308 checks passed
@meta-codesync meta-codesync Bot deleted the lfq.build-portable-custom-ops branch March 1, 2026 01:57
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants