From a078d48607a0fd74875f0a4fc8ce6e73b50296d5 Mon Sep 17 00:00:00 2001 From: ethanwee1 Date: Tue, 30 Jun 2026 20:42:01 +0000 Subject: [PATCH] [release/2.12] Fix Windows cross-drive HIPIFY failure in CUDAExtension When building HIP extensions (e.g. torchaudio) on Windows where the source checkout lives on a subst/virtual drive (B:) that aliases a directory on the real drive (C:), os.path.relpath() raised "path is on mount 'C:', start on mount 'B:'" because os.getcwd() reported the alias while the hipified source resolved to the underlying drive. Normalize both the build dir and the hipified source through os.path.realpath() before computing the relative path. --- torch/utils/cpp_extension.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/torch/utils/cpp_extension.py b/torch/utils/cpp_extension.py index 3e9d5d3823cbe..0d428aa7d06fe 100644 --- a/torch/utils/cpp_extension.py +++ b/torch/utils/cpp_extension.py @@ -1493,13 +1493,20 @@ def CUDAExtension(name, sources, *args, **kwargs): ) hipified_sources = set() + # Resolve build_dir through realpath so that a Windows subst/virtual + # drive (e.g. a B: that aliases a directory on C:) matches the + # canonicalized source paths returned by hipify. Without this, + # os.path.relpath() below can raise "path is on mount 'C:', start on + # mount 'B:'" when os.getcwd() reports the alias but the hipified + # source resolves to the underlying drive. + build_dir_real = os.path.realpath(build_dir) for source in sources: s_abs = os.path.abspath(source) hipified_s_abs = (hipify_result[s_abs].hipified_path if (s_abs in hipify_result and hipify_result[s_abs].hipified_path is not None) else s_abs) # 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)) + hipified_sources.add(os.path.relpath(os.path.realpath(hipified_s_abs), build_dir_real)) sources = list(hipified_sources)