Repository navigation
Keep uv, its cache and the uv-managed Python inside a custom UNSLOTH_STUDIO_HOME - #13373
Conversation
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. |
|
@codex security review |
… and only isolate a usable cache
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 14ec194337
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| out = {**(env if env is not None else os.environ)} | ||
| if not (out.get("UV_PYTHON_INSTALL_DIR") or "").strip(): | ||
| out["UV_PYTHON_INSTALL_DIR"] = str(STUDIO_HOME / "python") |
There was a problem hiding this comment.
Keep custom-home updates on the Studio uv cache
When a custom home's recorded cache is missing or has been emptied while uv's profile-default cache is warm, _with_studio_uv_cache() selects that shared cache and places it in env; this new custom-home helper copies the selected UV_CACHE_DIR unchanged. studio/setup.sh then treats it as an explicit caller value, so unsloth studio update downloads packages onto the profile drive and may backfill the shared path into the marker, defeating the isolation this change promises. The custom-home case needs to select the writable Studio cache before the warm-default fallback while still preserving a genuinely caller-supplied UV_CACHE_DIR.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: the install records the Studio cache and fills it, so update only reaches the shared default if the user empties the Studio cache while a shared one is warm. Installs from before this change keep their recorded cache on purpose.
| bin_dir = STUDIO_HOME / "bin" | ||
| current = out.get("PATH", "") | ||
| if (bin_dir / ("uv.exe" if os.name == "nt" else "uv")).is_file() and str( |
There was a problem hiding this comment.
Direct replacement uv installs into the custom home
When the custom install has no private uv—for example, the original install reused a system uv that is later removed or no longer present on the update process's PATH—this branch does nothing beyond leaving <home>/bin off PATH. Because it also does not pass UV_INSTALL_DIR or UV_UNMANAGED_INSTALL, both setup scripts install their replacement uv into the profile-default location (and may persist that location on the user PATH), contrary to the custom-home isolation promised here. Set a private install destination for custom-home updates when the caller has not supplied one, even when the binary does not exist yet.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: it needs a system uv the install relied on to disappear later. Pointing setup's uv install at the home would mean exporting astral's install variables into every setup run, which costs more than this case is worth.
| if not (bin_dir / ("uv.exe" if os.name == "nt" else "uv")).is_file(): | ||
| return | ||
| current = os.environ.get("PATH", "") | ||
| if str(bin_dir) not in current.split(os.pathsep): | ||
| os.environ["PATH"] = str(bin_dir) + os.pathsep + current if current else str(bin_dir) |
There was a problem hiding this comment.
Preserve explicit uv destinations at backend startup
When a custom home still contains a private uv from an earlier install but the caller later selects UV_INSTALL_DIR, UV_UNMANAGED_INSTALL, or XDG_BIN_HOME and places that uv on PATH, this startup hook unconditionally prepends the stale <studio>/bin copy. The installers explicitly suppress their private destination when any of those overrides is present, so leaving the old file behind is expected; overriding PATH here makes on-demand installs run the wrong, potentially below-minimum uv instead of the caller-selected one. Apply the same explicit-destination guard before prepending the private binary.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: a stale uv in the home plus an explicit uv destination set after the install is not a path anyone takes. The home's uv is the pinned release the installer chose, so it is still a valid uv.
|
Codex Review: Didn't find any major issues. Bravo. 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". |
… Python store to engine installs
|
Codex Review: Didn't find any major issues. Breezy! 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". |
|
Codex Review: Didn't find any major issues. 👍 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". |
|
|
…under strict mode
… stale private uv
…tead of putting it first on PATH
…inner version guard
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 49b800e91a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| if (uv_dir / ("uv.exe" if os.name == "nt" else "uv")).is_file(): | ||
| os.environ["PATH"] = _path_with_first(os.environ.get("PATH", ""), str(uv_dir)) |
There was a problem hiding this comment.
Validate the private uv before prepending it
When the private uv is stale or nonfunctional and its replacement download fails while a usable system uv remains on PATH, both installer paths can continue successfully, leaving the stale file in place. This startup hook checks only is_file() and then shadows the working system uv, so subsequent engine/package installs execute the known-bad private copy. Unlike the earlier explicit-destination case, the fresh evidence is the installers' tolerated refresh-failure path; validate the private binary/version before moving its directory first on PATH.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: it needs a future uv floor above the pinned release, a failed replacement download on that reinstall, and a working system uv, all at once. Even then the home's uv is the pinned release the installer chose, so on-demand installs still run; a version probe on every backend start costs more than this case is worth.
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
…re on main's always-uv-managed Windows path
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! 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". |
Part of #11327
Problem
UNSLOTH_STUDIO_HOME(andSTUDIO_HOME) move the Studio install to a custom folder, but the installers still put the large uv pieces on the profile drive:~/.cache/uv,%LOCALAPPDATA%\uv\cache) whenever one was populated~/.local/share/uv/python,%APPDATA%\uv\python)~/.local/bin; on Windows also winget or the user PATH in the registrySo a user who points the home at
E:\Unslothto save space onC:still gets several GB onC:(the CUDA torch wheels alone are a few GB of cache). On Windows the uv install also edited the user PATH, which env-override mode otherwise promises not to do (#5190).Change
Opt-in: only when
UNSLOTH_STUDIO_HOME(or itsSTUDIO_HOMEalias) names a root other than the default~/.unsloth/studio. Default installs, Desktop, Docker's explicitUV_CACHE_DIR, andUNSLOTH_HOMEon its own are unchanged. At runtime the backend andunsloth studio updatekey on<home>/uvand<home>/python, which only the opt-in installer creates, since every launch exportsUNSLOTH_STUDIO_HOMEand so its presence proves nothing.--isolated-uv-cache), as long as it passes the existing usability probe; otherwise the existing selector and fallback run as before. An explicitUV_CACHE_DIRstill wins.UV_PYTHON_INSTALL_DIR=<home>/pythonunless the user set it.install.ps1restores the variable afterwards, since underirm | iexit is the user's session.<home>/uvdirectory: no winget, no user PATH or shell profile edit (astral'sUV_UNMANAGED_INSTALLfor the script fallback ininstall.sh). Re-runs find it there first. An explicitUV_INSTALL_DIR/UV_UNMANAGED_INSTALL/XDG_BIN_HOMEstill wins.<home>/uvfirst when it holds a uv (only uv binaries live there), and defaultsUV_PYTHON_INSTALL_DIRto<home>/python. The managed engine installer's child environment passesUV_PYTHON_INSTALL_DIRthrough, so the ROCm engine's managed Python lands in the home as well.unsloth studio update: runs setup directly. For an opted-in home it now passesUV_UNMANAGED_INSTALL=<home>/uvandUV_PYTHON_INSTALL_DIR=<home>/python: a uv already on PATH is used as before; otherwise setup version-checks the home's uv and installs or replaces it there, with no profile or user PATH edit. Without this, an update installed uv into~/.local/binand added a PATH line to~/.profile.python/oruv/in it, so the uninstaller still recognises a partial install. A stale private uv is reinstalled in place rather than shadowed.The uninstaller already removes a marked custom root whole, so
python/anduv/go with it.Testing
Real
install.shruns, base (main) vs this branch, same script otherwise: sandboxedHOMEwith a populated shared uv cache,UNSLOTH_STUDIO_HOMEelsewhere, cleanPATHwith no uv,UV_PYTHON_PREFERENCE=only-managed(a host without a suitable Python),UNSLOTH_NO_TORCH=1.HOME(profile drive)UNSLOTH_STUDIO_HOME~/.local/share/uv/python/cpython-3.13.14.../python3.13<home>/python/cpython-3.13.14.../python3.13/api/healthHOMEunsloth studio updatepath on the same custom-home install, with a cleanPATH: onmainsetup installed uv into~/.local/binand wroteexport PATH=".../.local/bin:$PATH"to~/.profile; with this PR nothing is written underHOME.The backend change was checked against that install: with a clean
PATH,shutil.which("uv")goes fromNoneto<home>/uv/uvaftersetup_cache_env(), andUV_PYTHON_INSTALL_DIRis<home>/python.On real Windows (
windows-latest, the Windows Application Control lane, which installs withUNSLOTH_STUDIO_HOME=C:\Users\Public\issue-8490-home): onmainwinget installed uv 0.13.0 system-wide and printed "Path environment variable modified"; with this PR winget is skipped, the pinned uv 0.12.1 goes into the home and the PATH is left alone, and the install still passes under the AppLocker rule. The Windows installer differential lane (default home, base vs head on two runners) reports no difference, so default installs are unchanged..github/scripts/clean-machine-assert.shasserted that uv lives outside the Studio home ($HOME/.local/bin), which is exactly what this changes; it now requires uv to be classified as a native binary wherever it lives.tests/python/test_custom_studio_home_keeps_uv.py(9 tests) runs the newinstall.ps1block under PowerShell and theinstall.shblocks undersh, and covers the backend and update lookups. All of them fail onmain. These existing suites still pass:test_cross_platform_parity.py,test_windows_uv_cache_selection.py,test_windows_uv_managed_python.py,test_windows_python_venv_hardening.py, the Windows ARM Python suites,test_setup_master_root.py,test_studio_update_uv_cache.py(684 tests), plustests/sh/test_install_uv_cache_root.sh,test_uv_cache_adaptive_selection.sh,test_uv_pinned_release.shandtest_portable_isolated_venv.sh.Not in this PR
UNSLOTH_HOME(portable mode) already move that.~/.unsloth/studioand ignores these variables. That is the Desktop half of [Feature Request] Allow Windows Desktop to configure the backend installation directory #11327 and needs its own change.