Repository navigation
jit: discover ROCm via rocm-sdk-devel pip package - #3264
Merged
Merged
Conversation
When aiter runs inside a venv whose only ROCm install is the
rocm-sdk-devel pip package, _find_rocm_home() previously failed in two
ways:
1. Without PATH set, `shutil.which("hipcc")` returns None and
ROCM_HOME falls back to /opt/rocm (or fails outright). Importing
aiter then crashes at module load because cpp_extension eagerly
calls `get_hip_version()` -> `executable_path("hipconfig")`.
2. With the venv on PATH, `which("hipcc")` finds .venv/bin/hipcc,
which is a python wrapper script — not a real binary. realpath()
leaves it in place, so ROCM_HOME becomes the venv root and the
linker gets `-L.venv/lib`, where libamdhip64 does not exist.
Detect the rocm-sdk-devel package via
`importlib.util.find_spec("_rocm_sdk_devel")` and, when it contains a
real `bin/hipconfig`, use its package directory as ROCM_HOME. This
runs ahead of the hipcc-on-PATH lookup so it also fixes case (2).
Also route the bare `hipcc` invocations in core.py
(`hip_flag_checker`, `check_LLVM_MAIN_REVISION`) through
`executable_path("hipcc")`, so JIT-built modules pick up the bundled
compiler in the same setups.
Changes:
- cpp_extension.py: new "Guess #2" in _find_rocm_home() that resolves
ROCM_HOME from the rocm-sdk-devel package before falling back to the
hipcc-on-PATH heuristic.
- core.py: hip_flag_checker and check_LLVM_MAIN_REVISION now resolve
hipcc via executable_path (shlex-quoted for the shell pipeline in
check_LLVM_MAIN_REVISION).
Verified by importing aiter with the venv python and both PATH set
(triggers a clean JIT build) and PATH empty (loads the prebuilt .so);
both succeed.
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves ROCm toolchain discovery for AITER’s JIT flow when ROCm is installed via Python packages inside a virtual environment (not via a system /opt/rocm install), aiming to remove the need to manually set ROCM_PATH/PATH.
Changes:
- Enhance
_find_rocm_home()to prefer therocm-sdk-develpip layout (site-packages/_rocm_sdk_devel) when present. - Update JIT-side hipcc invocations to resolve
hipccviaexecutable_path("hipcc")instead of relying onPATH.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| aiter/jit/utils/cpp_extension.py | Adds _rocm_sdk_devel-based ROCm root detection ahead of hipcc-on-PATH heuristics. |
| aiter/jit/core.py | Switches hipcc subprocess calls to use executable_path() and adds quoting for the shell pipeline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Before this change, `check_LLVM_MAIN_REVISION` invoked a shell pipeline
with a bare `hipcc`; when the binary was missing, the shell exited 127
and `subprocess.CalledProcessError` was caught, returning the older
LLVM revision (554785). The previous commit moved `hipcc` resolution
to `executable_path("hipcc")`, but called it while building `cmd`
outside the `try` — so a missing `hipcc` now raises `AssertionError`
ahead of `subprocess` and the fallback never fires.
Move the resolution inside the `try` and also catch `AssertionError`
from `executable_path` so the original fallback semantics are kept.
Raised by Copilot review on PR #3264.
valarLip
approved these changes
Jun 15, 2026
This was referenced Oct 8, 2026
This was referenced Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Make AITER work out of the box with ROCm installed into venv, without needing to set ROCM_PATH or PATH.
Summary
When aiter runs inside a venv with ROCm python packages,
_find_rocm_home()fails in two distinct ways:No PATH —
shutil.which("hipcc")returnsNone,ROCM_HOMEfalls back to/opt/rocm(or stays unset), and importing aiter crashes at module load:because
cpp_extension.pyeagerly resolvesHIP_VERSIONviaexecutable_path("hipconfig")even when no JIT compile is needed.Venv on PATH —
which("hipcc")returns.venv/bin/hipcc, which is a Python wrapper script (from rocm_sdk_core._cli import hipcc; sys.exit(hipcc())), not a real binary.realpath()leaves it in place, soROCM_HOME = .venvand the linker is invoked with-L.venv/lib, wherelibamdhip64does not exist:Reproducer
Requires
uv(https://docs.astral.sh/uv/) on a host without a system ROCm install, or one where/opt/rocmis not what you intend to use.With this PR, both invocations succeed: case 1 picks up the prebuilt
.so(or, on first run, builds one); case 2 JIT-builds against<VENV>/lib/python*/site-packages/_rocm_sdk_devel/lib/libamdhip64.so.Fix
cpp_extension.py— new "Guess Pa opt 1121 #2" in_find_rocm_home(): detect_rocm_sdk_develviaimportlib.util.find_spec. If it contains a realbin/hipconfig, use the package directory asROCM_HOME. This runs ahead of the hipcc-on-PATH heuristic so it fixes both cases above without changing behavior on systems with a normal ROCm install at/opt/rocmorROCM_HOMEalready set.core.py—hip_flag_checkerandcheck_LLVM_MAIN_REVISIONpreviously invoked barehipccvia subprocess, relying on PATH. They now useexecutable_path("hipcc")so JIT-built modules pick up the bundled compiler.Test plan
mainand passes with this PR./opt/rocminstall and no_rocm_sdk_develpackage,_find_rocm_home()falls through to the existing hipcc-on-PATH //opt/rocmheuristics unchanged.