Skip to content

Load ROCm from the SDK wheels the torch wheel was built against - #4

Merged
cyyever merged 1 commit into
trimfrom
rocm-wheel-runtime
Oct 23, 2026
Merged

cyyever merged 1 commit into
trimfrom
rocm-wheel-runtime

Conversation

@cyyever

@cyyever cyyever commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Draft until reviewed.

Agent details (AI-generated)

Problem. ROCm wheels built with PYTORCH_ROCM_EXTERNAL_SDK=1 declare no ROCm dependency and ship no torch/_rocm_init.py. import torch therefore finds ROCm only through LD_LIBRARY_PATH or the host's ld.so.conf. On a Breadboard guest that means the accelerator pack's ROCm 10.0 rather than our patched 10.1 SDK. Without LD_LIBRARY_PATH the import fails on librocm-openblas.so.0.

Change.

  • The build reads the SDK wheels' version from PYTORCH_ROCM_SDK_VERSION.
  • tools/metadata/dependencies.py pins rocm[libraries] to that version.
  • torch/CMakeLists.txt writes the _rocm_init.py that the existing install rule and torch/__init__.py already expect, so import torch preloads the SDK libraries through rocm_sdk.initialize_process and checks the version. The preload list is TheRock's build_prod_wheels.py list without hipdnn, which this SDK does not build.
  • PYTORCH_ROCM_EXTERNAL_SDK is removed.

Needs a breadkernel change. accelerator-wheels-rocm.toml must set PYTORCH_ROCM_SDK_VERSION to the SDK wheel version and drop PYTORCH_ROCM_EXTERNAL_SDK. Without it, the fallback pins whatever rocm is installed in the build venv, which is 10.0.0 today.

Tested. The CMake block was run with and without the variable; the dependency provider was exercised. On a gfx1201 sandbox, with the generated file added to the published gdb71170c wheel, import torch works without LD_LIBRARY_PATH and all ROCm libraries load from the rocm_sdk wheels. A full wheel build with the change has not been run.

🤖 Generated with Claude Code

ROCm wheels built against an unpacked TheRock SDK (PYTORCH_ROCM_EXTERNAL_SDK)
declared no ROCm dependency and shipped no torch/_rocm_init.py, so
`import torch` resolved librocm-openblas and the HIP libraries only through
LD_LIBRARY_PATH or whatever ROCm the host's ld.so.conf exposed. On a
Breadboard guest that is the accelerator pack's ROCm 10.0, not the 10.1 SDK
the wheel was built and patched against; without LD_LIBRARY_PATH the import
fails on librocm-openblas.so.0.

The build now takes the SDK wheels' version from PYTORCH_ROCM_SDK_VERSION.
tools/metadata/dependencies.py pins rocm[libraries] to it, and
torch/CMakeLists.txt writes the _rocm_init.py that the existing install rule
and torch/__init__.py already expect, so `import torch` preloads the SDK
libraries from those wheels through rocm_sdk.initialize_process and checks
the version. The preload list is TheRock's build_prod_wheels.py list minus
hipdnn, which this SDK does not build. PYTORCH_ROCM_EXTERNAL_SDK is gone;
the alternative of keeping it and fixing the guest's ld.so.conf would leave
torch tied to whatever ROCm the host provides.

Test Plan:

```
cmake -P test.cmake   # the new block, with and without PYTORCH_ROCM_SDK_VERSION
python -c 'import dependencies; ...'   # rocm[libraries]==<version>
env -u LD_LIBRARY_PATH python -c 'import torch; ...'
```

With the generated _rocm_init.py added to the published gdb71170c wheel on
a gfx1201 sandbox, `import torch` succeeds without LD_LIBRARY_PATH and
/proc/self/maps shows libamdhip64, libhsa-runtime64, librocblas, libMIOpen
and librocm-openblas loaded from the rocm_sdk wheels. A full wheel build
with the change was not run.

Authored with an AI assistant (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cyyever
cyyever marked this pull request as ready for review October 23, 2026 05:12
@cyyever
cyyever merged commit 6ff2913 into trim Oct 23, 2026
17 checks passed
@cyyever
cyyever deleted the rocm-wheel-runtime branch October 23, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant