Determine the appropriate PyTorch installation URL based on CUDA availability. Uses @functools.lru_cache to avoid redundant CUDA detection and print statements. Args: torch_nightly_url_base: Base URL for PyTorch nightly packages Returns: URL string for PyTorch pack
(torch_nightly_url_base)
| 156 | |
| 157 | @functools.lru_cache(maxsize=1) |
| 158 | def determine_torch_url(torch_nightly_url_base): |
| 159 | """ |
| 160 | Determine the appropriate PyTorch installation URL based on CUDA availability. |
| 161 | Uses @functools.lru_cache to avoid redundant CUDA detection and print statements. |
| 162 | |
| 163 | Args: |
| 164 | torch_nightly_url_base: Base URL for PyTorch nightly packages |
| 165 | |
| 166 | Returns: |
| 167 | URL string for PyTorch packages |
| 168 | """ |
| 169 | if platform.system().lower() == "windows": |
| 170 | print( |
| 171 | "Windows detected, using CPU-only PyTorch until CUDA support is available" |
| 172 | ) |
| 173 | return f"{torch_nightly_url_base}/cpu" |
| 174 | |
| 175 | print("Attempting to detect CUDA via nvcc...") |
| 176 | |
| 177 | try: |
| 178 | cuda_version = _get_cuda_version() |
| 179 | except Exception as err: |
| 180 | print(f"CUDA detection failed ({err}), using CPU-only PyTorch") |
| 181 | return f"{torch_nightly_url_base}/cpu" |
| 182 | |
| 183 | major, minor = cuda_version |
| 184 | print(f"Detected CUDA version: {major}.{minor}") |
| 185 | |
| 186 | # Get appropriate PyTorch CUDA URL |
| 187 | torch_url = _get_pytorch_cuda_url(cuda_version, torch_nightly_url_base) |
| 188 | print(f"Using PyTorch URL: {torch_url}") |
| 189 | |
| 190 | return torch_url |
| 191 | |
| 192 | |
| 193 | # Prebuilt binaries for Intel-based macOS are no longer available on PyPI; users must compile from source. |
no test coverage detected