[issue] MIGraphX 2.17 pip wheels fail to load: executables keep build machine RUNPATH
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 333
- Forks
- 150
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 54
Description
After installing the MIGraphX 2.17 wheel from the AMD index
pip install "migraphx==2.17.0+rocm10.0.0" \
--extra-index-url https://stable.repo.amd.com/rocm/migraphx/whl-next/
three things fail:
migraphx-driverdoes not startimport migraphxraisesImportError- the MIGraphX execution provider does not register in ONNX Runtime
All libraries are present in site-packages, but the shipped executables have a RUNPATH
pointing at build machine paths. The same MIGraphX installed from deb packages works fine.
Verified in a clean ubuntu:24.04 container with no system ROCm installed.
Reproducer
docker run --rm --device=/dev/kfd --device=/dev/dri --group-add video ubuntu:24.04 bash -c '
apt-get -qq update && apt-get -qq install -y python3.12-venv
python3.12 -m venv /venv && . /venv/bin/activate
pip install "migraphx==2.17.0+rocm10.0.0" \
--extra-index-url https://stable.repo.amd.com/rocm/migraphx/whl-next/
migraphx-driver --version
# error while loading shared libraries: libhiprtc.so.7: cannot open shared object file
python -c "import migraphx"
# ImportError: libhiprtc.so.7: cannot open shared object file
pip install "rocm[libraries,device-gfx1201]==10.0.0" \
--extra-index-url https://stable.repo.amd.com/rocm/whl-next/
migraphx-driver --version
# same error, libhiprtc.so.7 is now in site-packages but still not found
'
Installing the ROCm runtime does not change the error. The ONNX Runtime plugin EP fails the same way:
pip install onnxruntime-ep-migraphx==1.0.0+rocm10.0.0 \
--extra-index-url https://stable.repo.amd.com/rocm/onnxruntime/whl-next/
import onnxruntime as ort, onnxruntime_ep_migraphx as m
for n, p in zip(m.get_ep_names(), m.get_library_paths()):
ort.register_execution_provider_library(n, p)
# FAIL : Failed to load library .../libmigraphx-ep.so
# with error: libmigraphx_c.so.3: cannot open shared object file
print(ort.get_available_providers())
# without the register call there is no error at all, the list is just
# ['AzureExecutionProvider', 'CPUExecutionProvider']
RUNPATH
The deb row is MIGraphX 2.15 from the ROCm 7.2.4 apt repository
| File | RUNPATH | Loads |
|---|---|---|
deb /opt/rocm/bin/migraphx-driver |
$ORIGIN/../lib:$ORIGIN/../lib:$ORIGIN/../lib/migraphx/lib |
yes |
wheel migraphx_libs/libmigraphx_c.so.3 |
$ORIGIN:$ORIGIN/../_rocm_sdk_libraries/lib:$ORIGIN/../_rocm_sdk_devel/lib:$ORIGIN/../_rocm_sdk_core/lib:/opt/rocm/lib |
yes |
wheel migraphx_libs/_bin/migraphx-driver |
/app/AMDMIGraphX/build/lib:/opt/python/lib/python3.12/site-packages/_rocm_sdk_devel/lib: |
no |
wheel onnxruntime_ep_migraphx/libmigraphx-ep.so |
/opt/_internal/cpython-3.12.14/lib/python3.12/site-packages/_rocm_sdk_devel/lib:/opt/_internal/cpython-3.12.14/lib/python3.12/site-packages/_rocm_sdk_devel/lib/migraphx/lib:/staging/onnxruntime-sdk/lib:/opt/rocm/lib: |
no |
Inside the same wheel the library is patched with $ORIGIN and the executable next to it is not,
so this looks like a missing patchelf step for binaries. migraphx-driver cannot find
libmigraphx_py.so, which sits in its parent directory. The 2.16 wheel has the same RUNPATH.
Workaround
export LD_LIBRARY_PATH=$(find $VIRTUAL_ENV/lib/python3.12/site-packages -name '*.so*' -printf '%h\n' | sort -u | paste -sd:)
This fixes migraphx-driver and import migraphx. The EP needs a ctypes preload
with RTLD_GLOBAL over three libraries instead:
import ctypes, pathlib, sys
sp = pathlib.Path(sys.prefix) / "lib/python3.12/site-packages"
for lib in ("_rocm_sdk_core/lib/libamdhip64.so.7", "migraphx_libs/libmigraphx_c.so.3"):
ctypes.CDLL(str(sp / lib), mode=ctypes.RTLD_GLOBAL)
ctypes.CDLL(str(next((sp / "onnxruntime/capi").glob("libonnxruntime.so.1.*"))), mode=ctypes.RTLD_GLOBAL)
# after this MIGraphXExecutionProvider shows up
Environment
- GPU: gfx1201 (R9700 AI PRO)
- CPU: AMD Ryzen Threadripper PRO 7975WX, 32 cores / 64 threads
- Host OS: Ubuntu 24.04.3 LTS, kernel 7.0.0-30. Reproduced in
ubuntu:24.04with no system ROCm - Python 3.12, MIGraphX 2.17.0+rocm10.0.0 and 2.16.0+rocm7.14.0, ONNX Runtime 1.29.0
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure in the clean Ubuntu 24.04 container, then inspect the RUNPATH of the wheel's migraphx-driver and ONNX Runtime EP binaries alongside the patched library. Trace the wheel build's patchelf step; done means the shipped executables and EP load their site-packages libraries without LD_LIBRARY_PATH or ctypes preloads.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, docker, python
- Domain
- build-system, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100