Skip to content

Commit 175d178

Browse files
committed
[multimodal] Fix pybind in nightly wheel build
Right now after ``` pip install executorch==1.1.0.dev20251001 --extra-index-url https://download.pytorch.org/whl/nightly ``` Then run ``` python -c "from executorch.extension.llm.runner import MultimodalRunner" ``` I'm getting this error: ``` (executorch) [[email protected] /data/users/larryliu/executorch (main)]$ python -c "from executorch.extension.llm.runner import MultimodalRunner" Traceback (most recent call last): File "/home/larryliu/.conda/envs/executorch/lib/python3.11/site-packages/executorch/extension/llm/runner/__init__.py", line 16, in <module> from executorch.extension.llm.runner._llm_runner import ( # noqa: F401 ImportError: libtorch_python.so: cannot open shared object file: No such file or directory During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<string>", line 1, in <module> File "/home/larryliu/.conda/envs/executorch/lib/python3.11/site-packages/executorch/extension/llm/runner/__init__.py", line 29, in <module> raise RuntimeError( RuntimeError: LLM runner is not installed. Please build ExecuTorch from source with EXECUTORCH_BUILD_PYBIND=ON ``` This PR should fix it by properly point to the installation path of pytorch.
1 parent 07dcd95 commit 175d178

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

extension/llm/runner/CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,26 @@ if(EXECUTORCH_BUILD_PYBIND)
106106
)
107107
if(APPLE)
108108
set(RPATH "@loader_path/../../pybindings")
109+
set(TORCH_RPATH "@loader_path/../../../torch/lib")
109110
else()
110111
set(RPATH "$ORIGIN/../../pybindings")
112+
set(TORCH_RPATH "$ORIGIN/../../../torch/lib")
111113
endif()
112-
set_target_properties(_llm_runner PROPERTIES INSTALL_RPATH ${RPATH})
114+
# Set RPATH to find PyTorch libraries relative to the installation location
115+
# This goes from executorch/extension/pybindings up to site-packages, then to
116+
# torch/lib. This is copied from root level CMakeLists.txt
117+
if(APPLE)
118+
set_target_properties(
119+
_llm_runner PROPERTIES BUILD_RPATH "${TORCH_RPATH}"
120+
INSTALL_RPATH "${RPATH};${TORCH_RPATH}"
121+
)
122+
else()
123+
set_target_properties(
124+
_llm_runner PROPERTIES BUILD_RPATH "${TORCH_RPATH}"
125+
INSTALL_RPATH "${RPATH};${TORCH_RPATH}"
126+
)
127+
endif()
128+
113129
# Add include directories
114130
target_include_directories(
115131
_llm_runner PRIVATE ${_common_include_directories} ${TORCH_INCLUDE_DIRS}

tools/cmake/Utils.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function(get_torch_base_path outVar)
121121
execute_process(
122122
COMMAND
123123
"${PYTHON_EXECUTABLE}" -c
124-
"import importlib.util; print(importlib.util.find_spec('torch').submodule_search_locations[0])"
124+
"\"import importlib.util; print(importlib.util.find_spec('torch').submodule_search_locations[0])\""
125125
OUTPUT_VARIABLE _tmp_torch_path
126126
ERROR_VARIABLE _tmp_torch_path_error
127127
RESULT_VARIABLE _tmp_torch_path_result COMMAND_ECHO STDERR

0 commit comments

Comments
 (0)