|
1 | 1 | # flake8: noqa: F401
|
2 | 2 |
|
3 |
| -# pyre-fixme[21]: Could not find module `executorch.pytree.pybindings`. |
4 |
| -# @manual=//executorch/pytree:pybindings |
5 |
| -from executorch.pytree.pybindings import ( |
6 |
| - broadcast_to_and_flatten as broadcast_to_and_flatten, |
7 |
| - from_str as from_str, |
8 |
| - register_custom as register_custom, |
9 |
| - tree_flatten as tree_flatten, |
10 |
| - tree_map as tree_map, |
11 |
| - tree_unflatten as tree_unflatten, |
12 |
| - TreeSpec as TreeSpec, |
13 |
| -) |
| 3 | +import warnings |
| 4 | + |
| 5 | +try: |
| 6 | + """ |
| 7 | + Internally we link the respective c++ library functions but for the OSS pip |
| 8 | + build we will just use the python library for now. The python library is not |
| 9 | + exactly the same so it will not work for the runtime, but it'll be fine for |
| 10 | + now as in most cases the runtime will not need it. |
| 11 | + """ |
| 12 | + |
| 13 | + # pyre-fixme[21]: Could not find module `executorch.pytree.pybindings`. |
| 14 | + # @manual=//executorch/pytree:pybindings |
| 15 | + from executorch.pytree.pybindings import ( |
| 16 | + broadcast_to_and_flatten as broadcast_to_and_flatten, |
| 17 | + from_str as from_str, |
| 18 | + register_custom as register_custom, |
| 19 | + tree_flatten as tree_flatten, |
| 20 | + tree_map as tree_map, |
| 21 | + tree_unflatten as tree_unflatten, |
| 22 | + TreeSpec as TreeSpec, |
| 23 | + ) |
| 24 | +except: |
| 25 | + warnings.warn( |
| 26 | + "Unable to import executorch.pytree, using native torch pytree instead." |
| 27 | + ) |
| 28 | + |
| 29 | + from torch.utils._pytree import ( |
| 30 | + _broadcast_to_and_flatten, |
| 31 | + _register_pytree_node, |
| 32 | + pytree_to_str, |
| 33 | + str_to_pytree, |
| 34 | + tree_flatten, |
| 35 | + tree_map, |
| 36 | + tree_unflatten, |
| 37 | + TreeSpec, |
| 38 | + ) |
| 39 | + |
| 40 | + broadcast_to_and_flatten = _broadcast_to_and_flatten |
| 41 | + from_str = str_to_pytree |
| 42 | + register_custom = _register_pytree_node |
| 43 | + TreeSpec.to_str = pytree_to_str # pyre-ignore |
0 commit comments