diff --git a/install.ps1 b/install.ps1 index 745c7369ea..c35f7f447b 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1939,6 +1939,11 @@ exit 0 # Mirrors Get-PytorchCudaTag in setup.ps1. function Get-TorchIndexUrl { $baseUrl = if ($env:UNSLOTH_PYTORCH_MIRROR) { $env:UNSLOTH_PYTORCH_MIRROR.TrimEnd('/') } else { "https://download.pytorch.org/whl" } + # Explicit override for hosts where GPU probing is impossible or must not + # happen (image builds, CI runners that build for a different target than + # they run on). Names the wheel index path leaf directly, e.g. + # UNSLOTH_TORCH_INDEX_FAMILY=cu128 | cu130 | cu126 | cpu | rocm6.4 | ... + if ($env:UNSLOTH_TORCH_INDEX_FAMILY) { return "$baseUrl/$($env:UNSLOTH_TORCH_INDEX_FAMILY)" } if (-not $NvidiaSmiExe) { return "$baseUrl/cpu" } try { $output = Invoke-NvidiaSmiBounded $NvidiaSmiExe diff --git a/install.sh b/install.sh index 5038de6264..823eee0de1 100755 --- a/install.sh +++ b/install.sh @@ -1962,6 +1962,17 @@ _has_usable_nvidia_gpu() { get_torch_index_url() { _base="${UNSLOTH_PYTORCH_MIRROR:-https://download.pytorch.org/whl}" _base="${_base%/}" + # Explicit override for hosts where GPU probing is impossible or must not + # happen (Docker image builds, CI runners that build for a different + # target than they run on). Names the wheel index path leaf directly: + # UNSLOTH_TORCH_INDEX_FAMILY=cu128 | cu130 | cu126 | cu124 | cu118 | cpu | rocm6.4 | ... + # Example: a Docker image that targets CUDA 12.8 is built on a host with no + # GPU and no nvidia-smi, so probing would otherwise fall back to cpu (or, on + # build hosts that leak /proc/driver/nvidia but cannot run nvidia-smi, cu126) + # and bake the wrong wheels. Setting this pins the index deterministically. + if [ -n "${UNSLOTH_TORCH_INDEX_FAMILY:-}" ]; then + echo "$_base/${UNSLOTH_TORCH_INDEX_FAMILY}"; return + fi # macOS: always CPU (no CUDA support) case "$(uname -s)" in Darwin) echo "$_base/cpu"; return ;; esac # Try nvidia-smi -- require the binary to actually list a usable GPU.