fix(rocm): unset empty HSA_OVERRIDE_GFX_VERSION before torch loads#864
Open
Xarianne wants to merge 1 commit into
Open
fix(rocm): unset empty HSA_OVERRIDE_GFX_VERSION before torch loads#864Xarianne wants to merge 1 commit into
Xarianne wants to merge 1 commit into
Conversation
Docker compose sets HSA_OVERRIDE_GFX_VERSION=${HSA_OVERRIDE_GFX_VERSION:-}
which results in an empty string when not provided. An empty string is
not the same as unset - ROCm treats it as 'force-empty' and no GPU is
detected, even natively supported ones (e.g. gfx1201 / RX 9070 on ROCm 7.2).
Pop the env var when it is empty, before torch loads, so ROCm auto-detects
the GPU correctly.
Tested on RX 9070 (gfx1201) with ROCm 7.2 and PyTorch 2.12.1+rocm7.2.
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a guard in backend/app.py that removes HSA_OVERRIDE_GFX_VERSION from the process environment when it is unset or empty, executed before existing ROCm/GPU detection and override logic. ChangesHSA Override Env Var Fix
Estimated code review effort: 1 (Trivial) | ~3 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Problem
When running Voicebox with ROCm in Docker, no GPU is detected even when the hardware is present and ROCm PyTorch is installed:
Root cause
docker-compose.rocm.ymlsets:HSA_OVERRIDE_GFX_VERSION=${HSA_OVERRIDE_GFX_VERSION:-}This uses the shell default syntax, which sets the variable to an empty string when no value is provided. Docker compose cannot conditionally omit an environment variable — it either sets it (even to empty) or doesn't include the line at all.
An empty string is not the same as unset. ROCm's HSA runtime interprets
HSA_OVERRIDE_GFX_VERSION=""as "force the GPU version to empty", which causes it to find zero GPUs. This affects all GPUs, including ones that are natively supported by ROCm (e.g. gfx1201 / RX 9070 on ROCm 7.2) and don't need an override at all.Verified inside the container:
torch.cuda.is_available()= False, 0 devices12.0.0→ True, 2 devicesFix
In
backend/app.py, before torch is imported, pop the environment variable when it is empty:This ensures that when docker-compose passes an empty string, the variable is fully removed from the environment before ROCm initialises. Users who explicitly set
HSA_OVERRIDE_GFX_VERSIONfor older GPUs (RDNA 1-3) are not affected — the variable is only popped when it is empty.Testing
Tested on RX 9070 (gfx1201) with ROCm 7.2 and PyTorch 2.12.1+rocm7.2:
torch.cuda.is_available()= False, 0 devicestorch.cuda.is_available()= True, 2 devices (AMD Radeon RX 9070 + AMD Ryzen 7 9800X3D iGPU)Summary by CodeRabbit
HSA_OVERRIDE_GFX_VERSIONvalues before hardware detection runs.