Weijie Lyu Claude Opus 4.8 (1M context) commited on
Commit
4ff86b7
·
1 Parent(s): fdba6dc

Make pip nvcc detection robust (glob, not hardcoded path)

Browse files

Search site-packages for nvidia/cuda_nvcc*/bin/nvcc instead of
assuming the exact path, and only add include/lib dirs that exist.
Also note in the fallback warning that a stale build cache (lingering
cu130 torch + missing nvcc package) needs a Factory Reboot.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +23 -11
app.py CHANGED
@@ -104,21 +104,33 @@ except ImportError:
104
  # requires, and torch's build check errors on a major CUDA mismatch (nvcc 13 vs
105
  # torch 12.8). Point CUDA_HOME at the pip nvcc and feed the runtime/cub headers
106
  # and cudart lib via CPATH/LIBRARY_PATH so nvcc 12.8 matches torch 12.8.
107
- import site
108
- _site = site.getsitepackages()[0]
109
- _nv = os.path.join(_site, "nvidia")
110
- _nvcc_home = os.path.join(_nv, "cuda_nvcc")
111
- if os.path.isdir(_nvcc_home):
 
 
 
 
 
 
 
112
  env["CUDA_HOME"] = _nvcc_home
113
  env["PATH"] = os.path.join(_nvcc_home, "bin") + os.pathsep + env.get("PATH", "")
114
- _incs = [os.path.join(_nv, "cuda_runtime", "include"),
115
- os.path.join(_nv, "cuda_cccl", "include")]
116
- env["CPATH"] = os.pathsep.join(_incs + ([env["CPATH"]] if env.get("CPATH") else []))
 
117
  _rt_lib = os.path.join(_nv, "cuda_runtime", "lib")
118
- env["LIBRARY_PATH"] = _rt_lib + os.pathsep + env.get("LIBRARY_PATH", "")
119
- env["LD_LIBRARY_PATH"] = _rt_lib + os.pathsep + env.get("LD_LIBRARY_PATH", "")
 
 
120
  else:
121
- print(f"⚠️ pip CUDA toolkit not found at {_nvcc_home}; falling back to system nvcc")
 
 
122
 
123
  # Build a cross-arch set incl. Blackwell sm_120 (the ZeroGPU GPU is cap 12.0);
124
  # the build stage may not see a GPU, so don't rely on get_device_capability.
 
104
  # requires, and torch's build check errors on a major CUDA mismatch (nvcc 13 vs
105
  # torch 12.8). Point CUDA_HOME at the pip nvcc and feed the runtime/cub headers
106
  # and cudart lib via CPATH/LIBRARY_PATH so nvcc 12.8 matches torch 12.8.
107
+ import site, glob
108
+ _search_dirs = list(site.getsitepackages())
109
+ try:
110
+ _search_dirs.append(site.getusersitepackages())
111
+ except Exception:
112
+ pass
113
+ _nvcc_bins = []
114
+ for _d in _search_dirs:
115
+ _nvcc_bins += glob.glob(os.path.join(_d, "nvidia", "cuda_nvcc*", "bin", "nvcc"))
116
+ if _nvcc_bins:
117
+ _nvcc_home = os.path.dirname(os.path.dirname(_nvcc_bins[0])) # .../nvidia/cuda_nvcc
118
+ _nv = os.path.dirname(_nvcc_home) # .../nvidia
119
  env["CUDA_HOME"] = _nvcc_home
120
  env["PATH"] = os.path.join(_nvcc_home, "bin") + os.pathsep + env.get("PATH", "")
121
+ _incs = [p for p in (os.path.join(_nv, "cuda_runtime", "include"),
122
+ os.path.join(_nv, "cuda_cccl", "include")) if os.path.isdir(p)]
123
+ if _incs:
124
+ env["CPATH"] = os.pathsep.join(_incs + ([env["CPATH"]] if env.get("CPATH") else []))
125
  _rt_lib = os.path.join(_nv, "cuda_runtime", "lib")
126
+ if os.path.isdir(_rt_lib):
127
+ env["LIBRARY_PATH"] = _rt_lib + os.pathsep + env.get("LIBRARY_PATH", "")
128
+ env["LD_LIBRARY_PATH"] = _rt_lib + os.pathsep + env.get("LD_LIBRARY_PATH", "")
129
+ print(f"[BUILD] using pip CUDA toolkit: CUDA_HOME={_nvcc_home}")
130
  else:
131
+ print("⚠️ pip CUDA nvcc (nvidia-cuda-nvcc-cu12) not found under site-packages/nvidia; "
132
+ "falling back to system nvcc (will mismatch cu128 torch). "
133
+ "If this persists, Factory Reboot the Space to clear the stale build cache.")
134
 
135
  # Build a cross-arch set incl. Blackwell sm_120 (the ZeroGPU GPU is cap 12.0);
136
  # the build stage may not see a GPU, so don't rely on get_device_capability.