-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a pure python wrapper fo pybindings.{aten,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
- Loading branch information
Showing
4 changed files
with
49 additions
and
6 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,32 @@ | ||
# 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 | ||
|
||
# Import the actual C++ extension that this file wraps. | ||
from executorch.extension.pybindings import _portable_lib | ||
|
||
# Let users import everything from _portable_lib as if this python file defined | ||
# them. Normally we'd exclude names starting with `_`, but _portable_lib | ||
# contains names like `_load_for_executorch` that we need to expose. | ||
__all__ = [name for name in dir(_portable_lib) if not name.startswith("__")] | ||
|
||
# The underscores also complicate things because it means we can't use `import | ||
# *` to bring them into our namespace. | ||
for _name in __all__: | ||
exec(f"from executorch.extension.pybindings._portable_lib import {_name}") | ||
|
||
# Clean up so that `dir(portable_lib)` is the same as `dir(_portable_lib)` | ||
# (modulo some __dunder__ names). | ||
del _name | ||
del _portable_lib | ||
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