Skip to content

[ROCm] Fix hipify path handling on Windows - #199665

Closed
0xDELUXA wants to merge 1 commit into
pytorch:mainfrom
0xDELUXA:hipify-windows-paths
Closed

0xDELUXA wants to merge 1 commit into
pytorch:mainfrom
0xDELUXA:hipify-windows-paths

Conversation

@0xDELUXA

@0xDELUXA 0xDELUXA commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Issue being fixed

Fixes #199664

BC-breaking?

No

Summary (human written only)

This fixes hipify() on Windows, where extension source files and headers were not being hipified correctly, causing JIT-built HIP extensions to fail. It also fixes a secondary crash when the source files and build directory are on different drives. The fixes were tested successfully with ROCm and DeepSpeed.

Agent details (if applicable)

Prepared with Claude; I reviewed the change and reran the tests myself.

Since #194641 normalizes extra_files and include-dir headers, this PR covers the remaining Windows cases. When no relative path exists between a source and the output directory (different drives on Windows), the output path is anchored at the source's drive root, so the .hip file still lands next to the source. The two include rewrites that emitted \ now go through _to_unix_path. On POSIX both are no-ops.

Tested on Windows with ROCm torch 2.16+rocm10.2.0 (gfx1200), with the patched hipify_python.py loaded in place of the installed one. The two new TestHipify tests fail before the change and pass after. The repro from the issue builds and runs, and DeepSpeed's FusedAdam JIT-builds with sources and build directory on different drives and matches torch.optim.AdamW to within 5e-8.

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang

@pytorch-bot

pytorch-bot Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

PR Status: in progress

To become ready for review, please address automated review on your PR either with a code/PR description change. If a review comment is irrelevant, react with 👎 on that specific comment to reject it, and leave a short reply explaining why. The change must pass any running CI and existing failures must be classified as unrelated (see status below in this comment).

Passing automated review does not guarantee that this PR will be merged. It still requires maintainer review and may be closed if its design or direction does not align with the project.

To minimize iteration time, feel free to run the pr-review skill from the repo locally. To trigger a fresh automated review, make a new push or comment @pytorchbot review. To bypass automated review, please add the "no automated review" label.

✅ AUTOMATED REVIEW - Ready for human review:

The PR fixes hipify() on Windows. Three include rewrites now go through
_to_unix_path, and when relpath raises ValueError because the paths are on
different drives, the new code falls back to the source file's drive root. The
review's Recommendation is Approve with only non-blocking points, and it
suggests a follow-up for the drive-root renaming issue.

Findings (4):

[minor] torch/utils/hipify/hipify_python.py:156
Non-blocking: the cross-drive fallback renames every directory below the drive
root. The fallback returns (drive + os.sep, <whole path below the drive root>).
That whole path goes through get_hip_file_path, which does substring
replacements in the directory part: cudahip, CUDAHIP, THCTHH. For example,
D:workcuda_opskernel.cu with the build dir on C: is written to a new directory,
D:workhip_opskernel.hip, created by clean_ctx.makedirs. Quoted includes of local
headers that are not hipified then no longer resolve. This contradicts the PR
body's claim that the .hip file still lands next to the source. It is not a
regression, since this case used to raise ValueError. Suggested fix: in the
fallback only, anchor at os.path.dirname(abs_path) and pass just the file name.
That keeps the output next to the source, and include rewrites still work
because they are built from hipified_path.

[minor] test/test_utils.py:798
Non-blocking: test_hipify_extension_sources mostly passes with or without the
fix. On Linux and macOS it passes either way, because relpath never raises there
and _to_unix_path does nothing. On Windows, only the "ATen/hip/HIPContext.h"
assertion depends on the fix, through the :886 change. The 'helper_hip.cuh'
assertion goes through :927, which already called _to_unix_path before this PR.
No test reaches the changed CurrentState.INITIALIZED branch (:917-925), which
needs a circular or self include. The comment "Mirrors the hipify call in
_jit_compile" overstates the match: the real call also passes ignores=,
clean_ctx=, _canonicalize_hip_source(...) and a realpath'd build dir.

[minor] test/test_utils.py:832
Non-blocking: test_hipify_rel_path_without_common_root only checks that
join(base, rel) rebuilds the path. On POSIX splitdrive returns '', so it
effectively only checks that a leading / is stripped. It never runs
get_hip_file_path or preprocessor. Its own input, cuda/kernel.cu, would expose
the drive-root renaming issue if it asserted dirname(join(base,
get_hip_file_path(rel, True))) == dirname(path). No test runs preprocessor with
relpath raising, so reverting :843 or :920 to os.path.join(output_directory,
...) would go unnoticed.

[info] torch/utils/hipify/hipify_python.py:886
Non-blocking: normalise separators in get_hip_file_path instead of at each
caller. The backslash fixed here comes from os.path.join inside
get_hip_file_path (:603, :608). Normalising its return value would cover every
caller. Note that get_hip_file_path is in __all__, so external callers on
Windows would then get / instead of .

Reviewed commit: 8c791e0

Review run

🐛 Report a bad review

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/199665

Note: Links to docs will display an error until the docs builds have been completed.

❌ 13 New Failures, 3 Cancelled Jobs, 1 Unclassified Failure

As of commit 8c791e0 with merge base db0d290 (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the module: rocm AMD GPU support for Pytorch label Oct 3, 2026
@0xDELUXA

0xDELUXA commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: rocm"

@pytorch-bot pytorch-bot Bot added the release notes: rocm mandatorylabel label Oct 3, 2026
@0xDELUXA
0xDELUXA marked this pull request as ready for review October 4, 2026 19:35
@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot missing actionable issue A PR without a linked actionable issue or maintainer sponsor triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Oct 4, 2026
@0xDELUXA
0xDELUXA force-pushed the hipify-windows-paths branch from 9f34241 to 5fb5b8a Compare October 7, 2026 19:26
@0xDELUXA

0xDELUXA commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Rechecked with torch 2.16.0a0+rocm10.2.0a20261007 (HIP 7.17.26401): the issue still reproduces, and the branch still merges cleanly into current main.

@jeffdaily @jithunnair-amd could you please approve the CI workflows and take a look when you have a moment?

@0xDELUXA
0xDELUXA force-pushed the hipify-windows-paths branch from 5fb5b8a to 8c791e0 Compare October 12, 2026 19:01
@soulitzer soulitzer added missing actionable issue A PR without a linked actionable issue or maintainer sponsor and removed missing actionable issue A PR without a linked actionable issue or maintainer sponsor labels Oct 15, 2026
@jeffdaily jeffdaily added open source and removed triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module bot-triaged This is a label only to be used by the auto triage bot missing actionable issue A PR without a linked actionable issue or maintainer sponsor open source labels Oct 19, 2026
jeffdaily
jeffdaily previously approved these changes Oct 19, 2026
@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 19, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-actions github-actions Bot added the bot-triaged This is a label only to be used by the auto triage bot label Oct 19, 2026
@github-actions github-actions Bot added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Oct 19, 2026
@thiagocrepaldi thiagocrepaldi added this to the 2.15.1 milestone Oct 29, 2026
@atalman atalman removed this from the 2.15.1 milestone Nov 17, 2026
@atalman

atalman commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

HI @thiagocrepaldi please target these fixes for 2.16.0 release these do not affect wheels and are not eligible to 1.5.1 release

@thiagocrepaldi thiagocrepaldi added this to the 2.16.0 milestone Nov 17, 2026
@pytorch-bot pytorch-bot Bot added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 17, 2026
@pytorch-bot
pytorch-bot Bot dismissed jeffdaily’s stale review November 17, 2026 19:55

This PR was reopened (likely due to being reverted), so your approval was removed. Please request another review.

@pytorch-bot

pytorch-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@thiagocrepaldi

Copy link
Copy Markdown
Collaborator

HI @thiagocrepaldi please target these fixes for 2.16.0 release these do not affect wheels and are not eligible to 1.5.1 release

thanks @atalman, but the PR should make into main branch too, right?

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review of 8c791e0: nothing blocking; ready for human review.

The PR fixes hipify() on Windows. Three include rewrites now go through _to_unix_path, and when relpath raises ValueError because the paths are on different drives, the new code falls back to the source file's drive root. The review's Recommendation is Approve with only non-blocking points, and it suggests a follow-up for the drive-root renaming issue.

⚪ 4 non-blocking findings

return drive + os.sep, _to_unix_path(rest).lstrip('/')

Non-blocking: the cross-drive fallback renames every directory below the drive root. The fallback returns (drive + os.sep, <whole path below the drive root>). That whole path goes through get_hip_file_path, which does substring replacements in the directory part: cudahip, CUDAHIP, THCTHH. For example, D:workcuda_opskernel.cu with the build dir on C: is written to a new directory, D:workhip_opskernel.hip, created by clean_ctx.makedirs. Quoted includes of local headers that are not hipified then no longer resolve. This contradicts the PR body's claim that the .hip file still lands next to the source. It is not a regression, since this case used to raise ValueError. Suggested fix: in the fallback only, anchor at os.path.dirname(abs_path) and pass just the file name. That keeps the output next to the source, and include rewrites still work because they are built from hipified_path.


return templ.format(_to_unix_path(get_hip_file_path(m.group(1), is_pytorch_extension)))

Non-blocking: normalise separators in get_hip_file_path instead of at each caller. The backslash fixed here comes from os.path.join inside get_hip_file_path (:603, :608). Normalising its return value would cover every caller. Note that get_hip_file_path is in all, so external callers on Windows would then get / instead of .


def test_hipify_extension_sources(self):

Non-blocking: test_hipify_extension_sources mostly passes with or without the fix. On Linux and macOS it passes either way, because relpath never raises there and _to_unix_path does nothing. On Windows, only the "ATen/hip/HIPContext.h" assertion depends on the fix, through the :886 change. The 'helper_hip.cuh' assertion goes through :927, which already called _to_unix_path before this PR. No test reaches the changed CurrentState.INITIALIZED branch (:917-925), which needs a circular or self include. The comment "Mirrors the hipify call in _jit_compile" overstates the match: the real call also passes ignores=, clean_ctx=, _canonicalize_hip_source(...) and a realpath'd build dir.


def test_hipify_rel_path_without_common_root(self):

Non-blocking: test_hipify_rel_path_without_common_root only checks that join(base, rel) rebuilds the path. On POSIX splitdrive returns '', so it effectively only checks that a leading / is stripped. It never runs get_hip_file_path or preprocessor. Its own input, cuda/kernel.cu, would expose the drive-root renaming issue if it asserted dirname(join(base, get_hip_file_path(rel, True))) == dirname(path). No test runs preprocessor with relpath raising, so reverting :843 or :920 to os.path.join(output_directory, ...) would go unnoticed.

This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

This branch was previously deployed

1 inactive deployment
bedrock — 8c791e03 Deployed Oct 19, 2026 by jeffdaily
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triaged This is a label only to be used by the auto triage bot ciflow/trunk Trigger trunk jobs on your pull request in progress PR is being worked on by the author, until the automated review accepts it Merged module: rocm AMD GPU support for Pytorch open source release notes: rocm mandatorylabel triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ROCm] hipify skips extension sources on Windows, so cpp_extension.load fails to build HIP extensions

7 participants