-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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 <dbort@meta.com>
- Loading branch information
1 parent
773da4d
commit 67d0dd7
Showing
5 changed files
with
59 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters