Skip to content

Add a pure python wrapper fo pybindings.portable_lib #3137

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

dbort
Copy link
Contributor

@dbort dbort commented Apr 18, 2024

Summary:
When installed as a pip wheel, we must import torch before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say import executorch.extension.pybindings.portable_lib

We only need this for OSS, so don't bother doing this for other pybindings targets.

Differential Revision: D56317150

Copy link

pytorch-bot bot commented Apr 18, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 5d20118 with merge base 90d0c1a (image):
💚 Looks good so far! There are no failures yet. 💚

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

This pull request was exported from Phabricator. Differential Revision: D56317150

dbort added a commit to dbort/executorch that referenced this pull request Apr 18, 2024
…3137)

Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Differential Revision: D56317150
@dbort dbort force-pushed the export-D56317150 branch from 32eacf2 to fc3ed1f Compare April 18, 2024 20:38
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56317150

dbort added a commit to dbort/executorch that referenced this pull request Apr 18, 2024
…3137)

Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Differential Revision: D56317150
@dbort dbort force-pushed the export-D56317150 branch from fc3ed1f to 6fbb967 Compare April 18, 2024 20:41
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56317150

dbort added a commit to dbort/executorch that referenced this pull request Apr 18, 2024
…3137)

Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Differential Revision: D56317150
@dbort dbort force-pushed the export-D56317150 branch from 6fbb967 to 72c1c39 Compare April 18, 2024 21:40
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56317150

dbort added a commit to dbort/executorch that referenced this pull request Apr 18, 2024
…3137)

Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Differential Revision: D56317150
@dbort dbort force-pushed the export-D56317150 branch from 72c1c39 to 3a6280d Compare April 18, 2024 21:42
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56317150

dbort added a commit that referenced this pull request Apr 18, 2024
Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Differential Revision: D56317150
dbort added a commit that referenced this pull request Apr 18, 2024
Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Differential Revision: D56317150
dbort added a commit that referenced this pull request Apr 19, 2024
Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Differential Revision: D56317150
@dbort dbort force-pushed the export-D56317150 branch from 3a6280d to 681f2bd Compare April 20, 2024 00:50
dbort added a commit to dbort/executorch that referenced this pull request Apr 20, 2024
…3137)

Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Differential Revision: D56317150
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56317150

dbort added a commit to dbort/executorch that referenced this pull request Apr 20, 2024
…3137)

Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Differential Revision: D56317150
@dbort dbort force-pushed the export-D56317150 branch from 681f2bd to a26ca55 Compare April 20, 2024 00:50
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56317150

dbort added a commit that referenced this pull request Apr 20, 2024
…en,portable}_lib (#3137)

Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Differential Revision: D56317150
Copy link

@mikekgfb mikekgfb left a comment

Choose a reason for hiding this comment

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

Thank you!

@dbort dbort changed the title Add a pure python wrapper fo pybindings.{aten,portable}_lib Add a pure python wrapper fo pybindings.portable_lib Apr 20, 2024
Copy link
Contributor

@larryliu0820 larryliu0820 left a comment

Choose a reason for hiding this comment

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

Looks good. I’m thinking is there a way to setup a test? I want to see if we are giving proper error message to user, if they don’t have torch installed properly.

Copy link
Contributor

@orionr orionr left a comment

Choose a reason for hiding this comment

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

Looks good! Did a real review here.

# the pybindings shared library extension. This will load libtorch.so and
# related libs, ensuring that the pybindings lib can resolve those runtime
# dependencies.
import torch as _torch
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we rely on ATen for the pybind? I'm guessing including torch here is going to pull all of that in. Okay, but just checking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do, so that users can use normal torch tensors for their inputs and outputs, making it easier for them to use.

@@ -46,8 +46,9 @@ executorch_pybindings(
executorch_pybindings(
compiler_flags = ["-std=c++17"],
cppdeps = PORTABLE_MODULE_DEPS + MODELS_ATEN_OPS_LEAN_MODE_GENERATED_LIB,
python_module_name = "portable_lib",
types = ["//executorch/extension/pybindings:pybindings_types_gen[portable_lib.pyi]"],
# Give this an underscore prefix because it has a pure python wrapper.
Copy link
Contributor

Choose a reason for hiding this comment

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

I must say this is pretty cool

dbort added a commit to dbort/executorch that referenced this pull request Apr 22, 2024
Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Reviewed By: orionr, mikekgfb

Differential Revision: D56317150
@dbort dbort force-pushed the export-D56317150 branch from a26ca55 to 797f608 Compare April 22, 2024 16:49
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56317150

dbort added a commit to dbort/executorch that referenced this pull request Apr 22, 2024
Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Reviewed By: orionr, mikekgfb

Differential Revision: D56317150
@dbort dbort force-pushed the export-D56317150 branch from 797f608 to 700e5fa Compare April 22, 2024 16:50
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56317150

dbort added a commit that referenced this pull request Apr 22, 2024
)

Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Reviewed By: orionr, mikekgfb

Differential Revision: D56317150
Summary:

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Reviewed By: orionr, mikekgfb

Differential Revision: D56317150
@dbort dbort force-pushed the export-D56317150 branch from 700e5fa to 5d20118 Compare April 22, 2024 19:27
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D56317150

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 969aa96.

@dbort
Copy link
Contributor Author

dbort commented Apr 22, 2024

@pytorchbot cherry-pick --onto release/0.2 -c release

@dbort dbort deleted the export-D56317150 branch April 22, 2024 21:31
pytorchbot pushed a commit that referenced this pull request Apr 22, 2024
Summary:
Pull Request resolved: #3137

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Reviewed By: orionr, mikekgfb

Differential Revision: D56317150

fbshipit-source-id: 920382636732aa276c25a76163afb7d28b1846d0
(cherry picked from commit 969aa96)
@pytorchbot
Copy link
Collaborator

Cherry picking #3137

The cherry pick PR is at #3218

Details for Dev Infra team Raised by workflow job

@dbort dbort mentioned this pull request Apr 22, 2024
guangy10 pushed a commit that referenced this pull request Apr 22, 2024
Summary:
Pull Request resolved: #3137

When installed as a pip wheel, we must import `torch` before trying to import the pybindings shared library extension. This will load libtorch.so and related libs, ensuring that the pybindings lib can resolve those runtime dependencies.

So, add a pure python wrapper that lets us do this when users say `import executorch.extension.pybindings.portable_lib`

We only need this for OSS, so don't bother doing this for other pybindings targets.

Reviewed By: orionr, mikekgfb

Differential Revision: D56317150

fbshipit-source-id: 920382636732aa276c25a76163afb7d28b1846d0
(cherry picked from commit 969aa96)

Co-authored-by: Dave Bort <[email protected]>
This was referenced Apr 25, 2024
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. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants