[release/2.13] Fix Windows HIP extension build when hipified sources span drives - #3550
Merged
pragupta merged 1 commit intoAug 10, 2026
Conversation
…torch#191743) Fixes CUDAExtension crashing on Windows HIP builds when the build directory and hipified source paths are on different drives. During hipify, CUDAExtension calls os.path.relpath(hipified_path, build_dir). On Windows, that raises ValueError if the paths are on different drive letters (e.g. checkout on B:, Python/torch on C:). This breaks Windows ROCm extension builds such as torchaudio ROCm/TheRock#6963). Prefer a relative path when possible; if relpath fails, use the absolute hipified path instead. Linux behavior is unchanged because cross-drive relpath does not fail there. Pull Request resolved: pytorch#191743 Approved by: https://github.com/pruthvistony, https://github.com/jeffdaily
There was a problem hiding this comment.
Pull request overview
Fixes a Windows-specific failure in torch.utils.cpp_extension.CUDAExtension when hipified source files end up on a different drive than the build directory (where os.path.relpath cannot compute a relative path).
Changes:
- Catch
ValueErrorfromos.path.relpath()in the HIP hipification path and fall back to an absolute path for the hipified source. - Adjust how hipified source paths are added to the
sourceslist during extension construction.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1611
to
+1615
| try: | ||
| hip_path = os.path.relpath(hipified_s_abs, build_dir) | ||
| except ValueError: | ||
| # Cross-drive on Windows: no relative path exists; fall back to absolute (#91797). | ||
| hip_path = hipified_s_abs |
Comment on lines
1609
to
+1613
| # setup() arguments must *always* be /-separated paths relative to the setup.py directory, | ||
| # *never* absolute paths | ||
| hipified_sources.add(os.path.relpath(hipified_s_abs, build_dir)) | ||
| try: | ||
| hip_path = os.path.relpath(hipified_s_abs, build_dir) | ||
| except ValueError: |
|
@tvukovic-amd can you start a build on theRock to confirm the cherry pick works? |
|
Please also add it in the PR description |
4 tasks
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.
cherry pick of pytorch#191743 which solves ROCm/TheRock#6963