Skip to content

Consolidate dual venvs and separate install from update - #4530

Merged
danielhanchen merged 52 commits into
mainfrom
feature/consolidate-envs
Mar 25, 2026
Merged

danielhanchen merged 52 commits into
mainfrom
feature/consolidate-envs

Conversation

@rolandtannous

@rolandtannous rolandtannous commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Consolidates dual venvs into a single ~/.unsloth/studio/unsloth_studio — previously install.sh created one venv and setup.sh nuked it and created a separate .venv, resulting in duplicate environment storage space
  • Separates concerns: install.sh handles first-time setup (system deps, uv, venv creation, unsloth install), setup.sh handles updates (frontend build, python deps, llama.cpp)
  • Smart updates: setup.sh checks installed version against PyPI and skips Python dep reinstallation when already up to date
  • Adds --local flag to install.sh and unsloth studio update for editable installs from a local repo checkout (no wheel build needed for testing)
  • Adds --package flag to install.sh and unsloth studio update for testing with custom package names (e.g. test PyPI uploads)
  • Adds unsloth studio update command alongside existing setup command
  • Adds global unsloth symlink to ~/.local/bin and adds ~/.local/bin to the user's shell profile (~/.bashrc, ~/.zshrc, or ~/.profile) if not already on PATH, so the CLI works without activating the venv
  • Fixes frontend 404 when launching via CLI by resolving static files from the installed package
  • Linux only — Windows changes (install.ps1, setup.ps1) will be handled in a separate PR

Architecture

install.sh (used for install)

→ system deps, uv, create unsloth_studio
→ uv pip install unsloth
→ SKIP_STUDIO_BASE=1 setup.sh
    → unsloth_studio exists ✓, activate
    → install_python_stack.py (SKIP_STUDIO_BASE=1 → skips base.txt, skips installing unsloth since already installed)
    → frontend build, llama.cpp build
→ auto-launch

setup.sh (used for install and update operations)

→ unsloth_studio exists? No → error: "Run install.sh first"
→ unsloth_studio exists? Yes → activate
→ install_python_stack.py (SKIP_STUDIO_BASE not set → reinstalls base.txt
   with latest unsloth if PyPI differs from currently installed)
→ frontend rebuild if sources changed
→ llama.cpp rebuild

Flows

  1. Fresh machine: curl ... | sh — creates venv, installs unsloth once, setup skips base, builds frontend/llama.cpp, launches
  2. unsloth studio update — reuses unsloth_studio, reinstalls base.txt (picks up new unsloth version), rebuilds frontend if needed
  3. unsloth studio update with no unsloth_studio — errors with "Run install.sh first"
  4. unsloth studio — launches correctly from existing venv

Files changed

File What
install.sh Single venv path, --local/--package flags, calls setup.sh directly, symlinks to ~/.local/bin
studio/setup.sh No more venv nuke/creation, PyPI version check, accepts env vars from install.sh
studio/install_python_stack.py SKIP_STUDIO_BASE / STUDIO_LOCAL_INSTALL / STUDIO_PACKAGE_NAME env vars, uv bootstrap before pip
studio/backend/colab.py Updated venv path .venv → unsloth_studio
unsloth_cli/commands/studio.py Added update command with --local / --package, frontend path resolution fix

Testing

The --local and --package flags were added to allow testing this branch before a PyPI release.

First-time install Update
Local repo ./install.sh --local unsloth studio update --local
Custom package ./install.sh --package roland-sloth unsloth studio update --package roland-sloth
Production ./install.sh unsloth studio update

Results

  • ./install.sh --local
  • unsloth studio update --local
  • ./install.sh --package roland-sloth
  • unsloth studio update --package roland-sloth
  • ./install.sh (production, requires merge + PyPI release)
  • unsloth studio update (production)
  • Windows (separate PR)

Rebase conflict resolution

Rebased on main after #4489 and #4527 were merged. Resolved 3 conflicts:

  1. install.sh — kept main's new version_ge / _uv_version_ok helpers from gate on min uv version and shortcut python candidate search if known #4489, used our $VENV_DIR path and auto-launch logic
  2. studio/setup.sh — kept main's run_quiet / run_quiet_no_exit helpers from gate on min uv version and shortcut python candidate search if known #4489, used our SKIP_STUDIO_BASE banner logic, removed Python discovery (our change)
  3. unsloth_cli/commands/studio.py — kept main's run_kwargs variable name from Fix Studio silently exiting on Windows without error output #4527 (trivial rename)

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request streamlines the Unsloth Studio installation and update process by consolidating virtual environments, separating concerns between installation and updates, and introducing flags for local development and custom package testing. It also enhances the CLI experience and fixes a frontend path resolution issue, making the setup more robust and user-friendly.

Highlights

  • Venv Consolidation: Consolidated dual virtual environments into a single ~/.unsloth/studio/unsloth_studio to simplify the environment setup.
  • Separation of Concerns: Separated the installation and update processes, with install.sh handling initial setup and setup.sh managing updates.
  • Smart Updates: setup.sh now checks the installed version against PyPI to avoid unnecessary reinstallation of Python dependencies.
  • Local and Package Flags: Added --local and --package flags to install.sh and unsloth studio update for testing with local repositories and custom package names.
  • CLI Enhancement: Introduced the unsloth studio update command and a global unsloth symlink for easier CLI access.
  • Frontend Path Resolution: Resolved the frontend 404 error by correctly resolving static files from the installed package.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request refactors the Unsloth Studio installation and update scripts across Windows (PowerShell) and Linux/macOS (Bash) to standardize the virtual environment location under ~/.unsloth/studio/unsloth_studio and improve the installation workflow. Key changes include introducing new command-line flags (--local, --package) for install.sh to support local repository installations and custom package names, updating Python dependency installation logic in studio/install_python_stack.py to handle these new modes and conditionally skip base package reinstallation, and refining studio/setup.sh to remove redundant Python discovery and add dependency update checks. The unsloth_cli is also updated to reflect the new venv path and introduce an update command. Review comments highlight an issue in install.sh where the --package flag's argument parsing is not robust, potentially leading to silent failures if no value is provided, and a redundant variable redefinition in install.ps1 that could be removed for clarity.

I am having trouble creating individual review comments. Click here to see my feedback.

install.sh (13-23)

high

The argument parsing for --package is not fully robust. If --package is provided as the last argument without a value, the script will not fail and will proceed with the default PACKAGE_NAME. This could lead to unexpected behavior. You should add a check after the loop to ensure that if _next_is_package is true, the script exits with an error.

for arg in "$@"; do
    if [ "$_next_is_package" = true ]; then
        PACKAGE_NAME="$arg"
        _next_is_package=false
        continue
    fi
    case "$arg" in
        --local) STUDIO_LOCAL_INSTALL=true ;;
        --package) _next_is_package=true ;;
    esac
done

if [ "$_next_is_package" = true ]; then
    echo "❌ ERROR: --package requires an argument." >&2
    exit 1
fi

install.ps1 (201)

medium

The variable $UnslothExe is being redefined here. It was already defined on line 175. This redefinition is redundant and can be removed for better code clarity and maintainability.

@Datta0

Datta0 commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

I tested the local package install method on AWS B20O instance (linux) fresh install and it works

@danielhanchen danielhanchen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! The goal of this PR is to consolidate the dual Studio venvs into a single ~/.unsloth/studio/unsloth_studio, separate install from update concerns, and add developer testing flags (--local/--package). As a summary, this PR rewrites the install/update flow so that install.sh creates the venv and setup.sh only updates an existing one, adds unsloth studio update CLI command, a global symlink, and PyPI version-check optimization.

Reviewers Severity Finding
7/8 High setup.sh deletes legacy ~/.unsloth/studio/.venv before checking if new unsloth_studio exists -- destroys working installs during upgrade
7/8 High setup.sh hard-requires ~/.unsloth/studio/unsloth_studio -- breaks documented editable/nightly flows that use activated developer venvs
6/8 Medium env $_SETUP_ENV bash "$SETUP_SH" is unquoted word-splitting -- fragile with spaces in PACKAGE_NAME
5/8 Medium PyPI version check skips ALL Python dep repair -- won't fix partially broken env or missing .venv_t5/
5/8 Medium install.sh unconditionally destroys existing venv on every run (regression from old skip-if-valid behavior)
4/8 Medium update() doesn't explicitly set/clear STUDIO_PACKAGE_NAME for default -- stale env vars can be inherited
4/8 Medium --local path uses SCRIPT_DIR.parent as repo root -- wrong from site-packages; also unsloth-zoo missing in --local/--package installs
4/8 Low [ -t 0 ] auto-launch checks stdin (pipe for curl | sh) -- auto-launch never triggers in primary install flow
3/8 Low Banner "Setup Complete!" is 1 char shorter than "Update Complete!" causing box misalignment
3/8 Low setup() CLI command is now identical to update() with defaults -- confusing

Concrete suggestions for each finding below.

Comment thread studio/setup.sh Outdated
[ -d "$REPO_ROOT/.venv_overlay" ] && rm -rf "$REPO_ROOT/.venv_overlay"
[ -d "$REPO_ROOT/.venv_t5" ] && rm -rf "$REPO_ROOT/.venv_t5"
# Clean up old .venv path (replaced by unsloth_studio)
[ -d "$STUDIO_HOME/.venv" ] && rm -rf "$STUDIO_HOME/.venv"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[7/8 reviewers] High: This line deletes the existing legacy ~/.unsloth/studio/.venv before checking whether the new unsloth_studio venv exists. On an upgrade from current main, existing users have ~/.unsloth/studio/.venv as their only working environment. This script removes it unconditionally and then errors out at line 225 with "Run install.sh first", leaving the user with no working Studio venv at all.

The fix is to migrate the legacy venv instead of deleting it:

Suggested change
[ -d "$STUDIO_HOME/.venv" ] && rm -rf "$STUDIO_HOME/.venv"
# Migrate old .venv path to unsloth_studio (if new path doesn't exist yet)
if [ ! -x "$VENV_DIR/bin/python" ] && [ -x "$STUDIO_HOME/.venv/bin/python" ]; then
echo "==> Migrating legacy Studio environment to $VENV_DIR"
mv "$STUDIO_HOME/.venv" "$VENV_DIR"
fi
# Clean up old .venv path only after migration succeeded
[ -d "$STUDIO_HOME/.venv" ] && rm -rf "$STUDIO_HOME/.venv"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone has .venv, they're on the old version with the old dual-venv flow and likely outdated/stale dependencies. Migrating it would just carry forward old problems into the new setup. The intended upgrade path is to run install.sh which creates a fresh unsloth_studio from scratch — that's the whole point of separating install from update. The error message already tells them to run install.sh. We could improve the message to mention the environment location changed, but migrating the old venv defeats the purpose of this refactor. please advise

Comment thread studio/setup.sh Resolved
Comment thread install.sh Resolved
Comment thread studio/setup.sh

if [ -n "$INSTALLED_VER" ] && [ -n "$LATEST_VER" ] && [ "$INSTALLED_VER" = "$LATEST_VER" ]; then
echo "✅ $_PKG_NAME $INSTALLED_VER is up to date (matches PyPI latest)"
_SKIP_PYTHON_DEPS=true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[5/8 reviewers] Medium: Version string equality check skips ALL Python dependency work (including install_python_stack, .venv_t5/ pre-install, and all extras). If the env is partially broken (e.g., unsloth is current but unsloth-zoo, transformers, or .venv_t5/ are missing/corrupt), unsloth studio update will not repair it.

Consider adding a health check alongside the version check:

Suggested change
_SKIP_PYTHON_DEPS=true
if [ -n "$INSTALLED_VER" ] && [ -n "$LATEST_VER" ] && [ "$INSTALLED_VER" = "$LATEST_VER" ] \
&& [ -d "$VENV_T5_DIR" ] \
&& "$VENV_DIR/bin/python" -c "import fastapi; import importlib.metadata as m; m.version('unsloth_zoo')" >/dev/null 2>&1; then
echo "\u2705 $_PKG_NAME $INSTALLED_VER is up to date (matches PyPI latest)"
_SKIP_PYTHON_DEPS=true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The time required to health-check every dependency (and we have a lot of them) would be close to or exceed the time to just reinstall the whole environment. If someone has a broken env, the intended path is to re-run install.sh which nukes and rebuilds from scratch. That's the whole point of separating install (fresh start) from update (quick version bump).

  • Broken env? → ./install.sh
  • Want latest version? → unsloth studio update

Adding a health check to the update path would defeat the purpose of making it fast.

Comment thread install.sh Resolved
Comment thread unsloth_cli/commands/studio.py Resolved
Comment thread studio/install_python_stack.py Resolved
Comment thread install.sh Resolved
Comment thread studio/setup.sh Resolved
Comment thread unsloth_cli/commands/studio.py Resolved
@Imagineer99

Copy link
Copy Markdown
Member

Tested on Linux (WSL): ./install.sh --package roland-sloth, unsloth studio update --package roland-sloth, and unsloth studio

All behaved as expected. Confirmed ~/.unsloth/studio/unsloth_studio with working Python and no ~/.unsloth/studio/.venv.

@danielhanchen

Copy link
Copy Markdown
Member

unsloth_cli/commands/ui.py:35 still references the old .venv path. Since studio.py:88 was updated to "unsloth_studio", this file should match:

# Current (line 35):
studio_venv_dir = STUDIO_HOME / ".venv"

# Should be:
studio_venv_dir = STUDIO_HOME / "unsloth_studio"

Without this, in_studio_venv is always False when running inside the new unsloth_studio venv, so unsloth ui always re-execs through run.py instead of importing run_server directly.

Also line 72 still references the deprecated command:

# Current (line 72):
typer.echo("Studio not set up. Run 'unsloth studio setup' first.")

# Should be:
typer.echo("Studio not set up. Run install.sh first.")

danielhanchen and others added 9 commits March 25, 2026 01:04
…udio.py

install.ps1 was creating the venv CWD-relative ($VenvName = "unsloth_studio"),
setup.ps1 was using an absolute path to ".unsloth\studio\.venv", and studio.py
looks for ".unsloth\studio\unsloth_studio". All three paths were different, so
the Windows installer would never produce a working Studio setup.

install.ps1:
- Use absolute $StudioHome + $VenvDir matching the Linux install.sh layout
- Add 3-way migration: old .venv at STUDIO_HOME, CWD-relative ~/unsloth_studio
  from the previous install.ps1, or fresh creation with torch validation
- For migrated envs, upgrade unsloth while preserving existing torch/CUDA wheels
- Set SKIP_STUDIO_BASE=1 before calling setup.ps1 (matches install.sh behavior)
- Fix launch instructions to use the absolute venv path

setup.ps1:
- Change $VenvDir from ".unsloth\studio\.venv" to ".unsloth\studio\unsloth_studio"
- Add SKIP_STUDIO_BASE guard: error out if venv is missing when called from
  install.ps1 (which should have already created it)
- Differentiate "Setup" vs "Update" in banners based on SKIP_STUDIO_BASE
setup.sh always errors out if the venv does not exist (line 224-228),
telling the user to run install.sh first. setup.ps1 was conditionally
creating a bare venv with python -m venv when SKIP_STUDIO_BASE was not
set, which would produce an empty venv with no torch or unsloth. Now
setup.ps1 matches setup.sh: always error, always point to install.ps1.
…dows

On CPU-only machines, `uv pip install unsloth --torch-backend=auto`
falls back to unsloth==2024.8 because the CPU solver cannot satisfy
newer unsloth's dependencies. install.ps1 already solved this with a
two-step approach; this applies the same fix to install.sh and
install_python_stack.py.

install.sh: add get_torch_index_url() that detects GPU via nvidia-smi
and maps CUDA versions to PyTorch index URLs (matching install.ps1's
Get-TorchIndexUrl). Fresh installs now install torch first via explicit
--index-url, then install unsloth with --upgrade-package to preserve
the pre-installed torch. All 5 --torch-backend=auto removed from
primary paths.

install.ps1: add fallback else-branch when TorchIndexUrl is empty,
using --torch-backend=auto as last resort (matching install.sh).

install_python_stack.py: remove unconditional --torch-backend=auto
from _build_uv_cmd. Torch is pre-installed by install.sh/setup.ps1
by the time this runs. Callers that need it can set UV_TORCH_BACKEND.

Both install.sh and install.ps1 now share the same three-branch logic:
migrated env (upgrade-package only), normal (torch-first + index-url),
and fallback (--torch-backend=auto if URL detection fails).
For migrated environments (moved from legacy venv location),
--reinstall-package is better than --upgrade-package because it forces
a clean reinstall even if the same version is already installed. This
ensures proper .dist-info and .pyc state in the new venv location.

--upgrade-package remains correct for the fresh install path where
torch is already installed and we just want to add unsloth without
re-resolving torch.
@danielhanchen

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request significantly refactors the Unsloth Studio installation and update process for both Windows (PowerShell) and Linux/macOS (Bash). The virtual environment path is standardized to ~/.unsloth/studio/unsloth_studio, with robust migration logic implemented for existing installations. The install scripts are now responsible for creating the virtual environment and initial package installations, including intelligent GPU detection for PyTorch. The setup scripts (invoked via unsloth studio update) now focus on updating existing packages and system-level setup. The unsloth ui command has been removed, consolidating functionality under unsloth studio, and a new unsloth studio update command is introduced for flexible dependency updates. New cross-platform tests ensure the consistency and correctness of the installation logic. I have no feedback to provide.

- Replace grep -oP (GNU Perl regex) with POSIX sed in
  get_torch_index_url() so the script works on BSD grep (macOS is
  already guarded by the Darwin early-return, but Alpine/BusyBox
  would silently get the wrong CUDA tag)
- Add LC_ALL=C before nvidia-smi invocation to prevent locale-dependent
  output parsing issues
- Add warning on stderr when nvidia-smi output is unparseable, matching
  install.ps1's [WARN] message
- Add explicit unsloth-zoo positional arg to install.ps1 migrated path,
  matching install.sh (--reinstall-package alone won't install it if it
  was never present in the migrated env)
- Fix stale comment in install_python_stack.py line 392 that still
  claimed --torch-backend=auto is added by _build_uv_cmd
- Add sed to test tools directory (function now uses sed instead of grep)
The migrated path runs uv pip install with --reinstall-package for
unsloth/unsloth-zoo. While uv should keep existing torch as satisfied,
the resolver could still re-resolve torch as a transitive dependency.
Without --index-url pointing at the correct CUDA wheel index, the
resolver would fall back to plain PyPI and potentially pull CPU-only
torch. Adding --index-url $TORCH_INDEX_URL ensures CUDA wheels are
available if the resolver needs them.

Applied to both install.sh and install.ps1.
The original install.ps1 on main already handles the migrated path
without --index-url and it works correctly. --reinstall-package only
forces reinstall of the named packages while uv keeps existing torch
as satisfied. No need for the extra flag.
studio.py sets STUDIO_LOCAL_REPO when --local is passed, but
install_python_stack.py never read it. The update path always
installed from PyPI regardless of the --local flag.

Add a local_repo branch that first updates deps from base.txt
(with --upgrade-package to preserve torch), then overlays the
local checkout as an editable install with --no-deps.
@danielhanchen
danielhanchen merged commit 19e9c60 into main Mar 25, 2026
4 checks passed
@danielhanchen
danielhanchen deleted the feature/consolidate-envs branch March 25, 2026 12:24
shibizhao pushed a commit to shibizhao/unsloth-npu that referenced this pull request Apr 7, 2026
* refactor: consolidate dual venvs into single ~/.unsloth/studio/unsloth_studio

* refactor: separate install.sh (first-time) from setup.sh (smart update with PyPI version check)

* fix: install.sh calls setup.sh directly, keep both setup and update CLI commands

* fix: use importlib.resources.files() directly without _path attribute

* fix: bootstrap uv before pip upgrade to handle uv venvs without pip

* fix: frontend 404 when launched via CLI, add global symlink to ~/.local/bin

* feat: add --local flag to install.sh and unsloth studio update for branch testing

* fix: resolve repo root from script location for --local installs

* feat: add --package flag to install.sh for testing with custom package names

* feat: add --package flag to unsloth studio update

* fix: always nuke venv in install.sh for clean installs

* revert: remove Windows changes, will handle in separate PR

* fix: error when --package is passed without an argument

* revert: restore Windows scripts to current main

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: always explicitly set STUDIO_LOCAL_INSTALL and STUDIO_PACKAGE_NAME env vars

* fix: pass explicit STUDIO_LOCAL_REPO env var for --local installs

* fix: align banner box for Setup vs Update labels

* deprecate: hide 'unsloth studio setup' command, point users to update/install.sh

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: check stdout not stdin for auto-launch detection (curl pipe fix)

* fix: update install URL to unsloth.ai/install.sh

* fix: update install.sh usage comments to unsloth.ai/install.sh

* fix: use --upgrade-package for base deps to preserve existing torch/CUDA installs

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: --local install now also installs unsloth-zoo via base.txt before editable overlay

* fix: don't skip base packages for --local installs (editable needs unsloth-zoo)

* refactor: move --local full dep install to install.sh, keep SKIP_STUDIO_BASE for all paths

* feat: add migration support for old .venv and CWD-based installs in setup.sh

* Revert "feat: add migration support for old .venv and CWD-based installs in setup.sh"

This reverts commit 301291d.

* feat: migrate old .venv layout in install.sh instead of always nuking

* feat: validate old .venv with torch CUDA test before migration, recovery message on launch failure

* fix: try CUDA then fall back to CPU for migration validation

* fix: upgrade unsloth/unsloth-zoo with --reinstall-package on migration to preserve torch

* remove: delete unused unsloth ui command (use unsloth studio instead)

* Fix Windows venv path mismatch between install.ps1, setup.ps1, and studio.py

install.ps1 was creating the venv CWD-relative ($VenvName = "unsloth_studio"),
setup.ps1 was using an absolute path to ".unsloth\studio\.venv", and studio.py
looks for ".unsloth\studio\unsloth_studio". All three paths were different, so
the Windows installer would never produce a working Studio setup.

install.ps1:
- Use absolute $StudioHome + $VenvDir matching the Linux install.sh layout
- Add 3-way migration: old .venv at STUDIO_HOME, CWD-relative ~/unsloth_studio
  from the previous install.ps1, or fresh creation with torch validation
- For migrated envs, upgrade unsloth while preserving existing torch/CUDA wheels
- Set SKIP_STUDIO_BASE=1 before calling setup.ps1 (matches install.sh behavior)
- Fix launch instructions to use the absolute venv path

setup.ps1:
- Change $VenvDir from ".unsloth\studio\.venv" to ".unsloth\studio\unsloth_studio"
- Add SKIP_STUDIO_BASE guard: error out if venv is missing when called from
  install.ps1 (which should have already created it)
- Differentiate "Setup" vs "Update" in banners based on SKIP_STUDIO_BASE

* setup.ps1: unconditionally error if venv missing, matching setup.sh

setup.sh always errors out if the venv does not exist (line 224-228),
telling the user to run install.sh first. setup.ps1 was conditionally
creating a bare venv with python -m venv when SKIP_STUDIO_BASE was not
set, which would produce an empty venv with no torch or unsloth. Now
setup.ps1 matches setup.sh: always error, always point to install.ps1.

* Fix --torch-backend=auto CPU solver dead-end on Linux, macOS, and Windows

On CPU-only machines, `uv pip install unsloth --torch-backend=auto`
falls back to unsloth==2024.8 because the CPU solver cannot satisfy
newer unsloth's dependencies. install.ps1 already solved this with a
two-step approach; this applies the same fix to install.sh and
install_python_stack.py.

install.sh: add get_torch_index_url() that detects GPU via nvidia-smi
and maps CUDA versions to PyTorch index URLs (matching install.ps1's
Get-TorchIndexUrl). Fresh installs now install torch first via explicit
--index-url, then install unsloth with --upgrade-package to preserve
the pre-installed torch. All 5 --torch-backend=auto removed from
primary paths.

install.ps1: add fallback else-branch when TorchIndexUrl is empty,
using --torch-backend=auto as last resort (matching install.sh).

install_python_stack.py: remove unconditional --torch-backend=auto
from _build_uv_cmd. Torch is pre-installed by install.sh/setup.ps1
by the time this runs. Callers that need it can set UV_TORCH_BACKEND.

Both install.sh and install.ps1 now share the same three-branch logic:
migrated env (upgrade-package only), normal (torch-first + index-url),
and fallback (--torch-backend=auto if URL detection fails).

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Use --reinstall-package for migrated envs on both Linux and Windows

For migrated environments (moved from legacy venv location),
--reinstall-package is better than --upgrade-package because it forces
a clean reinstall even if the same version is already installed. This
ensures proper .dist-info and .pyc state in the new venv location.

--upgrade-package remains correct for the fresh install path where
torch is already installed and we just want to add unsloth without
re-resolving torch.

* Address review findings: portability, parity, and stale comments

- Replace grep -oP (GNU Perl regex) with POSIX sed in
  get_torch_index_url() so the script works on BSD grep (macOS is
  already guarded by the Darwin early-return, but Alpine/BusyBox
  would silently get the wrong CUDA tag)
- Add LC_ALL=C before nvidia-smi invocation to prevent locale-dependent
  output parsing issues
- Add warning on stderr when nvidia-smi output is unparseable, matching
  install.ps1's [WARN] message
- Add explicit unsloth-zoo positional arg to install.ps1 migrated path,
  matching install.sh (--reinstall-package alone won't install it if it
  was never present in the migrated env)
- Fix stale comment in install_python_stack.py line 392 that still
  claimed --torch-backend=auto is added by _build_uv_cmd
- Add sed to test tools directory (function now uses sed instead of grep)

* Add --index-url to migrated env path to prevent CPU torch resolution

The migrated path runs uv pip install with --reinstall-package for
unsloth/unsloth-zoo. While uv should keep existing torch as satisfied,
the resolver could still re-resolve torch as a transitive dependency.
Without --index-url pointing at the correct CUDA wheel index, the
resolver would fall back to plain PyPI and potentially pull CPU-only
torch. Adding --index-url $TORCH_INDEX_URL ensures CUDA wheels are
available if the resolver needs them.

Applied to both install.sh and install.ps1.

* Revert --index-url on migrated env path

The original install.ps1 on main already handles the migrated path
without --index-url and it works correctly. --reinstall-package only
forces reinstall of the named packages while uv keeps existing torch
as satisfied. No need for the extra flag.

* Fix unsloth studio update --local not installing local checkout

studio.py sets STUDIO_LOCAL_REPO when --local is passed, but
install_python_stack.py never read it. The update path always
installed from PyPI regardless of the --local flag.

Add a local_repo branch that first updates deps from base.txt
(with --upgrade-package to preserve torch), then overlays the
local checkout as an editable install with --no-deps.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants