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.

Studio installer: show the previous unsloth version next to the new one (#14248)

Daniel Han527854709d7a
diff --git a/install.ps1 b/install.ps1
index c3083706a29..68dbed78545 100644
--- a/install.ps1
+++ b/install.ps1
@@ -7299,6 +7299,8 @@ exit 0
$script:PrevTorchVer = ""
$script:PrevTorchPin = $null
$script:ExistingInstall = $false
+ # The release being replaced, shown next to the new one at the end (#9910).
+ $script:PrevPackageVersion = ""
function Test-VenvPythonReady {
param([Parameter(Mandatory = $true)][string]$PythonExe)
@@ -7778,6 +7780,24 @@ exit 0
return $null
}
+ # Version of distribution $Name in $VenvRoot from its dist-info METADATA, without running the
+ # interpreter. $null when there is no record or more than one.
+ function Get-PackageVersionFromDisk {
+ param([string]$VenvRoot, [string]$Name)
+ $sitePackages = Join-Path $VenvRoot "Lib\site-packages"
+ $distName = $Name -replace '[-.]', '_'
+ try {
+ $records = @(Get-ChildItem -LiteralPath $sitePackages -Directory -Filter "$distName-*.dist-info" -ErrorAction Stop)
+ if ($records.Count -ne 1) { return $null }
+ $metadata = Join-Path $records[0].FullName "METADATA"
+ if (-not (Test-Path -LiteralPath $metadata -PathType Leaf)) { return $null }
+ foreach ($line in [System.IO.File]::ReadAllLines($metadata)) {
+ if ($line -match '^Version:\s*(\S+)') { return $Matches[1] }
+ }
+ } catch {}
+ return $null
+ }
+
# Before anything below moves an environment aside; a broken legacy .venv still counts.
$_legacyVenvDir = Join-Path $StudioHome ".venv"
$_cwdVenvPy = if ($env:USERPROFILE) { Join-Path $env:USERPROFILE "unsloth_studio\Scripts\python.exe" } else { $null }
@@ -7836,6 +7856,8 @@ exit 0
if ((Get-HostMachineArch) -eq "arm64" -and (Test-Path -LiteralPath $VenvPython -PathType Leaf)) {
$script:PrevVenvPlatformTag = Get-PythonPlatformTag $VenvPython
}
+ $script:PrevPackageVersion = Get-PackageVersionFromDisk -VenvRoot $VenvDir -Name $PackageName
+ if ($script:PrevPackageVersion) { substep "found $PackageName $($script:PrevPackageVersion)" }
# 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-StudioVenvRollback prints a moment later.
@@ -11211,7 +11233,13 @@ sys.exit(2 if conflict else (0 if installed else 1))
if ($_installedPackageVersionExit -eq 2) {
substep "duplicate metadata found for $PackageName; the dependency pass will repair it" "Cyan"
} elseif ($_installedPackageVersionExit -eq 0 -and $installedPackageVersion) {
- step $PackageName "$installedPackageVersion installed"
+ $_installedPackageChange = ""
+ if ($script:PrevPackageVersion -eq $installedPackageVersion) {
+ $_installedPackageChange = " (unchanged)"
+ } elseif ($script:PrevPackageVersion) {
+ $_installedPackageChange = " (was $($script:PrevPackageVersion))"
+ }
+ step $PackageName "$installedPackageVersion installed$_installedPackageChange"
} else {
substep "[WARN] installed $PackageName version could not be determined" "Yellow"
}
diff --git a/install.sh b/install.sh
index 16a874983e2..ad2f1fbd5ba 100755
--- a/install.sh
+++ b/install.sh
@@ -1243,6 +1243,19 @@ _dir_has_entries() { # dir
return "$_dhe_found"
}
+# Version of distribution $2 in venv $1, read from its dist-info METADATA without running the interpreter. Prints nothing when there is no record or more than one.
+_dist_version_from_disk() { # venv dir, distribution name
+ _dvd_name=$(printf '%s' "$2" | tr '.-' '__')
+ _dvd_meta=""
+ for _dvd_candidate in "$1"/lib/python*/site-packages/"$_dvd_name"-*.dist-info/METADATA; do
+ [ -f "$_dvd_candidate" ] || continue
+ [ -z "$_dvd_meta" ] || return 0
+ _dvd_meta=$_dvd_candidate
+ done
+ [ -n "$_dvd_meta" ] || return 0
+ sed -n '/^Version:/{s/^Version:[[:space:]]*//;s/[[:space:]]*$//;p;q;}' "$_dvd_meta" 2>/dev/null || true
+}
+
# Clear $VENV_DIR for a recreate without ever destroying the only copy. The legacy-layout migration below moves $STUDIO_HOME/.venv straight into $VENV_DIR without going through _start_studio_venv_replacement, so a plain `rm -rf` there is unrecoverable: if the `uv venv` that follows cannot resolve an interpreter the user is left with no environment at all. Move it aside instead and let the exit/signal traps put it back. When a replacement is already in flight the rollback copy holds the user's real environment and $VENV_DIR is this run's own work, so plain removal stays correct.
_discard_venv_for_recreate() { # venv dir
if [ "$_VENV_ROLLBACK_ACTIVE" != true ] && [ -d "$1" ] \
@@ -4216,6 +4229,8 @@ _MIGRATED=false
_PREV_TORCH_VER=""
# Any earlier environment in this home, readable or not: only a home without one takes a new-install torch default.
_EXISTING_INSTALL=false
+# The release being replaced, shown next to the new one at the end (#9910).
+_PREV_PACKAGE_VERSION=""
# Replace occupied venvs even when bin/python is missing or dangling, as in the repair loop reported in #9479.
if [ -x "$VENV_DIR/bin/python" ] || _dir_has_entries "$VENV_DIR"; then
@@ -4240,6 +4255,8 @@ if [ -x "$VENV_DIR/bin/python" ] || _dir_has_entries "$VENV_DIR"; then
# _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" -I -c \
"import torch; print(torch.__version__)" 2>/dev/null | tail -n 1 || true)
+ _PREV_PACKAGE_VERSION=$(_dist_version_from_disk "$VENV_DIR" "$PACKAGE_NAME")
+ [ -z "$_PREV_PACKAGE_VERSION" ] || substep "found $PACKAGE_NAME $_PREV_PACKAGE_VERSION"
# 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
substep "moving the existing environment aside..."
@@ -8581,7 +8598,13 @@ fi
if [ "$_installed_package_version_exit" -eq 2 ]; then
substep "duplicate metadata found for $PACKAGE_NAME; the dependency pass will repair it"
elif [ -n "$_installed_package_version" ]; then
- step "$PACKAGE_NAME" "$_installed_package_version installed"
+ _installed_package_change=""
+ if [ "${_PREV_PACKAGE_VERSION:-}" = "$_installed_package_version" ]; then
+ _installed_package_change=" (unchanged)"
+ elif [ -n "${_PREV_PACKAGE_VERSION:-}" ]; then
+ _installed_package_change=" (was $_PREV_PACKAGE_VERSION)"
+ fi
+ step "$PACKAGE_NAME" "$_installed_package_version installed$_installed_package_change"
else
substep "[WARN] installed $PACKAGE_NAME version could not be determined" "$C_WARN"
fi
diff --git a/tests/test_installer_unsloth_version.py b/tests/test_installer_unsloth_version.py
index 43e69d39ce7..c5a16701c5e 100644
--- a/tests/test_installer_unsloth_version.py
+++ b/tests/test_installer_unsloth_version.py
@@ -76,3 +76,145 @@ def test_windows_version_reporter_uses_distribution_metadata():
text = True,
)
assert result.stdout.strip() == f"pytest {version('pytest')} installed"
+
+
+def _fake_venv(
+ root: Path,
+ records: dict[str, str],
+ windows: bool = False,
+) -> Path:
+ site = root / ("Lib/site-packages" if windows else "lib/python3.13/site-packages")
+ for dirname, version_line in records.items():
+ info = site / dirname
+ info.mkdir(parents = True)
+ (info / "METADATA").write_text(
+ f"Metadata-Version: 2.4\nName: x\n{version_line}\n\nVersion: 0.0.0 in the body\n",
+ encoding = "utf-8",
+ )
+ site.mkdir(parents = True, exist_ok = True)
+ return root
+
+
+DISK_CASES = [
+ ({"unsloth-2026.9.3.dist-info": "Version: 2026.9.3"}, "2026.9.3"),
+ ({"unsloth-2026.9.3.dist-info": "Version: 2026.9.3\r"}, "2026.9.3"),
+ # unsloth_zoo must not be read as unsloth.
+ ({"unsloth_zoo-2026.9.1.dist-info": "Version: 2026.9.1"}, ""),
+ # Duplicate records: the version is ambiguous, so say nothing.
+ (
+ {
+ "unsloth-2026.9.3.dist-info": "Version: 2026.9.3",
+ "unsloth-2026.10.1.dist-info": "Version: 2026.10.1",
+ },
+ "",
+ ),
+ ({}, ""),
+]
+
+
[email protected](shutil.which("sh") is None, reason = "POSIX shell is unavailable")
[email protected]("records, expected", DISK_CASES)
+def test_posix_previous_version_read_from_disk(tmp_path, records, expected):
+ source = INSTALL_SH.read_text(encoding = "utf-8")
+ helper = _extract(r"^_dist_version_from_disk\(\) \{.*?^\}", source)
+ venv = _fake_venv(tmp_path / "venv", records)
+ result = subprocess.run(
+ [
+ "sh",
+ "-c",
+ f'set -eu\n{helper}\nprintf "[%s]" "$(_dist_version_from_disk "$1" unsloth)"',
+ "sh",
+ str(venv),
+ ],
+ check = True,
+ capture_output = True,
+ text = True,
+ )
+ assert result.stdout == f"[{expected}]"
+
+
[email protected](shutil.which("pwsh") is None, reason = "PowerShell is unavailable")
[email protected]("records, expected", DISK_CASES)
+def test_windows_previous_version_read_from_disk(tmp_path, records, expected):
+ source = INSTALL_PS1.read_text(encoding = "utf-8")
+ helper = _extract(r"^ function Get-PackageVersionFromDisk \{.*?^ \}", source)
+ venv = _fake_venv(tmp_path / "venv", records, windows = True)
+ result = run_pwsh(
+ [
+ "pwsh",
+ "-NoProfile",
+ "-NonInteractive",
+ "-Command",
+ f"{helper}; Write-Output \"[$(Get-PackageVersionFromDisk -VenvRoot '{venv}' -Name 'unsloth')]\"",
+ ],
+ check = True,
+ capture_output = True,
+ text = True,
+ )
+ assert result.stdout.strip() == f"[{expected}]"
+
+
+REPORT_CASES = [
+ ("", ""),
+ ("2026.9.3", " (was 2026.9.3)"),
+ (None, " (unchanged)"),
+]
+
+
[email protected](shutil.which("sh") is None, reason = "POSIX shell is unavailable")
[email protected]("previous, suffix", REPORT_CASES)
+def test_posix_installer_reports_previous_version(previous, suffix):
+ current = version("pytest")
+ previous = current if previous is None else previous
+ reporter = _extract(
+ r"^_installed_package_version_exit=0.*?^fi.*?^fi",
+ INSTALL_SH.read_text(encoding = "utf-8"),
+ )
+ result = subprocess.run(
+ [
+ "sh",
+ "-c",
+ (
+ 'step() { printf "%s %s\\n" "$1" "$2"; }\n'
+ 'substep() { printf "WARN %s\\n" "$1"; }\n'
+ f"_VENV_PY={sys.executable!r}\n"
+ "PACKAGE_NAME=pytest\n"
+ f"_PREV_PACKAGE_VERSION={previous!r}\n"
+ f"{reporter}"
+ ),
+ ],
+ check = True,
+ capture_output = True,
+ text = True,
+ )
+ assert result.stdout.strip() == f"pytest {current} installed{suffix}"
+
+
[email protected](shutil.which("pwsh") is None, reason = "PowerShell is unavailable")
[email protected]("previous, suffix", REPORT_CASES)
+def test_windows_installer_reports_previous_version(previous, suffix):
+ current = version("pytest")
+ previous = current if previous is None else previous
+ reporter = _extract(
+ r" \$installedPackageVersion = .*?^ if .*?^ \} else \{.*?^ \}",
+ INSTALL_PS1.read_text(encoding = "utf-8"),
+ )
+ result = run_pwsh(
+ [
+ "pwsh",
+ "-NoProfile",
+ "-NonInteractive",
+ "-Command",
+ (
+ 'function step { param($Label, $Value) Write-Output "$Label $Value" }; '
+ 'function substep { param($Message, $Color) Write-Output "WARN $Message" }; '
+ f"$VenvPython = '{sys.executable}'; $PackageName = 'pytest'; "
+ f"$script:PrevPackageVersion = '{previous}'; "
+ f"{reporter}"
+ ),
+ ],
+ check = True,
+ capture_output = True,
+ text = True,
+ )
+ assert result.stdout.strip() == f"pytest {current} installed{suffix}"