Commit edacadc
authored
Fix _llm_runner.so RPATH for pip wheel installs (#17772)
Summary
from executorch.extension.llm.runner import TextLLMRunner fails on pip
wheel installs because _llm_runner.so cannot find _portable_lib.so or
its transitive libtorch*.so dependencies at runtime.
Root cause — two issues:
1. Missing torch preload: __init__.py imported torch after _llm_runner,
so libtorch*.so shared libs weren't loaded when the dynamic linker tried
to resolve _llm_runner.so's dependencies. The existing
portable_lib.py already solves this correctly by importing torch first.
2. Incomplete RPATH + wrong RPATH property: The RPATH on _llm_runner.so
only included ../../pybindings (to find _portable_lib.so) but was
missing ../../../../torch/lib (to find libtorch*.so). More critically,
only
INSTALL_RPATH was set — but pip install never runs cmake --install; it
copies .so files directly from the build directory, so only BUILD_RPATH
takes effect. The portable_lib target already handles this correctly
by setting both properties.
Fixes:
- extension/llm/runner/__init__.py: Move import torch before the
_llm_runner import to preload libtorch shared libs.
- extension/llm/runner/CMakeLists.txt: Add torch/lib to the RPATH, and
set both BUILD_RPATH and INSTALL_RPATH so the paths are embedded
regardless of whether the .so is copied from the build tree or installed
via
CMake.
Test plan
- Build from source with EXECUTORCH_BUILD_PYBIND=ON
- Remove build directories (pip-out/, cmake-out/) to simulate a clean
pip install environment
- Verify RPATH with otool -l _llm_runner*.so | grep -A2 RPATH (macOS) —
confirms @loader_path/../../pybindings and
@loader_path/../../../../torch/lib are present
- Verify from executorch.extension.llm.runner import TextLLMRunner
succeeds1 parent cfb8383 commit edacadc
2 files changed
Lines changed: 9 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
127 | 129 | | |
128 | | - | |
| 130 | + | |
129 | 131 | | |
130 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
131 | 135 | | |
132 | 136 | | |
133 | 137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | | - | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
0 commit comments