Repository navigation
Use hybrid uv cache migration for Studio installs - #10204
Conversation
|
Final live verification for PR product head
The immutable pre-fix contract failed on both Windows and Ubuntu. A separate Linux + Windows live run then passed both real installs with populated Studio caches and empty isolated global caches. The staging verification asserts this exact PR head is an ancestor, keeps the regression tree byte-identical, and allows only upstream main's independently verified |
|
Confirmed the installers set no UV_CACHE_DIR before the first uv call and that storage_roots.py only redirects at runtime, so the install-time cache does land outside the Studio root. One thing before I review: pointing a fresh install at an empty |
|
Confirmed—the cost is real and material for a user whose default uv cache already contains the matching artifacts. I ran a controlled A/B on exact PR head
Isolated installer Torch command
That is +25.146 s and ~2.895 GB received (18.1×) for the Torch/vision/audio step on this machine. uv listed 2.75 GB of compressed package downloads, including 506.5 MiB Torch, 403.5 MiB cuBLAS, 349.1 MiB cuDNN, 204.2 MiB cuFFT, 191.6 MiB cuSolver, 187.4 MiB NCCL, and 179.6 MiB Triton. Both installs produced the same versions and Full real installerI then ran the full
So the full-install delta was +48.507 s, +3.962 GB received, and 3.27× wall time. The Torch uv call alone moved from 1.310 s to 26.544 s. The empty Studio cache ended at 7.272 GB by This host has unusually fast networking (~2.9 GB arrived in ~25 s), so the elapsed penalty is likely a lower bound for typical connections. Conclusion: the PR currently does impose a one-time multi-GB redownload on users who rely on uv's default and already have the matching wheels cached. An explicit |
|
Implemented the hybrid policy on
On the same RTX PRO 6000 cu130 machine with a 53.4 GB warm global cache, a real full install took 25.613 s / 0.288 GB RX with reuse versus 72.494 s / 4.280 GB RX into a new Studio cache. Both produced Torch 2.11.0+cu130 with working CUDA and identical package versions. That avoids about 3.99 GB and 46.9 seconds in this environment. Forced isolation was also live-tested: it populated a 1.771 GB Studio cache while the global cache size remained exactly unchanged. Fresh-upstream Actions are green on Ubuntu (114 passed), macOS (143 passed), and Windows (143 passed). The final real Windows shared + isolated install run pinned the exact PR product head and passed: 41,138 shared-cache files, 41,137 isolated Studio-cache files, unchanged shared snapshot during isolation, working CLIs, and caller |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
CI triage note: the red |
Both installer headers say usage and supported options live in the README under "Unsloth Studio (web UI)" and are deliberately not repeated in the script, and Advanced launch options already carries every peer switch this branch sits next to: UNSLOTH_NO_TORCH, UNSLOTH_SKIP_AUTOSTART, UNSLOTH_PYTHON, UNSLOTH_STUDIO_HOME. This branch added UNSLOTH_ISOLATE_UV_CACHE and --isolated-uv-cache to those headers without adding them where the headers point, so the only way to find the switch was to read the installer. Documents the piped env var and the local flag for both shells, and states that an explicit UV_CACHE_DIR still wins over it, which is what the code does: the custom branch returns before the isolation branch is reached. Every invocation shown was run against this branch's own parsers rather than transcribed: --local --isolated-uv-cache and the env var in 1/true/ yes/on all select isolation, absent and 0 do not, on both installers.
Comments only, no code. Two sweeps over the 103 comment lines this branch adds, down to 41. Deleted the ones a test label already says (the artifact lands next to the metadata; a deeper unreadable corner keeps it warm; metadata is not a warm cache) and collapsed the rest to the fact that would otherwise be re-derived: wheels-* is metadata only, -L is what makes find match Get-ChildItem -Recurse, SilentlyContinue is what stops one denied subdirectory reading as an empty cache, unreadable is not empty. comment_tools.py check: 5/5 OK, code unchanged in every file. Tests still green: 45 sh checks under both shells, 121 pytest.
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Three places pick a uv cache and only two of them agreed. install.sh and install.ps1 choose one for the install itself (#10204), and storage_roots._setup_cache_env seeds cache_root()/uv for the backend server. An update reaches neither: `unsloth studio update` runs setup.sh / setup.ps1 straight from the CLI process, nothing on that path sets UV_CACHE_DIR, and _setup_cache_env is only called from the backend, so uv fell back to its own user-wide default. On a fresh install the installer downloads into <StudioHome>/cache/uv and the first update downloads all of it again into ~/.cache/uv or %LOCALAPPDATA%\uv\cache, where uninstall cannot reclaim it. The rule is the installer's own rather than an unconditional redirect: prefer the Studio cache, and defer to uv's default only when the Studio one holds no package bytes and uv's does. _setup_cache_env mkdirs an empty Studio cache on every server start, so a shared-mode install would otherwise be sent to a cache holding nothing -- one duplicate download online, and with UV_OFFLINE, --offline or uv.toml offline = true, where uv may read only what is cached, an update that cannot resolve at all. Whichever cache wins is passed to the child as an explicit absolute path. uv reads UV_CACHE_DIR as --cache-dir, so a blank inherited value is a missing argument rather than an unset one (`UV_CACHE_DIR= uv cache dir` exits 2 with "a value is required"), and uv answers a relative cache-dir with the relative spelling, which setup.sh would resolve from a different directory.
Both tests lifted the studio.conf writer out of install.sh with a sed range that started at the comment "studio.conf: exe path". #10204 removed that comment, so the range came back empty. test_portable_bun_cache_pinned.sh has a non-emptiness guard and said so; test_install_portable_root.sh had none and reported all eleven exports as missing instead, which points at the wrong file. Start at the UNSLOTH_EXE line the block actually writes, and give test_install_portable_root.sh the same guard so an empty range names itself. tests/sh: 0 failures across the directory.
…es (#10386) * Give `unsloth studio update` the same uv cache the install used Three places pick a uv cache and only two of them agreed. install.sh and install.ps1 choose one for the install itself (#10204), and storage_roots._setup_cache_env seeds cache_root()/uv for the backend server. An update reaches neither: `unsloth studio update` runs setup.sh / setup.ps1 straight from the CLI process, nothing on that path sets UV_CACHE_DIR, and _setup_cache_env is only called from the backend, so uv fell back to its own user-wide default. On a fresh install the installer downloads into <StudioHome>/cache/uv and the first update downloads all of it again into ~/.cache/uv or %LOCALAPPDATA%\uv\cache, where uninstall cannot reclaim it. The rule is the installer's own rather than an unconditional redirect: prefer the Studio cache, and defer to uv's default only when the Studio one holds no package bytes and uv's does. _setup_cache_env mkdirs an empty Studio cache on every server start, so a shared-mode install would otherwise be sent to a cache holding nothing -- one duplicate download online, and with UV_OFFLINE, --offline or uv.toml offline = true, where uv may read only what is cached, an update that cannot resolve at all. Whichever cache wins is passed to the child as an explicit absolute path. uv reads UV_CACHE_DIR as --cache-dir, so a blank inherited value is a missing argument rather than an unset one (`UV_CACHE_DIR= uv cache dir` exits 2 with "a value is required"), and uv answers a relative cache-dir with the relative spelling, which setup.sh would resolve from a different directory. * Resolve uv's cache answer the way uv does Two ways the probe could name a directory uv never uses, both measured on the uv this repo pins, 0.10.7. A configured `cache-dir = "~/.myuv"` is printed verbatim and uv treats the tilde as an ordinary relative segment: it creates a literal "~" directory in its working directory, not one in $HOME. expanduser therefore probed a path that does not exist, so a warm configured cache read as cold, or an unrelated $HOME cache was picked up. A relative cache-dir resolves against uv's working directory, and --directory (env alias UV_WORKING_DIR) moves that out from under ours. Measured: with UV_WORKING_DIR set, `uv cache dir` prints "relcache" and the cache lands under UV_WORKING_DIR, not under the caller's cwd. * Fall back to uv's platform cache when the probe cannot answer uv discovers configuration from the CURRENT directory, so a malformed uv.toml beside whoever ran `unsloth studio update` makes `uv cache dir` exit nonzero even though setup.sh changes directory before it runs uv at all. Treating that as "there is no default cache" sent the update to a cold Studio cache: a duplicate download online, and an offline update that cannot resolve despite a populated platform cache. install.sh:646 already falls back to XDG_CACHE_HOME/uv or HOME/.cache/uv in exactly this situation. The probe now does the same, adding LOCALAPPDATA/uv/cache for Windows, and returns nothing only when there is no anchor to build a path from. * Trim the comments this branch added Delete first, collapse second. The rationale that survives names a mistake the next reader would otherwise make: metadata-only caches reading as warm, UnicodeDecodeError escaping an OSError handler, a blank UV_CACHE_DIR exiting 2, uv's literal tilde. The measured numbers and the alternatives considered are in the PR description, which is where they belong. Prose in the added block: 51 lines to 16. * Record which uv cache the install used, instead of inferring it later (#10410) * Record which uv cache the install used, instead of inferring it later Content cannot answer the question the update asks. In shared mode the installers point the running backend at the Studio cache (_prepare_studio_uv_cache_for_launch, Set-StudioUvCacheForLaunch), so one on-demand install from the server (wheel_utils.py:405) leaves package bytes there. Both caches then hold packages, and the update stops preferring the one the install filled: a duplicate download online, and under UV_OFFLINE or uv.toml offline = true an update that cannot resolve. The mirror case is just as wrong, a studio-mode install losing once the user warms their own default cache with an unrelated uv pip install. Both installers now write the cache they chose to <StudioHome>/cache/uv-cache-dir and the update reads it, falling back to inspecting both caches for installs that predate the marker. Every mode records, a caller's own UV_CACHE_DIR included, since that is where the install put its wheels and an earlier marker left in place would aim later updates at a cache this install never filled. A caller keeps control either way: a nonblank UV_CACHE_DIR outranks the marker at update time too. The marker is honoured only while the cache it names still holds packages, so `uv cache clean` does not leave a stale pointer outranking a warm cache. The marker describes the environment, so it travels with it. It is written absolute, since the update resolves it against its own working directory (on PowerShell that needs $PWD explicitly: GetFullPath resolves against the .NET process directory, which Set-Location does not move). The previous contents are saved before the first write and restored wherever a failed install rolls the venv back, and the snapshot resets per run because under `irm | iex` the script scope is the caller's session. An unwritable Studio root skips the marker rather than failing the install. For installs that predate the marker, the update records what the fallback worked out once setup has returned 0, and replaces a marker whose cache has since been emptied. A caller's UV_CACHE_DIR is never promoted: that belongs to one run, and the installers are what record an install. * Reset the marker snapshot before the selector, and restore it on any failure Four fixes, all on the marker's lifecycle. The per-run reset ran AFTER Set-StudioUvCacheEnvironment, which is what writes the marker, so it cleared the snapshot that call had just taken and made both Restore-StudioUvCacheMarker calls no-ops. A failed reinstall kept the new marker. Moved above the call, and the parity test now pins it to the lines directly above rather than anywhere in the file, since searching the file matches the copy inside the restore helper and passes either way. Restoring only from inside the venv rollback missed every failure that happens before a replacement is in flight: a first install has no previous venv, the ownership guard can refuse the directory, the backup move can fail. The restore now runs from the exit and signal handlers on the sh side and from Exit-InstallFailure and the commit guard's finally on the PowerShell side. Test-Path was unsuppressed under $ErrorActionPreference = "Stop". Probing a path inside a directory the ACL denies throws UnauthorizedAccessException rather than returning false, so an optional marker could abort the install. Measured: Test-Path THREW UnauthorizedAccessException on a chmod 000 parent. The reader stripped whole lines. The installers write UV_CACHE_DIR through verbatim and a directory name may legitimately begin or end with a space, so stripping probed a different path and read a warm cache as cold. splitlines already drops the terminator; blank lines are still skipped, since blank means unset. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read the marker the way uv reads a path Same reason the probe stopped expanding: the installers write this path through as uv would read it, and uv treats a leading tilde as an ordinary segment rather than $HOME. Both installers already make the value absolute, so expanduser could only ever have been wrong here, never right. * Tie the marker's lifetime to the environment it describes Eight findings, all on when the marker may be written, reverted or kept. Committing the environment commits the marker. The unconditional restore I added reverted it on any nonzero exit, including after the venv was already committed, so a later failure left the installed environment pointing at the previous install's cache. Both shells now clear the snapshot at the commit. The PowerShell reset moves to the first lines of Install-UnslothStudio. It sat after the lock checks, and nothing clears the flag on success, so under `irm | iex` a second install failing early reverted the marker belonging to the first, which had succeeded. A marker that cannot be read is left alone. `cat` failing was recorded as an empty snapshot with existed=true, so a rollback wrote a blank marker over the previous install's; Get-Content failing left $null, and TrimEnd on it throws inside the rollback, before -ErrorAction can apply. Writes no longer follow symlinks. A redirection, Set-Content and write_text all truncate the target rather than replacing the entry, so a marker path linked elsewhere silently destroyed an unrelated file. Relative caches resolve against uv's working directory, which --directory and UV_WORKING_DIR move, rather than the installer's $PWD. The marker directory is created with the .NET API, since New-Item -Path treats brackets in a custom Studio root as a wildcard, as this installer already notes at two other call sites. The backfill is suppressed during a staged update: STUDIO_HOME names the live install there, and the stage can still be rejected. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Anchor a relative uv working directory, and clear the marker with the venv flag UV_WORKING_DIR may itself be relative, and uv resolves it against the directory the installer ran from before it resolves the cache under it. Recording "work/cache" would name somewhere else at update time. Both shells anchor the base first; on PowerShell that has to be $PWD.Path, since GetFullPath would use the .NET process directory instead. The commit cleared the marker flag after the venv flag and after the backup deletion. A signal in that window kept the newly committed environment, because venv rollback was already inactive, and reverted the marker it came with, because that flag was still set. Both are cleared together now, and a parity test asserts the order rather than mere presence. * Commit the marker on a first install, gate its write, and record paths as bytes Three items from the last review. The commit cleared _UV_MARKER_SAVED inside the rollback branch, and a first install has no previous environment, so it took no branch and left the marker revertible. Anything failing after that point, the shim-path guard or a signal, kept the newly installed environment and reverted the marker it came with. Both shells clear it before the branch now. The unlink that keeps a symlinked marker from truncating what it points at can fail silently, on a directory that denies deletion while the target stays writable. Both writes now happen only once the entry is confirmed gone; on PowerShell that probe is Get-Item -Force, since Test-Path follows the link and reports a broken one as absent. A POSIX path may hold bytes that are not UTF-8, and Python hands those over as surrogates. Encoding them raised UnicodeEncodeError, which is not an OSError and escaped the best-effort handler, failing an update whose setup had already succeeded and whose old marker was already unlinked. The path is written with os.fsencode and read back with surrogateescape. Two of the existing marker cases in the rollback suite were passing vacuously: _record_uv_cache_choice sits outside the spliced block, so the harness exited 127 before writing anything, which satisfied every expectation about a marker that must not change. The helper is spliced alongside the others and the cases now fail if the harness writes to stderr or dies on a missing command. * Tighten the comments added by this PR Comments and docstrings only, no code. Verified with comment_tools.py check and by rerunning the suites: 183 passed, the two sh suites under sh, dash and bash, and all 24 pwsh studio tests. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * Publish a staged update's cache choice, and treat a malformed marker as cold Two items from the last review. A desktop update never runs the direct path, so suppressing the backfill under --stage left exactly the installs the marker exists for permanently on the content fallback. The staged child still cannot write the live marker, since STUDIO_HOME names the environment it is replacing and the stage may never activate, so it parks the choice in the stage root and _studio_stage.stage promotes it after the probes pass. A stage that fails verification publishes nothing, and a stage that parks nothing leaves the live marker alone. A marker holding an embedded NUL builds a Path fine and then raises ValueError, not OSError, out of scandir, so a corrupted or hand-edited file aborted every update before setup ran. That cache reads as cold now, which is what the rest of this code already does with a cache it cannot inspect. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Probe uv where setup will run it, and record the marker unambiguously Two items from the last review. Both setup scripts change into their own directory before the dependency pass (studio/setup.sh:1788), and uv discovers uv.toml and pyproject.toml from its working directory. The probe asked from the caller's, so running an update while standing in an unrelated project answered with that project's cache, and the answer is then forced on the child through UV_CACHE_DIR. It now runs with the setup script's directory as its working directory, and resolves a relative answer against that same base. A newline is legal in a POSIX path and uv reports one verbatim, but the marker reader split the record into lines and kept the last fragment, so such a cache read as absent and the update redirected uv elsewhere. The record is one path followed by one delimiter now: strip that delimiter, keep everything else. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Make one install agree with itself about its cache, and commit in one step Six items from the last review. setup.ps1 never changes directory: it addresses everything through PSScriptRoot and hands install_python_stack.py the cwd it inherited, so probing from the script's directory answered for a configuration that child never sees. The probe now uses the directory setup will actually run uv from, which is the script's on POSIX and the inherited one on Windows. UV_WORKING_DIR may itself be relative, and uv resolves it after starting where the probe started, so it is anchored to the probe's directory rather than to wherever the update was launched. uv reports a cache path verbatim, and stripping the reported line changed a directory name that legitimately ends in a space. Blank lines are still dropped. A relative UV_CACHE_DIR named a different directory in each phase of one install, because setup.sh changes into its own directory before the dependency pass. It is resolved once, before anything reads it, so both phases and the marker agree. What is restored afterwards is still the caller's own spelling. Windows PowerShell 5.1 decodes a BOM-less file with the active ANSI code page, and the update writes this marker BOM-less UTF-8, so a non-ASCII path was read back as mojibake and restored that way. It is read as UTF-8 explicitly. The commit cleared two flags, and a signal between them put the previous environment back while keeping the marker of the attempt that replaced it. One flag decides both rollbacks now, set first and alone, and both restores consult it. * Resolve the Windows cache through one helper, and leave ambiguous installs alone Two items from the last review. The custom branch on Windows anchored a relative UV_CACHE_DIR to $PWD alone, ignoring UV_WORKING_DIR, and rooting it that way also stopped the marker writer from applying its own resolution. From C:\work with UV_WORKING_DIR=subdir and UV_CACHE_DIR=cache, uv uses C:\work\subdir\cache and the installer recorded C:\work\cache. Both call Resolve-StudioUvCachePath now, which mirrors _absolutize_uv_cache_dir. An install that predates the marker cannot say which cache it used, and content cannot tell either: the running backend is pointed at the Studio cache even in shared mode, so one on-demand wheel warms it. Where both caches are warm and no marker settles it, the update keeps uv's default, which is what such an install has been updating from all along. Preferring the Studio cache there was a new way for an offline update to fail on an install that cannot record its way out. A Studio cache that wins on content alone still wins when uv's default is cold, which is the case this PR exists for, and a recorded marker still settles both. * Tighten the comments this branch added Comments and docstrings only, no code. Verified with comment_tools.py check and by rerunning the suites: 238 passed, both sh suites under sh, dash and bash, and all 24 pwsh studio tests. * Stay out of the way when uv is told not to cache Confirmed against uv 0.10.7: UV_NO_CACHE=1 makes `uv cache dir` report a temporary directory that is discarded when the process exits. The probe inherited that, read the throwaway as cold, and the update then seeded a UV_CACHE_DIR that --no-cache outranks anyway and recorded it as the install's cache. On an install predating the marker that redirected every later update to a cache nothing had ever filled. Neither seeds nor records now, on uv's own boolish spelling of the variable: 0 and false leave caching on, and a value uv cannot parse is one it refuses to run on at all, which is not the same as running without a cache. * Tighten the comments the last change added Comments and docstrings only, no code. Verified with comment_tools.py check and by rerunning the suites: 246 passed, both sh suites under sh, dash and bash, and all 24 pwsh studio tests. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Both tests lifted the studio.conf writer out of install.sh with a sed range that started at the comment "studio.conf: exe path". #10204 removed that comment, so the range came back empty. test_portable_bun_cache_pinned.sh has a non-emptiness guard and said so; test_install_portable_root.sh had none and reported all eleven exports as missing instead, which points at the wrong file. Start at the UNSLOTH_EXE line the block actually writes, and give test_install_portable_root.sh the same guard so an empty range names itself. tests/sh: 0 failures across the directory.
Summary
UV_CACHE_DIRunchanged.<StudioHome>/cache/uvfor new or empty-cache installs.--isolated-uv-cacheorUNSLOTH_ISOLATE_UV_CACHE=1; this always uses the Studio cache and warns that cached packages may download again.Both
install.shandinstall.ps1implement the same priority and print which cache policy was selected.Root cause
Both installers resolve the Studio root before installation, but previously left
UV_CACHE_DIRunset. Install-timeuv venvanduv pip installtherefore used uv's user-wide platform cache. Runtime cache setup happens only after installation when Studio starts, which is too late for those commands.The pre-fix contract was reproduced on immutable source
87ab4ed7c9646bdf4281a0b7d5058156b404da23:Both runs reached uv 0.11.29, confirmed uv's platform default and caller-override semantics, and failed only because neither installer configured the install-time cache.
UX validation
The first revision always chose an empty Studio cache. On a real RTX PRO 6000 cu130 machine with a populated 53.4 GB global uv cache, that caused a material duplicate-download penalty. The hybrid revision was then validated with real installs on exact product head
7f9784fab29434133979a9a8bb458dcf616f099f:--no-torch)For the full Torch install, reusing the populated cache avoided approximately 3.99 GB and 46.9 seconds on unusually fast networking. New users still get Studio-owned storage, while existing users do not silently redownload multi-gigabyte wheels.
Verification
Focused regressions:
bash -n install.sh tests/sh/test_install_uv_cache_root.shsh tests/sh/test_install_uv_cache_root.sh: 29 passedbash tests/sh/test_install_uv_cache_root.sh: 29 passedpytest tests/python/test_windows_python_venv_hardening.py tests/python/test_cross_platform_parity.py: 85 passed, 29 platform-specific skipped locallygit diff --check, worktree safety checks, and PR safety scan passedFresh-upstream fork CI on the exact PR product head:
UV_CACHE_DIRwas absent again in the caller after each install.Fixes #10193