From 3c9f0ed14954d9b803cb58b1df44d1388bb2acb0 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Fri, 27 Mar 2026 02:38:11 -0700 Subject: [PATCH] fix: use unsloth[huggingfacenotorch] instead of --no-deps in no-torch mode (#4647) The previous --no-deps approach skipped ALL dependencies, not just torch. This left safetensors, transformers, datasets, accelerate, etc. missing, causing PackageNotFoundError at runtime. Fix: in no-torch mode, install unsloth[huggingfacenotorch] (which pulls all runtime deps except torch), then install unsloth-zoo with --no-deps (since zoo's published metadata still declares torch as a hard dep). This gives a working no-torch environment with all non-torch packages. Applied to all three installer files: install.sh, install.ps1, and studio/install_python_stack.py. --- install.ps1 | 26 ++++++++++++++++++------ install.sh | 36 +++++++++++++++++++++++----------- studio/install_python_stack.py | 17 +++++++++++----- 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/install.ps1 b/install.ps1 index 41e8efa5c3..83dcf866e5 100644 --- a/install.ps1 +++ b/install.ps1 @@ -620,8 +620,14 @@ shell.Run cmd, 0, False # Migrated env: force-reinstall unsloth+unsloth-zoo to ensure clean state # in the new venv location, while preserving existing torch/CUDA Write-Host "==> Upgrading unsloth in migrated environment..." - $noDepsArg = if ($SkipTorch) { "--no-deps" } else { $null } - uv pip install --python $VenvPython $noDepsArg --reinstall-package unsloth --reinstall-package unsloth-zoo "unsloth>=2026.3.14" unsloth-zoo + if ($SkipTorch) { + # No-torch: install runtime deps via [huggingfacenotorch] extras, + # then unsloth-zoo with --no-deps to avoid pulling torch. + uv pip install --python $VenvPython --reinstall-package unsloth "unsloth[huggingfacenotorch]>=2026.3.14" + uv pip install --python $VenvPython --no-deps --reinstall-package unsloth-zoo unsloth-zoo + } else { + uv pip install --python $VenvPython --reinstall-package unsloth --reinstall-package unsloth-zoo "unsloth>=2026.3.14" unsloth-zoo + } if ($StudioLocalInstall) { Write-Host "==> Overlaying local repo (editable)..." uv pip install --python $VenvPython -e $RepoRoot --no-deps @@ -639,13 +645,21 @@ shell.Run cmd, 0, False } Write-Host "==> Installing unsloth (this may take a few minutes)..." - $noDepsArg = if ($SkipTorch) { "--no-deps" } else { $null } - if ($StudioLocalInstall) { - uv pip install --python $VenvPython $noDepsArg --upgrade-package unsloth "unsloth>=2026.3.14" unsloth-zoo + if ($SkipTorch) { + # No-torch: install runtime deps via [huggingfacenotorch] extras, + # then unsloth-zoo with --no-deps to avoid pulling torch. + uv pip install --python $VenvPython --upgrade-package unsloth "unsloth[huggingfacenotorch]>=2026.3.14" + uv pip install --python $VenvPython --no-deps --upgrade-package unsloth-zoo unsloth-zoo + if ($StudioLocalInstall) { + Write-Host "==> Overlaying local repo (editable)..." + uv pip install --python $VenvPython -e $RepoRoot --no-deps + } + } elseif ($StudioLocalInstall) { + uv pip install --python $VenvPython --upgrade-package unsloth "unsloth>=2026.3.14" unsloth-zoo Write-Host "==> Overlaying local repo (editable)..." uv pip install --python $VenvPython -e $RepoRoot --no-deps } else { - uv pip install --python $VenvPython $noDepsArg --upgrade-package unsloth "$PackageName" + uv pip install --python $VenvPython --upgrade-package unsloth "$PackageName" } } else { # Fallback: GPU detection failed to produce a URL -- let uv resolve torch diff --git a/install.sh b/install.sh index 2024622603..4afa514527 100755 --- a/install.sh +++ b/install.sh @@ -863,13 +863,19 @@ if [ "$_MIGRATED" = true ]; then # Migrated env: force-reinstall unsloth+unsloth-zoo to ensure clean state # in the new venv location, while preserving existing torch/CUDA echo "==> Upgrading unsloth in migrated environment..." - _no_deps_arg="" if [ "$SKIP_TORCH" = true ]; then - _no_deps_arg="--no-deps" + # No-torch: install runtime deps via [huggingfacenotorch] extras, + # then unsloth-zoo with --no-deps to avoid pulling torch. + uv pip install --python "$_VENV_PY" \ + --reinstall-package unsloth \ + "unsloth[huggingfacenotorch]>=2026.3.14" + uv pip install --python "$_VENV_PY" --no-deps \ + --reinstall-package unsloth-zoo unsloth-zoo + else + uv pip install --python "$_VENV_PY" \ + --reinstall-package unsloth --reinstall-package unsloth-zoo \ + "unsloth>=2026.3.14" unsloth-zoo fi - uv pip install --python "$_VENV_PY" $_no_deps_arg \ - --reinstall-package unsloth --reinstall-package unsloth-zoo \ - "unsloth>=2026.3.14" unsloth-zoo if [ "$STUDIO_LOCAL_INSTALL" = true ]; then echo "==> Overlaying local repo (editable)..." uv pip install --python "$_VENV_PY" -e "$_REPO_ROOT" --no-deps @@ -885,17 +891,25 @@ elif [ -n "$TORCH_INDEX_URL" ]; then fi # Fresh: Step 2 - install unsloth, preserving pre-installed torch echo "==> Installing unsloth (this may take a few minutes)..." - _no_deps_arg="" if [ "$SKIP_TORCH" = true ]; then - _no_deps_arg="--no-deps" - fi - if [ "$STUDIO_LOCAL_INSTALL" = true ]; then - uv pip install --python "$_VENV_PY" $_no_deps_arg \ + # No-torch: install runtime deps via [huggingfacenotorch] extras, + # then unsloth-zoo with --no-deps to avoid pulling torch. + uv pip install --python "$_VENV_PY" \ + --upgrade-package unsloth \ + "unsloth[huggingfacenotorch]>=2026.3.14" + uv pip install --python "$_VENV_PY" --no-deps \ + --upgrade-package unsloth-zoo unsloth-zoo + if [ "$STUDIO_LOCAL_INSTALL" = true ]; then + echo "==> Overlaying local repo (editable)..." + uv pip install --python "$_VENV_PY" -e "$_REPO_ROOT" --no-deps + fi + elif [ "$STUDIO_LOCAL_INSTALL" = true ]; then + uv pip install --python "$_VENV_PY" \ --upgrade-package unsloth "unsloth>=2026.3.14" unsloth-zoo echo "==> Overlaying local repo (editable)..." uv pip install --python "$_VENV_PY" -e "$_REPO_ROOT" --no-deps else - uv pip install --python "$_VENV_PY" $_no_deps_arg \ + uv pip install --python "$_VENV_PY" \ --upgrade-package unsloth "$PACKAGE_NAME" fi else diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py index 2402d7c39c..bcd17c4d88 100644 --- a/studio/install_python_stack.py +++ b/studio/install_python_stack.py @@ -440,17 +440,24 @@ def install_python_stack() -> int: if skip_base: print(_green(f"✅ {package_name} already installed — skipping base packages")) elif NO_TORCH: - # No-torch mode: install unsloth + unsloth-zoo without torch deps + # No-torch mode: install runtime deps via [huggingfacenotorch] extras + # (safetensors, transformers, datasets, etc.), then unsloth-zoo with + # --no-deps to avoid pulling torch. _progress("base packages (no torch)") pip_install( - "Updating base packages (no-torch mode)", + "Installing unsloth runtime deps (no-torch mode)", + "--no-cache-dir", + "--upgrade-package", + "unsloth", + "unsloth[huggingfacenotorch]>=2026.3.14", + ) + pip_install( + "Installing unsloth-zoo (no-torch mode)", "--no-cache-dir", "--no-deps", "--upgrade-package", - "unsloth", - "--upgrade-package", "unsloth-zoo", - req = REQ_ROOT / "base.txt", + "unsloth-zoo", ) if local_repo: pip_install(