The Windows installer recreates the venv on every re-run (the existing
environment is moved aside for rollback and a fresh venv is created), so
irm install.ps1 | iex over an existing install resolved the newest torch
in range instead of keeping the installed release. This ports the
install.sh preservation merged in PR 7250:
- The installed torch version is probed (bounded process, drained
streams, 30s timeout, last non-empty stdout line) BEFORE the rollback
move, while the old interpreter still exists.
- Get-PreviousTorchPin mirrors _previous_torch_pin: numeric-strict base
(nightly/dev/rc builds never pin), UNSLOTH_TORCH_UPGRADE=1 opt-out,
and a release-in-window check against the route's final constraint,
so a raised ROCm floor correctly rejects keeping an older release.
The decision runs after every index and floor decision.
- The kept release installs as an exact pin with minor-paired
companions (torchvision 0.minor+15, torchaudio 2.minor) at the main
install, the AMD ROCm install and both flavor repairs; when the pinned
release is not installable from the selected index the installer warns,
clears the pin and falls back to the supported range. The CPU fallback
cannot be reached with a live pin (the ROCm site resolves or clears it
first) and keeps the plain range install.
- The with-deps unsloth installs now carry a uv overrides file with the
exact installed trio (twin of _build_unsloth_torch_overrides), so
dependency resolution cannot move torch after it was deliberately
selected.
- The kept release is exported as UNSLOTH_KEPT_TORCH for setup.ps1,
whose ROCm/CPU/CUDA torch installs substitute the kept trio when the
env var is present (ROCm floors dominate; behavior without the env
var is unchanged, so direct studio update runs are unaffected). After
setup returns the installer re-probes and warns loudly if the kept
release series changed, then clears the env var.
Preservation is version-agnostic (numeric parse + window comparison),
so a future ceiling bump to torch 2.12 keeps 2.11 installs in place.
New suite tests/studio/test_previous_torch_pin.ps1 (AST-extracted
helpers, 50+ checks incl. future-ceiling cases and structural wiring)
passes, along with the flavor/pin-hardening/pin-stale/node ps1 suites,
the parity and install-stack pytest suites, and the sh preservation and
constraint suites.