Skip to content

[pybind] Find portable_lib.so in pip package during cmake build #5961

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

Closed
wants to merge 1 commit into from

Conversation

larryliu0820
Copy link
Contributor

  • Rename _portable_lib.cpython-3.<distribution info>.so to _portable_lib.so so it can be found by CMake find_library(). This can be achieved by setting SETUPTOOLS_EXT_SUFFIX.
  • Since executorch-config.cmake is also being used to find installed libraries such as executorch.a, xnnpack_backend.a, add a condition to tell if executorch-config.cmake is being used in cmake-out or site-packages.

* Rename `_portable_lib.cpython-3.<distribution info>.so` to
  `_portable_lib.so` so it can be found by CMake `find_library()`. This
can be achieved by setting `SETUPTOOLS_EXT_SUFFIX`.
* Since `executorch-config.cmake` is also being used to find installed
  libraries such as `executorch.a`, `xnnpack_backend.a`, add a condition
to tell if `executorch-config.cmake` is being used in cmake-out or
site-packages.
Copy link

pytorch-bot bot commented Oct 7, 2024

🔗 Helpful Links

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

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

✅ You can merge normally! (2 Unrelated Failures)

As of commit 701c1b1 with merge base 0a11e99 (image):

UNSTABLE - The following jobs failed but were likely due to flakiness present on trunk and has been marked as unstable:

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 Oct 7, 2024
@facebook-github-bot
Copy link
Contributor

@larryliu0820 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

set(EXECUTORCH_LIBRARIES)
if(_portable_lib_LIBRARY)
# Assuming current file is <site-packages>/executorch/executorch-config.cmake
message(WARNING "portable library is found")
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of these should use STATUS instead of WARNING since they're just informational

@facebook-github-bot
Copy link
Contributor

@larryliu0820 merged this pull request in 7337f8e.

larryliu0820 added a commit that referenced this pull request Oct 8, 2024
Addressing comments in #5961.

* Separate out `executorch-wheel-config.cmake` from
  `executorch-config.cmake`.
* Hardcode the envrionment variable `SETUPTOOLS_EXT_SUFFIX` in
  `setup.py`.
larryliu0820 added a commit that referenced this pull request Oct 8, 2024
Addressing comments in #5961.

* Separate out `executorch-wheel-config.cmake` from
  `executorch-config.cmake`.
* Hardcode the envrionment variable `SETUPTOOLS_EXT_SUFFIX` in
  `setup.py`.
facebook-github-bot pushed a commit that referenced this pull request Oct 8, 2024
Summary:
Addressing comments in #5961.

* Separate out `executorch-wheel-config.cmake` from `executorch-config.cmake`.
* Hardcode the envrionment variable `SETUPTOOLS_EXT_SUFFIX` in `setup.py`.

Pull Request resolved: #5965

Reviewed By: dbort

Differential Revision: D64017947

Pulled By: larryliu0820

fbshipit-source-id: 0bdff5e2d2ec5873540d1b701595c7a316e84e80
@larryliu0820
Copy link
Contributor Author

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

pytorchbot pushed a commit that referenced this pull request Oct 10, 2024
Summary:
* Rename `_portable_lib.cpython-3.<distribution info>.so` to `_portable_lib.so` so it can be found by CMake `find_library()`. This can be achieved by setting `SETUPTOOLS_EXT_SUFFIX`.
* Since `executorch-config.cmake` is also being used to find installed libraries such as `executorch.a`, `xnnpack_backend.a`, add a condition to tell if `executorch-config.cmake` is being used in cmake-out or site-packages.

Pull Request resolved: #5961

Reviewed By: metascroy

Differential Revision: D64014291

Pulled By: larryliu0820

fbshipit-source-id: 2757f2883d3f836e9efd45676f792c12f742e63d
(cherry picked from commit 7337f8e)
@pytorchbot
Copy link
Collaborator

Cherry picking #5961

The cherry pick PR is at #6141 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

pytorchbot pushed a commit that referenced this pull request Oct 10, 2024
Summary:
Addressing comments in #5961.

* Separate out `executorch-wheel-config.cmake` from `executorch-config.cmake`.
* Hardcode the envrionment variable `SETUPTOOLS_EXT_SUFFIX` in `setup.py`.

Pull Request resolved: #5965

Reviewed By: dbort

Differential Revision: D64017947

Pulled By: larryliu0820

fbshipit-source-id: 0bdff5e2d2ec5873540d1b701595c7a316e84e80
(cherry picked from commit 1327090)
larryliu0820 added a commit that referenced this pull request Oct 11, 2024
Summary:
* Rename `_portable_lib.cpython-3.<distribution info>.so` to `_portable_lib.so` so it can be found by CMake `find_library()`. This can be achieved by setting `SETUPTOOLS_EXT_SUFFIX`.
* Since `executorch-config.cmake` is also being used to find installed libraries such as `executorch.a`, `xnnpack_backend.a`, add a condition to tell if `executorch-config.cmake` is being used in cmake-out or site-packages.

Pull Request resolved: #5961

Reviewed By: metascroy

Differential Revision: D64014291

Pulled By: larryliu0820

fbshipit-source-id: 2757f2883d3f836e9efd45676f792c12f742e63d
larryliu0820 added a commit that referenced this pull request Oct 11, 2024
Summary:
Addressing comments in #5961.

* Separate out `executorch-wheel-config.cmake` from `executorch-config.cmake`.
* Hardcode the envrionment variable `SETUPTOOLS_EXT_SUFFIX` in `setup.py`.

Pull Request resolved: #5965

Reviewed By: dbort

Differential Revision: D64017947

Pulled By: larryliu0820

fbshipit-source-id: 0bdff5e2d2ec5873540d1b701595c7a316e84e80
@larryliu0820 larryliu0820 mentioned this pull request Oct 11, 2024
larryliu0820 added a commit that referenced this pull request Oct 11, 2024
Summary:
* Rename `_portable_lib.cpython-3.<distribution info>.so` to `_portable_lib.so` so it can be found by CMake `find_library()`. This can be achieved by setting `SETUPTOOLS_EXT_SUFFIX`.
* Since `executorch-config.cmake` is also being used to find installed libraries such as `executorch.a`, `xnnpack_backend.a`, add a condition to tell if `executorch-config.cmake` is being used in cmake-out or site-packages.

Pull Request resolved: #5961

Reviewed By: metascroy

Differential Revision: D64014291

Pulled By: larryliu0820

fbshipit-source-id: 2757f2883d3f836e9efd45676f792c12f742e63d
larryliu0820 added a commit that referenced this pull request Oct 11, 2024
Summary:
Addressing comments in #5961.

* Separate out `executorch-wheel-config.cmake` from `executorch-config.cmake`.
* Hardcode the envrionment variable `SETUPTOOLS_EXT_SUFFIX` in `setup.py`.

Pull Request resolved: #5965

Reviewed By: dbort

Differential Revision: D64017947

Pulled By: larryliu0820

fbshipit-source-id: 0bdff5e2d2ec5873540d1b701595c7a316e84e80
larryliu0820 added a commit that referenced this pull request Oct 11, 2024
Summary:
* Rename `_portable_lib.cpython-3.<distribution info>.so` to `_portable_lib.so` so it can be found by CMake `find_library()`. This can be achieved by setting `SETUPTOOLS_EXT_SUFFIX`.
* Since `executorch-config.cmake` is also being used to find installed libraries such as `executorch.a`, `xnnpack_backend.a`, add a condition to tell if `executorch-config.cmake` is being used in cmake-out or site-packages.

Pull Request resolved: #5961

Reviewed By: metascroy

Differential Revision: D64014291

Pulled By: larryliu0820

fbshipit-source-id: 2757f2883d3f836e9efd45676f792c12f742e63d
larryliu0820 added a commit that referenced this pull request Oct 11, 2024
Summary:
Addressing comments in #5961.

* Separate out `executorch-wheel-config.cmake` from `executorch-config.cmake`.
* Hardcode the envrionment variable `SETUPTOOLS_EXT_SUFFIX` in `setup.py`.

Pull Request resolved: #5965

Reviewed By: dbort

Differential Revision: D64017947

Pulled By: larryliu0820

fbshipit-source-id: 0bdff5e2d2ec5873540d1b701595c7a316e84e80
larryliu0820 added a commit that referenced this pull request Oct 11, 2024
* Add MethodMeta object for python visibility (#5571)

Summary:
Pull Request resolved: #5571

Some clients and consumers of the Executorch program files (.pte) were
requesting ways to access metadata like the sizes of tensors and the number
of bytes they needed.
When I told them how to access them in C++, they requested Python wrappers
since they had processing scripts written in Python.

Add some implementations of MethodMeta and TensorInfo methods.
Note that these become more expensive than in C++ because they need to
allocate python objects, but I doubt these are used in
performance-sensitive applications anyway. And dealing with
lifetimes of mixed C++/Python objects is complex, so I favored simple lifetimes.

Reviewed By: dbort

Differential Revision: D63288433

fbshipit-source-id: af775120a8ebd9bf455671a8ce1f158259aa50e6

* Add mapping from C++ program::verification to Python (#5915)

Summary:
As titled. This enables
`portable_lib._load_for_executorch[_from_buffer]` to accept `Program::Verification` argument.

See added test, now we can do something like:

```
from executorch.extension.pybindings.portable_lib import Verification
module = load_fn(
  exported_program.buffer,
  enable_etdump=False,
  debug_buffer_size=0,
  program_verification=Verification.Minimal,
)
```

Pull Request resolved: #5915

Test Plan: See unit test

Reviewed By: dbort

Differential Revision: D63987538

Pulled By: larryliu0820

fbshipit-source-id: b68d8d1149e2d46b90544679707f420179e72b19

* Find portable_lib.so in pip package during cmake build (#5961)

Summary:
* Rename `_portable_lib.cpython-3.<distribution info>.so` to `_portable_lib.so` so it can be found by CMake `find_library()`. This can be achieved by setting `SETUPTOOLS_EXT_SUFFIX`.
* Since `executorch-config.cmake` is also being used to find installed libraries such as `executorch.a`, `xnnpack_backend.a`, add a condition to tell if `executorch-config.cmake` is being used in cmake-out or site-packages.

Pull Request resolved: #5961

Reviewed By: metascroy

Differential Revision: D64014291

Pulled By: larryliu0820

fbshipit-source-id: 2757f2883d3f836e9efd45676f792c12f742e63d

* Improve pip package build (#5965)

Summary:
Addressing comments in #5961.

* Separate out `executorch-wheel-config.cmake` from `executorch-config.cmake`.
* Hardcode the envrionment variable `SETUPTOOLS_EXT_SUFFIX` in `setup.py`.

Pull Request resolved: #5965

Reviewed By: dbort

Differential Revision: D64017947

Pulled By: larryliu0820

fbshipit-source-id: 0bdff5e2d2ec5873540d1b701595c7a316e84e80

* Let find_package(executorch) find the correct include directory (#6102)

Summary:
There's a typo in `executorch-wheel-config.cmake` that points to the wrong `include` path:
```
<site-packages>/executorch/share/cmake/include
```

Where it actually should be
```
<site-packages>/executorch/include
```

Fixing this issue. Verified it on [build_torchao_ops.sh](https://github.com/pytorch/ao/blob/main/torchao/experimental/build_torchao_ops.sh)

Pull Request resolved: #6102

Reviewed By: lucylq

Differential Revision: D64189337

Pulled By: larryliu0820

fbshipit-source-id: 13033587f5499537623995b8f9457fb47d780340

* New Runtime pybind API (#6063)

Summary:
Based on this proposal: https://docs.google.com/document/d/10Q4-pt97inQQtFf-FjjwhMaDXXCfk1zGy6V6EkygNUY/edit#heading=h.fcrpnrtb6cud

Historically our pybinding APIs are not following the same C++ modeling
(Program, Method etc) and hence it's hard to use and easy to hit
footguns - for example, if we load the program and return it from a
python method, it goes out of the scope and releases the memory.

This effort is to create Pybind APIs that resembles C++ objects so it's
less confusing to the users.

Add the following python classes:
* `Runtime`: a singleton object hosting methods like `load_program`.
  Returns a `Program` object when calling `load_program`. Also exposes
  the operator registry
* `Program`: each pte file should have one `Program` object. Most
  important method is `load_method` which returns a `Method` object. It
  has a property `method_names` where we can inspect what methods are
  inside this .pte file.
* `Method`: one object per method name in a given `Program`. Exposes
  `execute` which takes in pytree flattened torch tensors as input and
  return pytree flattened output. It also exposes `MethodMeta` for users
  to inspect more information regarding input/output of this method.

Pull Request resolved: #6063

Reviewed By: dbort

Differential Revision: D64132360

Pulled By: larryliu0820

fbshipit-source-id: a2f35edc5fd8c200df0812a693e454d66d6a907e

* Lint

* Fix test_pybindings.py

---------

Co-authored-by: Riley Dulin <[email protected]>
larryliu0820 added a commit that referenced this pull request Oct 18, 2024
…wheel

Summary: Initially our portable lib prebuilt library is named as:

```
_portable_lib.cpython-310-x86_64-linux-gnu.so
```
Where it includes an `EXT_SUFFIX` `cpython-310-x86_64-linux-gnu` consists of architecture and build OS
information.

This is enforced by `setuptools` following PEP 3149 and there's no good
way to change this behavior.

which is easier to be found by `find_package()` macro in CMake.

However #5961 is breaking the other prebuilt libraries such as
`libcustom_ops_aot_lib.so` which depends on the original
`_portable_lib.cpython-310-x86_64-linux-gnu.so` name in its RPATH.

This PR is a fix that reverts #5961 and restore the full name during
packaging, but try to match the `EXT_SUFFIX` in CMake to be able to find
the .so file.

Test Plan:

```bash
python -c "from executorch.extension.llm.custom_ops import
sdpa_with_kv_cache"
```

Does not throw `_portable_lib.cpython-310-x86_64-linux-gnu.so` not found
error.

Reviewers:

Subscribers:

Tasks:

Tags:
facebook-github-bot pushed a commit that referenced this pull request Oct 19, 2024
…#6363)

Summary:
Initially our portable lib prebuilt library is named as:

```
_portable_lib.cpython-310-x86_64-linux-gnu.so
```
Where it includes an `EXT_SUFFIX` `cpython-310-x86_64-linux-gnu` consists of architecture and build OS information.

This is enforced by `setuptools` following PEP 3149 and there's no good way to change this behavior.

#5961 was an attempt to rename the .so filename at **packaging** stage to `_portable_lib.so`, so that it is easier to be found by `find_package()` macro in CMake.

However #5961 is breaking the other prebuilt libraries such as `libcustom_ops_aot_lib.so` which depends on the original `_portable_lib.cpython-310-x86_64-linux-gnu.so` name in its RPATH.

This PR is a fix that reverts #5961 and restore the full name during packaging, but try to match the `EXT_SUFFIX` in CMake to be able to find the .so file.

Pull Request resolved: #6363

Test Plan:
```bash
EXECUTORCH_BUILD_PYBIND=ON python setup.py bdist_wheel # build wheel including _portable_lib.*.so
pip install dist/executorch-0.5.0a0+7510f8c-cp310-cp310-linux_x86_64.whl
python -c "from executorch.extension.llm.custom_ops import sdpa_with_kv_cache"

# Run torchao script to make sure find_package() works
push ao/torchao/experimental
bash build_torchao_ops.sh executorch
```

Does not throw `_portable_lib.cpython-310-x86_64-linux-gnu.so` not found error.

Reviewed By: kirklandsign

Differential Revision: D64635137

Pulled By: larryliu0820

fbshipit-source-id: 7e54ea15361ae63acb8324538ea4982e95d6f07a
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. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants