-
Notifications
You must be signed in to change notification settings - Fork 607
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
# pyre-strict | ||
|
||
# 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. | ||
import torch as _torch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
# Let users import everything from the C++ _portable_lib extension as if this | ||
# python file defined them. Although we could import these dynamically, it | ||
# wouldn't preserve the static type annotations. | ||
from executorch.extension.pybindings._portable_lib import ( # noqa: F401 | ||
# Disable "imported but unused" (F401) checks. | ||
_create_profile_block, # noqa: F401 | ||
_dump_profile_results, # noqa: F401 | ||
_get_operator_names, # noqa: F401 | ||
_load_bundled_program_from_buffer, # noqa: F401 | ||
_load_for_executorch, # noqa: F401 | ||
_load_for_executorch_from_buffer, # noqa: F401 | ||
_load_for_executorch_from_bundled_program, # noqa: F401 | ||
_reset_profile_results, # noqa: F401 | ||
BundledModule, # noqa: F401 | ||
ExecuTorchModule, # noqa: F401 | ||
) | ||
|
||
# Clean up so that `dir(portable_lib)` is the same as `dir(_portable_lib)` | ||
# (apart from some __dunder__ names). | ||
del _torch |
There was a problem hiding this comment.
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