From e00eeffe2c42a1b61530dd14c21ccca184f42d2b Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Sun, 12 Apr 2026 22:27:53 +0000 Subject: [PATCH] Move $_NoTorch initialization before stale-venv detection in setup.ps1 $_NoTorch was defined at line 1672 but read at lines 1521/1533 in the stale-venv detection block. In PowerShell, reading an undefined variable returns $null, and -not $null evaluates to $true, so the $_NoTorch guards added in the previous commit were silently no-ops. Fix: move the $env:UNSLOTH_NO_TORCH check to before the stale-venv block so --no-torch mode is correctly respected in the torch tag comparison and ROCm repair decision. --- studio/setup.ps1 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/studio/setup.ps1 b/studio/setup.ps1 index 0828eb81e4..3290f0399d 100644 --- a/studio/setup.ps1 +++ b/studio/setup.ps1 @@ -1510,6 +1510,11 @@ if (Test-Path $VenvDir -PathType Container) { $shouldRebuild = $true } + # --no-torch: skip ROCm torch repair and wheel install entirely. + # Must be defined here (before stale-venv detection) because the + # expectedTorchTag and $_NeedRocmRepair logic below depend on it. + $_NoTorch = $env:UNSLOTH_NO_TORCH -in @("1", "true", "True", "TRUE") + # $_NeedRocmRepair is used later to override the version fast-path # ($SkipPythonDeps) so the ROCm install block still runs even when # the unsloth package is already at the latest version. @@ -1666,10 +1671,8 @@ $env:TORCHINDUCTOR_CACHE_DIR = $TorchCacheDir [Environment]::SetEnvironmentVariable('TORCHINDUCTOR_CACHE_DIR', $TorchCacheDir, 'User') substep "TORCHINDUCTOR_CACHE_DIR set to $TorchCacheDir (avoids MAX_PATH issues)" -# --no-torch mode: skip the ROCm wheel path entirely. AMD users running -# install.ps1 --no-torch get a Python 3.13 venv (fine for GGUF); entering -# the ROCm block would hard-fail on the 3.12 version check for no reason. -$_NoTorch = $env:UNSLOTH_NO_TORCH -in @("1", "true", "True", "TRUE") +# $_NoTorch was already initialized earlier (before stale-venv detection) +# so it is available here for the $CuTag selection. if ($HasNvidiaSmi) { $CuTag = Get-PytorchCudaTag