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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
installer: stop condemning a warm uv cache for a directory uv never writes (#10899)
Daniel Hana94ef51a77cf
diff --git a/install.ps1 b/install.ps1index 28bc4d7f955..27ae9f907d7 100644--- a/install.ps1+++ b/install.ps1@@ -1742,14 +1742,27 @@ exit 1# True for a name uv itself creates: <kind>-v<N>, whole suffix numeric. `archive-v0.backup`# is not uv's. Mirrors _uv_is_bucket_name, suffix from the LAST `-v` included.function Test-StudioUvBucketName {- param([Parameter(Mandatory = $true)][AllowEmptyString()][string]$Name)- $at = $Name.LastIndexOf("-v")+ param(+ [Parameter(Mandatory = $true)][AllowEmptyString()][string]$Name,+ # Off by default: warmth counting bytes under `Archive-V0` that uv looks for at+ # `archive-v0` picks a cache that cannot serve them. Only the write probe folds.+ [switch]$Fold+ )+ # Whole name, since the `-v` marker varies with the kind. Invariant: a Turkish+ # locale dots the I in `flat-Index-v4`.+ $lower = if ($Fold) { $Name.ToLowerInvariant() } else { $Name }+ $at = $lower.LastIndexOf("-v")if ($at -lt 0) { return $false }- $suffix = $Name.Substring($at + 2)+ $suffix = $lower.Substring($at + 2)if ([string]::IsNullOrEmpty($suffix)) { return $false }# \A and \z, not ^ and $: in .NET `$` also matches before a final newline, so# `archive-v1<LF>` passed here while the sh helper rejected it.- return ($suffix -match '\A[0-9]+\z')+ if (-not ($suffix -match '\A[0-9]+\z')) { return $false }+ # Every CacheBucket in uv 0.12.1 ($UvPinnedVersion) plus built-wheels; keep in step+ # with install.sh on a pin bump.+ return ($lower.Substring(0, $at) -in @(+ "archive", "binaries", "builds", "built-wheels", "environments", "flat-index",+ "git", "interpreter", "osv", "python", "sdists", "simple", "wheels"))}# Readable is not usable: uv writes CACHEDIR.TAG into the root and renames distributions@@ -1760,13 +1773,23 @@ exit 1param([Parameter(Mandatory = $true)][string]$Cache)$probeDirs = [System.Collections.Generic.List[string]]::new()$probeDirs.Add($Cache)+ # Measured like _uv_cache_is_writable does: NTFS folds unless fsutil+ # setCaseSensitiveInfo says otherwise, which is how a WSL-created tree behaves.+ $fold = $false+ $probeRoot = Join-Path $Cache (".unsloth-case-probe." ++ [guid]::NewGuid().ToString("N").Substring(0, 8) + "-A")+ try {+ [System.IO.Directory]::CreateDirectory($probeRoot) | Out-Null+ $fold = [System.IO.Directory]::Exists($probeRoot.Substring(0, $probeRoot.Length - 1) + "a")+ } catch { }+ Remove-Item -LiteralPath $probeRoot -Force -Recurse -ErrorAction SilentlyContinuetry {foreach ($entry in [System.IO.Directory]::GetFileSystemEntries($Cache)) {$name = [System.IO.Path]::GetFileName($entry)# Only where a BUCKET should be. Anything else up here is not uv's to write,# and a cache-dir on a mount point has a root-owned lost+found that must not# condemn it.- if (-not (Test-StudioUvBucketName -Name $name)) { continue }+ if (-not (Test-StudioUvBucketName -Name $name -Fold:$fold)) { continue }# A file, or a link dangling or not, is an existing path to uv's own create,# which answers "already exists", so uv refuses it.if (-not [System.IO.Directory]::Exists($entry)) { return $false }@@ -1796,6 +1819,7 @@ exit 1try {$buckets = Get-ChildItem -LiteralPath $Cache -Directory -Force -ErrorAction Stop |Where-Object {+ # No -Fold: warmth is exact-case, so every name here is lowercase.(Test-StudioUvBucketName -Name $_.Name) -and($_.Name.Substring(0, $_.Name.LastIndexOf("-v")) -in@("archive", "builds", "built-wheels", "wheels", "sdists"))diff --git a/install.sh b/install.shindex 8fec62d8d13..26a7ac3b926 100755--- a/install.sh+++ b/install.sh@@ -597,6 +597,13 @@ _uv_is_bucket_name() {case "${1##*-v}" in''|*[!0-9]*) return 1 ;;esac+ # Every CacheBucket in uv 0.12.1 (UV_PINNED_VERSION) plus built-wheels; re-read+ # uv-cache/src/lib.rs on a pin bump, or a missing kind goes unprobed and uv fails on it.+ case "${1%-v*}" in+ archive|binaries|builds|built-wheels|environments|flat-index) ;;+ git|interpreter|osv|python|sdists|simple|wheels) ;;+ *) return 1 ;;+ esacreturn 0}@@ -657,11 +664,27 @@ _uv_cache_root_is_writable() {_uv_cache_is_writable() {_uv_cache_root_is_writable "$1" || return 1_uv_w_bad=0+ # Measured, not assumed: default APFS folds, ext4 does not, and an existing `Python-V0`+ # beside `python-v0` is one entry on the first and two on the second. Root already writable.+ _uv_w_fold=0+ _uv_w_probe="$1/.unsloth-case-probe.$$-A"+ if mkdir "$_uv_w_probe" 2>/dev/null; then+ [ -d "$1/.unsloth-case-probe.$$-a" ] && _uv_w_fold=1+ rmdir "$_uv_w_probe" 2>/dev/null || true+ fi+ unset _uv_w_probe_uv_w_glob=oncase $- in *f*) _uv_w_glob=off ;; esacset +ffor _uv_w_dir in "$1"/*; do- _uv_is_bucket_name "${_uv_w_dir##*/}" || continue+ _uv_w_name="${_uv_w_dir##*/}"+ if ! _uv_is_bucket_name "$_uv_w_name"; then+ # Only the NAME is folded here; file or dangling link is the rejection below.+ [ "$_uv_w_fold" = 1 ] || continue+ case "$_uv_w_name" in *[[:upper:]]*) ;; *) continue ;; esac+ _uv_w_lower=$(printf '%s' "$_uv_w_name" | tr '[:upper:]' '[:lower:]')+ _uv_is_bucket_name "$_uv_w_lower" || continue+ fiif [ ! -d "$_uv_w_dir" ]; then# A file, or a symlink dangling or not, is an existing path to mkdir(2).if [ -e "$_uv_w_dir" ] || [ -L "$_uv_w_dir" ]; then@@ -672,7 +695,7 @@ _uv_cache_is_writable() {_uv_cache_root_is_writable "$_uv_w_dir" || _uv_w_bad=1doneif [ "$_uv_w_glob" = off ]; then set -f; fi- unset _uv_w_dir _uv_w_glob+ unset _uv_w_dir _uv_w_glob _uv_w_name _uv_w_lower _uv_w_foldif [ "$_uv_w_bad" -ne 0 ]; thenunset _uv_w_badreturn 1@@ -786,7 +809,11 @@ _configure_uv_cache() {# CRLF, and a WSL install shares $STUDIO_HOME with the Windows one. The other two readers# already defend. Untreated, a CR fails [ -d ] and abandons the warm cache in silence, and# a BOM makes the value non-absolute so $PWD gets prepended.- _uv_recorded=$(cat "$STUDIO_HOME/cache/uv-cache-dir" 2>/dev/null | tr -d '\r') || _uv_recorded=""+ # Trailing CR only, like Read-StudioUvCacheMarker's Trim(): `tr -d` ate CRs inside the path.+ _uv_recorded=$(cat "$STUDIO_HOME/cache/uv-cache-dir" 2>/dev/null) || _uv_recorded=""+ _uv_cr=$(printf '\r')+ _uv_recorded="${_uv_recorded%"$_uv_cr"}"+ unset _uv_cr_uv_bom=$(printf '\357\273\277')_uv_recorded="${_uv_recorded#"$_uv_bom"}"unset _uv_bomdiff --git a/tests/python/test_cross_platform_parity.py b/tests/python/test_cross_platform_parity.pyindex 59f634ddbfd..87b67e62fec 100644--- a/tests/python/test_cross_platform_parity.py+++ b/tests/python/test_cross_platform_parity.py@@ -1235,8 +1235,43 @@ class TestInstallUvCacheRootParity:# rejected it from the start, so this was a real split.bucket_sh = sh.split("_uv_is_bucket_name() {", 1)[1].split("\n}", 1)[0]assert "''|*[!0-9]*) return 1 ;;" in bucket_sh, bucket_sh- bucket_ps1 = ps1.split("function Test-StudioUvBucketName", 1)[1].split("\n}", 1)[0]+ # To the NEXT function: the body is indented, so splitting on "\n}" ran two+ # functions on and every assertion below it read the wrong code.+ bucket_ps1 = ps1.split("function Test-StudioUvBucketName", 1)[1].split(+ "function Test-StudioUvCacheWritable", 1+ )[0]assert "IsNullOrEmpty($suffix)" in bucket_ps1, bucket_ps1+ # Both sides MEASURE whether to fold: default APFS folds and ext4 does not, NTFS+ # folds unless fsutil setCaseSensitiveInfo says otherwise. Blind folding condemns.+ assert "ToLowerInvariant()" in bucket_ps1, bucket_ps1+ assert "-cin" not in bucket_ps1, bucket_ps1+ assert "[switch]$Fold" in bucket_ps1, bucket_ps1+ writable_ps1 = ps1.split("function Test-StudioUvCacheWritable", 1)[1].split(+ "function Test-StudioUvCachePopulated", 1+ )[0]+ assert ".unsloth-case-probe." in writable_ps1, writable_ps1+ assert "-Fold:$fold" in writable_ps1, writable_ps1+ writable_sh = sh.split("_uv_cache_is_writable() {", 1)[1].split("\n}", 1)[0]+ assert "tr '[:upper:]' '[:lower:]'" in writable_sh, writable_sh+ # By a directory the probe MAKES: an existing pair cannot say whether it is one.+ assert ".unsloth-case-probe." in writable_sh, writable_sh+ assert "_uv_w_fold=1" in writable_sh, writable_sh+ # and it decides only the NAME: a colliding file must reach the rejection below.+ assert writable_sh.index("_uv_w_fold") < writable_sh.index('[ ! -d "$_uv_w_dir" ]')+ probe_kinds = {+ "archive", "binaries", "builds", "built-wheels", "environments", "flat-index",+ "git", "interpreter", "osv", "python", "sdists", "simple", "wheels",+ }+ assert 'UV_PINNED_VERSION="0.12.1"' in sh, "re-read uv-cache/src/lib.rs for the new pin"+ case_body = re.search(+ r'case "\$\{1%-v\*\}" in\n(.*?)\n\s*\*\) return 1', bucket_sh, re.S+ ).group(1)+ kinds_sh = set(re.findall(r"[a-z\-]+", case_body))+ assert kinds_sh == probe_kinds, sorted(kinds_sh ^ probe_kinds)+ kinds_ps1 = set(+ re.findall(r'"([a-z\-]+)"', bucket_ps1.split("-in @(", 1)[1].split("))", 1)[0])+ )+ assert kinds_ps1 == probe_kinds, sorted(kinds_ps1 ^ probe_kinds)# and the CLI validates the whole suffix too, or `unsloth studio update` prefers a# cache the installers just rejected. Its docstring claimed the same rule long before# it had it.diff --git a/tests/python/test_windows_uv_cache_selection.py b/tests/python/test_windows_uv_cache_selection.pyindex 2a21748d3f2..0a43bf4c7e4 100644--- a/tests/python/test_windows_uv_cache_selection.py+++ b/tests/python/test_windows_uv_cache_selection.py@@ -427,6 +427,55 @@ def test_a_lost_and_found_does_not_condemn_the_cache(tmp_path):(default / "lost+found").chmod(0o755)+@requires_pwsh+def test_an_unknown_bucket_kind_does_not_condemn_the_cache(tmp_path):+ """Bucket-shaped but not a kind uv creates, so uv never opens it. Refusing the whole cache+ for it redownloaded what the cache already held."""+ default = _warm(tmp_path / "uvdefault")+ (default / "unused-v999").mkdir()+ if os.name != "nt":+ (default / "unused-v999").chmod(0o000)+ try:+ assert _select(tmp_path / "studio", str(default))["mode"] == "shared"+ finally:+ if os.name != "nt":+ (default / "unused-v999").chmod(0o755)+++@requires_pwsh+def test_a_read_only_managed_python_bucket_still_condemns_the_cache(tmp_path):+ """python-v0 IS uv's, since 0.8.16, and the installer installs a managed CPython. Leaving+ it out of the kind list would select a cache the install then fails to write."""+ default = _warm(tmp_path / "uvdefault")+ (default / "python-v0").mkdir()+ if os.name != "nt":+ (default / "python-v0").chmod(0o555)+ try:+ assert _select(tmp_path / "studio", str(default))["mode"] == "studio"+ finally:+ if os.name != "nt":+ (default / "python-v0").chmod(0o755)+++@requires_pwsh+def test_a_differently_cased_bucket_follows_the_filesystem(tmp_path):+ """Where the directory folds, `Python-V0` IS uv's python-v0 and an unwritable one has to+ condemn the cache. Where it does not, as on a case-sensitive NTFS directory or the Linux+ filesystem this runs on, it is a directory uv never opens and must not condemn anything.+ Measured the same way the selector measures it rather than assumed from the platform."""+ default = _warm(tmp_path / "uvdefault")+ (default / "Python-V0").mkdir()+ folds = (default / "python-v0").exists()+ if os.name != "nt":+ (default / "Python-V0").chmod(0o555)+ try:+ expected = "studio" if folds else "shared"+ assert _select(tmp_path / "studio", str(default))["mode"] == expected+ finally:+ if os.name != "nt":+ (default / "Python-V0").chmod(0o755)++@requires_pwshdef test_a_bucket_that_is_not_a_directory_is_refused(tmp_path):"""A file where a bucket goes is an existing path to the create uv makes, which fails."""diff --git a/tests/sh/test_uv_cache_adaptive_selection.sh b/tests/sh/test_uv_cache_adaptive_selection.shindex 91eedf61274..5189c887448 100755--- a/tests/sh/test_uv_cache_adaptive_selection.sh+++ b/tests/sh/test_uv_cache_adaptive_selection.sh@@ -174,6 +174,39 @@ mkdir -p "$_alien/archive-v0/torch" "$_alien/lost+found": > "$_alien/archive-v0/torch/libtorch.so": > "$_alien/CACHEDIR.TAG"chmod 000 "$_alien/lost+found"+# Bucket-SHAPED but not a kind uv creates, so uv never opens it.+_alien_bucket="$_TMP/uvalienbucket"+mkdir -p "$_alien_bucket/archive-v0/torch" "$_alien_bucket/unused-v999"+: > "$_alien_bucket/archive-v0/torch/libtorch.so"+: > "$_alien_bucket/CACHEDIR.TAG"+chmod 000 "$_alien_bucket/unused-v999"+# python-v0 IS uv's, since 0.8.16, and the installer installs a managed CPython.+_managed_python="$_TMP/uvpython"+mkdir -p "$_managed_python/archive-v0/torch" "$_managed_python/python-v0"+: > "$_managed_python/archive-v0/torch/libtorch.so"+: > "$_managed_python/CACHEDIR.TAG"+chmod a-w "$_managed_python/python-v0"+# Case-SENSITIVE: two directories, only the lowercase one uv's. Inferring the fold from the+# pair existing would condemn the cache, which is why the probe makes its own directory.+_cased_bucket="$_TMP/uvcased"+mkdir -p "$_cased_bucket/archive-v0/torch" "$_cased_bucket/Python-V0" "$_cased_bucket/python-v0"+: > "$_cased_bucket/archive-v0/torch/libtorch.so"+: > "$_cased_bucket/CACHEDIR.TAG"+chmod a-w "$_cased_bucket/Python-V0"+_cased_only="$_TMP/uvcasedonly"+mkdir -p "$_cased_only/archive-v0/torch" "$_cased_only/Python-V0"+: > "$_cased_only/archive-v0/torch/libtorch.so"+: > "$_cased_only/CACHEDIR.TAG"+chmod a-w "$_cased_only/Python-V0"+# Asked the same way install.sh asks, so the fold cases below run for real on an APFS runner+# rather than being simulated into always-true on ext4.+_cased_file="$_TMP/uvcasedfile"+mkdir -p "$_cased_file/archive-v0/torch"+: > "$_cased_file/archive-v0/torch/libtorch.so"+: > "$_cased_file/CACHEDIR.TAG"+: > "$_cased_file/Python-V0"+_FOLDS=false+mkdir -p "$_TMP/.foldcheck-A" && [ -d "$_TMP/.foldcheck-a" ] && _FOLDS=true# A bucket NAME needs the whole suffix to be the version: a backup copy or a tarball beside# the real bucket is not uv's to write, and must not condemn the cache._lookalike="$_TMP/uvlookalike"@@ -260,6 +293,26 @@ elseassert_eq "a denied metadata bucket too" "studio" "$(echo "$_out" | cut -d' ' -f1)"_out=$(_run "$_TMP/q" '' "$_alien")assert_eq "lost+found does not condemn it" "shared" "$(echo "$_out" | cut -d' ' -f1)"+ _out=$(_run "$_TMP/q2" '' "$_alien_bucket")+ assert_eq "an unknown KIND does not either" "shared" "$(echo "$_out" | cut -d' ' -f1)"+ _out=$(_run "$_TMP/q3" '' "$_managed_python")+ assert_eq "a read-only python-v0 still does" "studio" "$(echo "$_out" | cut -d' ' -f1)"+ if [ "$_FOLDS" = true ]; then+ _out=$(_run "$_TMP/q4" '' "$_cased_bucket")+ assert_eq "a cased bucket condemns when folded" "studio" "$(echo "$_out" | cut -d' ' -f1)"+ _out=$(_run "$_TMP/q5" '' "$_cased_only")+ assert_eq "so does a lone cased bucket" "studio" "$(echo "$_out" | cut -d' ' -f1)"+ # A FILE collides with uv's mkdir, and only the rejection branch catches it.+ _out=$(_run "$_TMP/q6" '' "$_cased_file")+ assert_eq "and a cased FILE does too" "studio" "$(echo "$_out" | cut -d' ' -f1)"+ else+ _out=$(_run "$_TMP/q4" '' "$_cased_bucket")+ assert_eq "a cased sibling does not condemn" "shared" "$(echo "$_out" | cut -d' ' -f1)"+ _out=$(_run "$_TMP/q5" '' "$_cased_only")+ assert_eq "nor a lone cased directory" "shared" "$(echo "$_out" | cut -d' ' -f1)"+ _out=$(_run "$_TMP/q6" '' "$_cased_file")+ assert_eq "nor a cased file" "shared" "$(echo "$_out" | cut -d' ' -f1)"+ fi_out=$(_run "$_TMP/v1" '' "$_empty_version")assert_eq "an empty -v suffix is not a bucket" "shared" "$(echo "$_out" | cut -d' ' -f1)"fi@@ -287,12 +340,15 @@ for _nc in 0 false; dounset UV_NO_CACHEdonechmod 700 "$_alien/lost+found"+chmod 700 "$_alien_bucket/unused-v999"+chmod u+w "$_managed_python/python-v0" "$_cased_bucket/Python-V0" "$_cased_only/Python-V0"chmod 700 "$_denied_bucket/archive-v0"chmod u+w "$_readonly" "$_readonly_bucket/archive-v0" "$_readonly_late/sdists-v9" \"$_denied_meta/interpreter-v4" "$_empty_version/archive-v1-v"# The probe writes into a directory uv is about to fill, so it has to leave nothing behind._run "$_TMP/g" '' "$_populated" >/dev/nullassert_eq "write probe cleaned up" "" "$(ls -A "$_populated" | grep 'unsloth-write-probe' || true)"+assert_eq "case probe cleaned up" "" "$(ls -A "$_populated" | grep 'unsloth-case-probe' || true)"echo "=== a relative cache-dir resolves against UV_WORKING_DIR, not the installer's cwd ==="_out=$(_run "$_TMP/h" '' "relcache" false "$_TMP/work")@@ -362,6 +418,15 @@ _out=$(_run "$_TMP/crlf" '' "$_populated")assert_eq "a BOM+CRLF marker is honoured" "studio" "$(echo "$_out" | cut -d' ' -f1)"assert_eq "and names the right directory" "$_TMP/crlf/cache/uv" "$(echo "$_out" | cut -d' ' -f2)"+# Stripping every CR made a cache whose name holds one read as a path that does not exist.+_cr=$(printf '\r')+mkdir -p "$_TMP/embedcr/cache" "$_TMP/sha${_cr}red/archive-v0/torch"+: > "$_TMP/sha${_cr}red/archive-v0/torch/libtorch.so"+printf '%s\r\n' "$_TMP/sha${_cr}red" > "$_TMP/embedcr/cache/uv-cache-dir"+_out=$(_run "$_TMP/embedcr" '' "$_empty")+assert_eq "a CR inside the path survives" "$_TMP/sha${_cr}red" "$(echo "$_out" | cut -d' ' -f2)"+unset _cr+echo "=== a trailing slash in the marker is the same directory ==="mkdir -p "$_TMP/slash/cache/uv/archive-v0/torch": > "$_TMP/slash/cache/uv/archive-v0/torch/libtorch.so"diff --git a/unsloth_cli/commands/studio.py b/unsloth_cli/commands/studio.pyindex 929298f0d51..625012d90d4 100644--- a/unsloth_cli/commands/studio.py+++ b/unsloth_cli/commands/studio.py@@ -3177,7 +3177,9 @@ _UV_CACHE_METADATA_SUFFIXES = (".lock", ".msgpack", ".http", ".rev")def _uv_is_bucket_name(name: str) -> bool:"""A name uv itself creates: <kind>-v<N>, whole suffix numeric, kind from the LAST `-v`.- Mirrors _uv_is_bucket_name in install.sh and Test-StudioUvBucketName in install.ps1."""+ Same shape rule as _uv_is_bucket_name in install.sh and Test-StudioUvBucketName in+ install.ps1, over the narrower kind list: this one only answers whether a bucket holds+ package BYTES, where the installers also probe the kinds uv merely writes."""kind, marker, version = name.rpartition("-v")# isascii too: str.isdigit() is true for Arabic-Indic and superscript digits, which the sh# `*[!0-9]*` case and the PowerShell \A[0-9]+\z both reject. uv writes ASCII.