Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Installer: read the venv's torch in isolation so a PYTHONPATH torch cannot break the install (#13041)

Daniel Han6d3af3c332dc
diff --git a/install.ps1 b/install.ps1
index 0379dd446f7..9d05b9bdc82 100644
--- a/install.ps1
+++ b/install.ps1
@@ -7786,7 +7786,7 @@ exit 0
try {
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = $PythonExe
- $psi.Arguments = "-c `"$Code`""
+ $psi.Arguments = "-I -c `"$Code`""
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.UseShellExecute = $false
@@ -8125,7 +8125,7 @@ exit 0
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = $PythonExe
# Dist metadata, not "import torch": a broken DLL would drop the pin (as in install.sh).
- $psi.Arguments = '-c "import importlib.metadata as m; print(m.version(''torch''))"'
+ $psi.Arguments = '-I -c "import importlib.metadata as m; print(m.version(''torch''))"'
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.UseShellExecute = $false
@@ -8212,7 +8212,7 @@ exit 0
if ($SkipTorch) {
& $OldPy -c "import sys; print(sys.executable)" 2>$null | Out-Null
} else {
- & $OldPy -c "import torch; A = torch.ones((2,2)); B = A + A" 2>$null | Out-Null
+ & $OldPy -I -c "import torch; A = torch.ones((2,2)); B = A + A" 2>$null | Out-Null
}
$legacyOk = ($LASTEXITCODE -eq 0)
} catch { $legacyOk = $false }
@@ -10902,7 +10902,7 @@ main()
function New-UnslothTorchOverridesFile {
param([string]$PythonExe)
if ($SkipTorch) { return $null }
- $pins = & $PythonExe -c "from importlib.metadata import version, PackageNotFoundError`nfor _p in ('torch', 'torchvision', 'torchaudio'):`n try:`n print(_p + '==' + version(_p))`n except PackageNotFoundError:`n pass" 2>$null
+ $pins = & $PythonExe -I -c "from importlib.metadata import version, PackageNotFoundError`nfor _p in ('torch', 'torchvision', 'torchaudio'):`n try:`n print(_p + '==' + version(_p))`n except PackageNotFoundError:`n pass" 2>$null
$lines = @($pins | Where-Object { $_ -match '^torch' })
if ($lines.Count -eq 0 -or $lines[0] -notmatch '^torch==') { return $null }
# --overrides replaces any UV_OVERRIDE env file, so fold caller files in, minus their trio.
diff --git a/install.sh b/install.sh
index 7b0d9cd75c2..c38807c265a 100755
--- a/install.sh
+++ b/install.sh
@@ -4178,7 +4178,7 @@ if [ -x "$VENV_DIR/bin/python" ] || _dir_has_entries "$VENV_DIR"; then
break
done
# _run_bounded the fallback: without version.py it hits `import torch`, which can wedge.
- [ -n "$_PREV_TORCH_VER" ] || _PREV_TORCH_VER=$(_run_bounded "$VENV_DIR/bin/python" -c \
+ [ -n "$_PREV_TORCH_VER" ] || _PREV_TORCH_VER=$(_run_bounded "$VENV_DIR/bin/python" -I -c \
"import torch; print(torch.__version__)" 2>/dev/null | tail -n 1 || true)
# New layout already exists — replace only after preserving rollback copy, unless the caller asked for no copy at all, in which case this line would be contradicted by the "discarded" one _start_studio_venv_replacement prints a moment later. install.ps1 varies its twin the same way.
if [ "${_NO_ROLLBACK:-false}" = true ]; then
@@ -4206,7 +4206,7 @@ elif [ "$_STUDIO_HOME_REDIRECT" != "env" ] && [ -x "$STUDIO_HOME/.venv/bin/pytho
if "$STUDIO_HOME/.venv/bin/python" -c "import sys; print(sys.executable)" >/dev/null 2>&1; then
_legacy_ok=true
fi
- elif "$STUDIO_HOME/.venv/bin/python" -c "
+ elif "$STUDIO_HOME/.venv/bin/python" -I -c "
import torch
device = 'cuda' if torch.cuda.is_available() else 'cpu'
A = torch.ones((10, 10), device=device)
@@ -6206,7 +6206,7 @@ _installed_torch_version_for_tag() {
done
return
fi
- "$_VENV_PY" -c "import torch; print(torch.__version__)" 2>/dev/null || true
+ "$_VENV_PY" -I -c "import torch; print(torch.__version__)" 2>/dev/null || true
}
# Whether index ($1) supports a plain --default-index reinstall. The pytorch.org cuXXX / xpu / rocmX.Y AND repo.amd.com gfx* indexes are all PEP 503 simple indexes uv resolves torch and every transitive dep from, the same URLs the fresh-install paths use, so a stale wheel is auto-repairable. Unknown or odd-mirror leaves are not, so we warn rather than risk a wrong reinstall.
@@ -6823,7 +6823,7 @@ _rocm_leaf_below() {
# 0 when the venv's torch has no identifiable rocm family at $2.$3 or newer, mirroring _installed_rocm_wheel_is_below in studio/install_python_stack.py
# Venv torch's AMD per-arch family from the `rocm` meta-package (as install_python_stack.py); empty if unknown.
_venv_torch_amd_family() {
- "$1" -c 'import re
+ "$1" -I -c 'import re
from importlib import metadata
try:
reqs = metadata.requires("rocm") or []
@@ -6837,7 +6837,7 @@ for r in reqs:
}
_venv_torch_rocm_below() {
- _vtr_leaf=$("$1" -c 'import re, torch; m = re.search(r"rocm([0-9]+)\.([0-9]+)", getattr(torch, "__version__", "") or ""); print("rocm%s.%s" % m.groups() if m else "")' 2>/dev/null || true)
+ _vtr_leaf=$("$1" -I -c 'import re, torch; m = re.search(r"rocm([0-9]+)\.([0-9]+)", getattr(torch, "__version__", "") or ""); print("rocm%s.%s" % m.groups() if m else "")' 2>/dev/null || true)
[ -n "$_vtr_leaf" ] || return 0
_rocm_leaf_below "$_vtr_leaf" "$2" "$3"
}
@@ -7826,11 +7826,28 @@ print(path if path.is_file() else '')
_bootstrap_packaged_mlx_override
+# -I hides a PYTHONPATH torch from the install but not from `import torch` at runtime: say so once.
+_TORCH_SHADOW_WARNED=false
+_warn_torch_shadowed() {
+ [ -n "$1" ] && [ "$_TORCH_SHADOW_WARNED" = false ] || return 0
+ # From /: `-c` adds the cwd to sys.path, which a launched backend does not.
+ _wts_ambient=$(cd / && _run_bounded "$_VENV_PY" -c "
+from importlib.metadata import version
+print('torch==' + version('torch'))
+" 2>/dev/null | sed -n 's/^torch==//p' | head -n 1) || _wts_ambient=""
+ if [ -n "$_wts_ambient" ] && [ "$_wts_ambient" != "$1" ]; then
+ _TORCH_SHADOW_WARNED=true
+ substep "[WARN] PYTHONPATH exposes torch $_wts_ambient, which Python imports instead of this environment's torch $1" "$C_WARN"
+ substep "[WARN] Unset PYTHONPATH before launching Unsloth so it uses the torch installed for it" "$C_WARN"
+ fi
+}
+
# A released unsloth wheel can pin an older torch (unsloth 2026.7.2 declares torch<2.11.0); a with-deps PyPI resolve then downgrades the whole trio, swapping the pinned +cuXXX/+rocm build for PyPI's default. The flavor guard below misses this, since PyPI's torch 2.10 default is itself cu128-flavored, so freeze the trio via uv --overrides while unsloth's other deps resolve normally. Sets _UNSLOTH_TORCH_OVERRIDES from the trio in the venv; every with-deps unsloth install must call this before resolving and rm it after.
_build_unsloth_torch_overrides() {
_UNSLOTH_TORCH_OVERRIDES=""
[ "$SKIP_TORCH" = false ] || return 0
- _torch_trio_pins=$("$_VENV_PY" -c "
+ # -I: a torch on PYTHONPATH or in the cwd was frozen instead of the venv's (#11980).
+ _torch_trio_pins=$("$_VENV_PY" -I -c "
from importlib.metadata import version, PackageNotFoundError
for _p in ('torch', 'torchvision', 'torchaudio'):
try:
@@ -7838,6 +7855,7 @@ for _p in ('torch', 'torchvision', 'torchaudio'):
except PackageNotFoundError:
pass
" 2>/dev/null) || _torch_trio_pins=""
+ _warn_torch_shadowed "$(printf '%s\n' "$_torch_trio_pins" | sed -n 's/^torch==//p' | head -n 1)"
case "$_torch_trio_pins" in
torch==*)
# uv resolves an override's relative includes (-r nested.txt) against THAT file's dir, so merge beside the caller's override when they share one writable dir, else mktemp. Globbing is off for both walks below: uv reads the literal name, so an ov[1].txt would otherwise make them iterate a sibling ov1.txt.
@@ -7932,7 +7950,7 @@ if [ "$_MIGRATED" = true ]; then
_install_bnb_rocm "install bitsandbytes (AMD)" "$_VENV_PY"
fi
# Repair ROCm torch if overwritten during migrated install
- _has_hip=$("$_VENV_PY" -c "import torch; print(getattr(torch.version,'hip','') or '')" 2>/dev/null || true)
+ _has_hip=$("$_VENV_PY" -I -c "import torch; print(getattr(torch.version,'hip','') or '')" 2>/dev/null || true)
if [ -z "$_has_hip" ]; then
substep "repairing ROCm torch (overwritten by dependency resolution)..."
_install_torch_default_index --force-reinstall
@@ -8171,7 +8189,7 @@ elif [ -n "$TORCH_INDEX_URL" ]; then
[ -n "$_UNSLOTH_TORCH_OVERRIDES" ] && rm -f "$_UNSLOTH_TORCH_OVERRIDES"
_UNSLOTH_TORCH_OVERRIDES=""
if [ "$SKIP_TORCH" = false ] && [ "$_torch_index_is_rocm_family" = true ]; then
- _has_hip=$("$_VENV_PY" -c "import torch; print(getattr(torch.version,'hip','') or '')" 2>/dev/null || true)
+ _has_hip=$("$_VENV_PY" -I -c "import torch; print(getattr(torch.version,'hip','') or '')" 2>/dev/null || true)
if [ -z "$_has_hip" ]; then
substep "repairing ROCm torch (overwritten by dependency resolution)..."
_install_torch_default_index --force-reinstall
@@ -8270,7 +8288,7 @@ fi
if [ "$SKIP_TORCH" = false ] && ! _cvd_hides_nvidia; then
case "${_expected_torch_tag:-}" in
cu[0-9]*)
- _arch_check=$(_run_bounded --secs 120 "$_VENV_PY" -c '
+ _arch_check=$(_run_bounded --secs 120 "$_VENV_PY" -I -c '
import ctypes, sys
def load(*names):
@@ -8379,7 +8397,7 @@ fi
if [ "$SKIP_TORCH" = false ] && [ -n "${_TORCH_EXTRA:-}" ]; then
# A sentinel line, not all of stdout: a sitecustomize or import hook prints before torch
# does, and that text made the equality below fail on a working GPU (as for _PREV_TORCH_VER).
- _extra_probe=$(_run_bounded "$_VENV_PY" -c \
+ _extra_probe=$(_run_bounded "$_VENV_PY" -I -c \
"import torch; print('UNSLOTH_CUDA_OK=%s' % torch.cuda.is_available())" 2>/dev/null \
| sed -n 's/^UNSLOTH_CUDA_OK=//p' | tail -n 1 || true)
if [ "$_extra_probe" = "True" ]; then
diff --git a/studio/setup.ps1 b/studio/setup.ps1
index 80dc09756f1..55016189c10 100644
--- a/studio/setup.ps1
+++ b/studio/setup.ps1
@@ -2318,7 +2318,8 @@ function Invoke-BoundedPythonProbe {
try {
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = $PythonExe
- $psi.Arguments = "-c `"$Code`""
+ # -I: the stale-venv probe runs before Enter-StudioVenv drops PYTHONPATH (#11980).
+ $psi.Arguments = "-I -c `"$Code`""
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.UseShellExecute = $false
@@ -7725,9 +7726,11 @@ function Enter-StudioVenv {
$env:VIRTUAL_ENV = $VenvDir
$env:PATH = (Join-Path $VenvDir "Scripts") + ";" + $env:PATH
Remove-Item Env:PYTHONHOME -ErrorAction SilentlyContinue
+ Remove-Item Env:PYTHONPATH -ErrorAction SilentlyContinue
return
}
. $ActivateScript
+ Remove-Item Env:PYTHONPATH -ErrorAction SilentlyContinue
}
Enter-StudioVenv
Assert-VenvActivated -VenvDir $VenvDir
diff --git a/studio/setup.sh b/studio/setup.sh
index da7874311b6..4d6dff25501 100755
--- a/studio/setup.sh
+++ b/studio/setup.sh
@@ -2548,6 +2548,8 @@ elif [ -n "$STAGE_ROOT" ]; then
else
source "$VENV_DIR/bin/activate"
fi
+# A PYTHONPATH torch would answer the probes below instead of the venv's (#11980); Colab has no venv.
+[ "$_COLAB_NO_VENV" = true ] || unset PYTHONPATH
install_python_stack() {
[ "${STUDIO_LOCAL_INSTALL:-0}" = 1 ] && [ -x "$VENV_DIR/bin/python" ] || _mirror_fallback
diff --git a/tests/sh/test_torch_probe_isolation.sh b/tests/sh/test_torch_probe_isolation.sh
new file mode 100755
index 00000000000..20f044837b7
--- /dev/null
+++ b/tests/sh/test_torch_probe_isolation.sh
@@ -0,0 +1,84 @@
+#!/bin/bash
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+# #11980: the installer's venv torch probes must ignore a torch on PYTHONPATH (NGC 2.9.0a0+...nv25.9).
+set -e
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+. "$SCRIPT_DIR/_harness.sh"
+INSTALL_SH="$SCRIPT_DIR/../../install.sh"
+
+echo "=== test_torch_probe_isolation ==="
+
+WORK=$(mktemp -d)
+trap 'rm -rf "${WORK:?}"' EXIT
+python3 -m venv --without-pip "$WORK/venv"
+_VENV_PY="$WORK/venv/bin/python"
+SP=$("$_VENV_PY" -I -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')
+fake_dist() {
+ mkdir -p "$1/$2-$3.dist-info"
+ printf 'Metadata-Version: 2.1\nName: %s\nVersion: %s\n' "$2" "$3" > "$1/$2-$3.dist-info/METADATA"
+}
+fake_dist "$SP" torch 2.11.0+cu130
+fake_dist "$SP" torchvision 0.26.0+cu130
+fake_dist "$SP" torchaudio 2.11.0+cu130
+mkdir -p "$WORK/shadow"
+fake_dist "$WORK/shadow" torch 2.9.0a0+50eac811a6.nv25.9
+
+FUNCS=$(sed -n '/^_run_bounded() {/,/^}/p; /^_TORCH_SHADOW_WARNED=false$/p; /^_warn_torch_shadowed() {/,/^}/p; /^_build_unsloth_torch_overrides() {/,/^}/p' "$INSTALL_SH")
+case "$FUNCS" in
+ *_warn_torch_shadowed*_build_unsloth_torch_overrides*) ok "extracted the probe functions from install.sh" ;;
+ *) bad "could not extract the probe functions from install.sh"; echo "Results: $PASS passed, $FAIL failed"; exit 1 ;;
+esac
+
+# Real builder, cwd = shadow, PYTHONPATH=$1; called twice since the warning is once per run.
+run_builder() {
+ (
+ cd "$WORK/shadow"
+ export PYTHONPATH="$1"
+ SKIP_TORCH=false
+ C_WARN=""
+ unset UV_OVERRIDE
+ substep() { echo "SUBSTEP: $1"; }
+ eval "$FUNCS"
+ _build_unsloth_torch_overrides
+ cat "$_UNSLOTH_TORCH_OVERRIDES"; rm -f "$_UNSLOTH_TORCH_OVERRIDES"
+ _build_unsloth_torch_overrides
+ rm -f "$_UNSLOTH_TORCH_OVERRIDES"
+ )
+}
+
+OUT=$(run_builder "$WORK/shadow")
+assert_contains "shadowed: venv torch is frozen" "$OUT" "torch==2.11.0+cu130"
+assert_not_contains "shadowed: PYTHONPATH torch is not frozen" "$OUT" "torch==2.9.0a0"
+assert_contains "shadowed: torchvision still frozen" "$OUT" "torchvision==0.26.0+cu130"
+assert_contains "shadowed: user is told which torch shadows the venv" "$OUT" "PYTHONPATH exposes torch 2.9.0a0+50eac811a6.nv25.9"
+assert_eq "shadowed: the warning prints once per run" "2" "$(printf '%s\n' "$OUT" | grep -c '^SUBSTEP:')"
+
+OUT=$(run_builder "")
+assert_contains "cwd shadow only: venv torch is frozen" "$OUT" "torch==2.11.0+cu130"
+assert_eq "cwd shadow only: no PYTHONPATH warning" "" "$(printf '%s\n' "$OUT" | sed '/^SUBSTEP:/!d')"
+
+_unisolated=$(grep -nE '(_VENV_PY"|VENV_DIR/bin/python") -c' "$INSTALL_SH" \
+ | grep -E "import torch|version\(_p\)" || true)
+assert_eq "no venv torch probe in install.sh runs without -I" "" "$_unisolated"
+for _probe in '_torch_trio_pins=$("$_VENV_PY" -I -c' \
+ '"$_VENV_PY" -I -c "import torch; print(torch.__version__)"' \
+ '_PREV_TORCH_VER=$(_run_bounded "$VENV_DIR/bin/python" -I -c'; do
+ assert_contains "install.sh still carries: $_probe" "$(cat "$INSTALL_SH")" "$_probe"
+done
+
+SETUP_SH="$SCRIPT_DIR/../../studio/setup.sh"
+assert_contains "setup.sh drops PYTHONPATH once the venv is active (Colab no-venv keeps it)" \
+ "$(cat "$SETUP_SH")" '[ "$_COLAB_NO_VENV" = true ] || unset PYTHONPATH'
+_unset_line=$(grep -n '|| unset PYTHONPATH$' "$SETUP_SH" | head -n 1 | cut -d: -f1)
+_stack_line=$(grep -n '^ python "$SCRIPT_DIR/install_python_stack.py"$' "$SETUP_SH" | head -n 1 | cut -d: -f1)
+if [ -n "$_unset_line" ] && [ -n "$_stack_line" ] && [ "$_unset_line" -lt "$_stack_line" ]; then
+ ok "setup.sh drops PYTHONPATH before install_python_stack.py runs"
+else
+ bad "setup.sh drops PYTHONPATH before install_python_stack.py runs (unset=$_unset_line stack=$_stack_line)"
+fi
+
+echo ""
+echo "Results: $PASS passed, $FAIL failed"
+[ "$FAIL" -eq 0 ]
diff --git a/tests/sh/test_unsloth_torch_override.sh b/tests/sh/test_unsloth_torch_override.sh
index 0438bcedda8..5d464fa8f5f 100644
--- a/tests/sh/test_unsloth_torch_override.sh
+++ b/tests/sh/test_unsloth_torch_override.sh
@@ -54,8 +54,8 @@ assert_true "overrides file build is gated on SKIP_TORCH=false" "$?"
# 3. The pin-collection snippet emits exact ==pins for the installed trio (run
# the embedded python against this test's interpreter).
-_snippet=$(sed -n '/_torch_trio_pins=\$("\$_VENV_PY" -c "/,/^" 2>\/dev\/null)/p' "$INSTALL_SH" \
- | sed '1s/.*-c "//' | sed '$d')
+_snippet=$(sed -n '/_torch_trio_pins=\$("\$_VENV_PY" -I -c "/,/^" 2>\/dev\/null)/p' "$INSTALL_SH" \
+ | sed '1s/.*-I -c "//' | sed '$d')
_out=$(python3 -c "$_snippet" 2>&1) || true
# torch may or may not be importable on the test host; the snippet must not
# crash and every line it does emit must be an exact pkg==version pin.
diff --git a/tests/studio/install/test_install_sh_torch_arch_check.py b/tests/studio/install/test_install_sh_torch_arch_check.py
index 96637361b44..14282bd28ad 100644
--- a/tests/studio/install/test_install_sh_torch_arch_check.py
+++ b/tests/studio/install/test_install_sh_torch_arch_check.py
@@ -53,7 +53,9 @@ class cuda:
def _check_source() -> str:
text = INSTALL_SH.read_text(encoding = "utf-8")
- m = re.search(r"_run_bounded --secs 120 \"\$_VENV_PY\" -c '\n(.*?)\n' 2>/dev/null", text, re.S)
+ m = re.search(
+ r"_run_bounded --secs 120 \"\$_VENV_PY\" -I -c '\n(.*?)\n' 2>/dev/null", text, re.S
+ )
assert m, "the post-install arch check was not found"
return m.group(1)
diff --git a/tests/studio/install/test_rocm_support.py b/tests/studio/install/test_rocm_support.py
index 6216296949a..e916000d2ca 100644
--- a/tests/studio/install/test_rocm_support.py
+++ b/tests/studio/install/test_rocm_support.py
@@ -2555,6 +2555,8 @@ class TestGfx1102Rocm64Floor:
with open(venv_py, "w", encoding = "utf-8") as fh:
fh.write(
"#!/bin/sh\n"
+ # install.sh probes the venv with `-I -c CODE`; the stub only reads CODE.
+ 'if [ "$1" = "-I" ]; then shift; fi\n'
f'exec \'{sys.executable.replace(os.sep, "/")}\' -c "\n'
"import sys, types\n"
"t = types.ModuleType('torch')\n"
diff --git a/tests/studio/test_torch_overrides_merge.ps1 b/tests/studio/test_torch_overrides_merge.ps1
index 7a5e777768b..329aa026eb0 100644
--- a/tests/studio/test_torch_overrides_merge.ps1
+++ b/tests/studio/test_torch_overrides_merge.ps1
@@ -183,6 +183,30 @@ try {
Check "the inherited ACL is replaced rather than kept" (
($src -match 'SetAccessRuleProtection\(\$true, \$false\)') -and ($src -match 'Set-Acl -LiteralPath \$f')
)
+
+ Remove-Item Env:UV_OVERRIDE -ErrorAction SilentlyContinue
+ # `python` first on Windows: `python3` there can be the Microsoft Store alias stub.
+ $pyNames = if ($onWindows) { @("python", "python3") } else { @("python3", "python") }
+ $hostPy = (Get-Command $pyNames -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1).Source
+ if (-not $hostPy) { throw "no python on PATH for the PYTHONPATH shadow case" }
+ $venv = Join-Path $work "venv"
+ & $hostPy -m venv --without-pip $venv
+ $venvPy = if ($onWindows) { Join-Path $venv "Scripts\python.exe" } else { Join-Path $venv "bin/python" }
+ $site = (& $venvPy -I -c "import sysconfig; print(sysconfig.get_paths()['purelib'])").Trim()
+ $shadow = Join-Path $work "shadow"
+ foreach ($d in @(@($site, "torch", "2.11.0+cu130"), @($site, "torchvision", "0.26.0+cu130"), @($shadow, "torch", "2.9.0a0+50eac811a6.nv25.9"))) {
+ $info = Join-Path $d[0] "$($d[1])-$($d[2]).dist-info"
+ New-Item -ItemType Directory -Path $info -Force | Out-Null
+ [System.IO.File]::WriteAllText((Join-Path $info "METADATA"), "Metadata-Version: 2.1`nName: $($d[1])`nVersion: $($d[2])`n")
+ }
+ $savedPythonPath = $env:PYTHONPATH
+ $env:PYTHONPATH = $shadow
+ try { $shadowed = New-UnslothTorchOverridesFile -PythonExe $venvPy }
+ finally { if ($null -eq $savedPythonPath) { Remove-Item Env:PYTHONPATH -ErrorAction SilentlyContinue } else { $env:PYTHONPATH = $savedPythonPath } }
+ $made += $shadowed
+ $pins = if ($shadowed) { [System.IO.File]::ReadAllText($shadowed) } else { "" }
+ Check "PYTHONPATH shadow: the venv's torch is frozen" ($pins -match '(?m)^torch==2\.11\.0\+cu130\r?$')
+ Check "PYTHONPATH shadow: the shadowing torch is not" ($pins -notmatch 'nv25\.9')
}
finally {
if ($null -eq $savedOverride) { Remove-Item Env:UV_OVERRIDE -ErrorAction SilentlyContinue }