Skip to content

Windows installer: always build Studio on a uv-managed Python, never one already installed - #13399

Merged
danielhanchen merged 6 commits into
mainfrom
win-uv-managed-python
Oct 12, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
win-uv-managed-python

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

The Windows installer now always builds the Studio environment on a uv-managed CPython (default 3.13), never on a Python already installed on the machine. This applies to fresh installs, reinstalls and Windows on ARM; the desktop app runs the same install.ps1.

Why

A fresh native Windows install (RTX PRO 6000 + RTX 5090, driver 591.86) on a machine that already had Python 3.12.6 logged Python 3.12 already installed, built the environment on it, and so missed the cu130 torch 2.13 route (cp313 only): torch 2.11.0+cu130 and no flash-attn, causal-conv1d or mamba-ssm, since every prebuilt-wheels-cu13 Windows wheel is cp313 for torch 2.13 / 2.14. Find-CompatiblePython returned any system 3.13, 3.12 or 3.11 it found, uv only provided Python when none existed (#7825), and Windows on ARM never used uv at all. UNSLOTH_PYTHON=3.13 did not help either: the search still fell back to 3.12. The header also advertised a --python flag that the argument parser silently ignored.

What changes

  • One resolver. Resolve-UvManagedPython -Minor -Patch -Arch asks uv for an arch-qualified build (cpython-3.13-windows-x86_64-none, or aarch64), with --no-bin --no-registry so nothing on PATH or in the py launcher changes, then uv python find --system --managed-python. It runs the interpreter (-S -I) and refuses anything that is not the requested minor, architecture and GIL build. A skipped patch (3.13.8 cannot import torch) is stepped past by asking for the next patch, since an arch-qualified key takes no version range.
  • Chosen before uv, resolved after it, and before the old environment is touched. The minor and architecture are decided first: Windows on ARM still runs x64 Python under emulation unless the native CUDA stack applies or UNSLOTH_ALLOW_ARM64_PYTHON is set, as before. The interpreter is resolved once uv is installed, before the existing environment is moved aside. A failed native ARM64 resolve degrades to x64 as today.
  • No system fallback. If uv cannot download (offline, UV_PYTHON_DOWNLOADS=never), a runtime uv installed earlier is used; otherwise the installer stops with the fix (UV_PYTHON_INSTALL_MIRROR, or uv python install cpython-3.13-windows-x86_64-none once while online) and says the existing environment was not changed.
  • Reinstalls keep their minor. install.ps1 rebuilds the environment on every run; it now rebuilds on a uv-managed Python of the minor the old one was on (from its pyvenv.cfg), so torch stays the release it was and comes from the uv cache. UNSLOTH_TORCH_UPGRADE=1 (Settings > Repair) moves it to 3.13 and torch 2.13.
  • --python X.Y[.Z] / --python=X.Y[.Z] now work; precedence --python > UNSLOTH_PYTHON > the existing minor > 3.13. An explicit request must be 3.11 to 3.13 and is exact.
  • Legacy layouts (.venv, ~/unsloth_studio) are only moved in and reused when their base lies in uv's own store; otherwise a fresh environment is built and the old one is left where it was.
  • Removed: Find-CompatiblePython, the winget / python.org Python bootstraps, Install-X64Python, Resolve-WindowsOnArmX64Python, Get-StudioVenvBasePython and the WoA re-probe/re-select loop, which only existed to steer the system-Python choice. winget is still used for uv.

Windows staging (windows-2022 and windows-11-arm, no GPU, cu130 forced, every runner Python except 3.12 masked)

leg Python torch flash-attn causal-conv1d
base (main), fresh 3.12.10, system 2.11.0+cu130 none none
this PR, fresh 3.13.14, uv-managed 2.13.0+cu130 2.8.4 1.7.0
base install, then this PR re-run 3.12.13, uv-managed 2.11.0+cu130 (keeping it) none none
then UNSLOTH_TORCH_UPGRADE=1 3.13.14, uv-managed 2.13.0+cu130 2.8.4 1.7.0
this PR, UV_PYTHON_DOWNLOADS=never stops with uv could not provide Python 3.13 (x86_64); no environment created n/a n/a n/a
base (main), Windows on ARM 3.13.16 x64, python.org install 2.11.0+cu130 none none
this PR, Windows on ARM 3.13.14 x64, uv-managed 2.11.0+cu130 (emulated x64 stays off the 2.13 route, as before) none none

The fresh and upgrade rows ran with #13396 merged in, which installs causal-conv1d and mamba-ssm at setup; both legs also ended with mamba-ssm 2.3.2.post1.

Tests

  • tests/python/test_windows_uv_managed_python.py (43): the arch-qualified request and the exact uv calls; a failed download still finding an earlier runtime; refusing the wrong architecture, a free-threaded build, another minor and unreadable output; stepping past a skipped patch; exact patches; --python / UNSLOTH_PYTHON precedence and validation; the existing-minor rule and its upgrade / explicit overrides; the Windows on ARM arch choice; the x64 degrade and the stops; the legacy base check; and an ordering check that no system-Python path remains and resolution precedes the environment rollback. Removing the arch check, the existing-minor rule or the ARM64 degrade each fails it.
  • Deleted test_windows_arm64_python_choice.py and test_windows_python_313_8_screen.py, and the cases in test_windows_on_arm_python_arch.py, test_windows_python_venv_hardening.py, test_woa_torch_index_persistence.py and test_installer_conda_path_guard.py that exercised the removed discovery and bootstraps. test_installer_profile_hardening.py now expects winget only for uv.
  • Every test file that reads install.ps1 (75): 6349 passed; the four TestProgressStepCountMatchesTotal::test_progress_reaches_total_on_both_core_paths[*-False] cases fail identically on main.

Not covered

  • No Windows GPU in staging; the tester's RTX PRO 6000 / RTX 5090 run used an earlier local patch of the same idea.
  • Whether the reinstall's torch came from the uv cache or the network is not visible in the non-verbose log.
  • Linux install.sh can still use a system python3.13 (it always requests 3.13, so the torch route is unaffected); a follow-up makes it uv-only as well.

…one already installed

A fresh install on a machine with Python 3.12 took that interpreter, so the
cu130 torch 2.13 route (cp313 only) closed and the box got torch 2.11 with
no prebuilt flash-attn / causal-conv1d / mamba-ssm. uv only provided Python
when nothing 3.11-3.13 was installed, and Windows on ARM never used it.

The environment is now always built on a uv-managed CPython, requested by
minor and architecture (cpython-3.13-windows-x86_64-none, or aarch64 for the
native Windows on ARM CUDA stack and UNSLOTH_ALLOW_ARM64_PYTHON), resolved
after uv is installed and before the existing environment is touched. A
reinstall keeps the environment's minor so its cached wheels are reused;
UNSLOTH_TORCH_UPGRADE=1 moves it to 3.13. When uv cannot provide one, an
earlier uv-installed runtime is used, else the installer stops with the
mirror / pre-install fix; there is no system fallback. --python X.Y[.Z] now
works as the header always said, and an explicit request is exact. Legacy
layouts on a non-uv base are rebuilt instead of moved in.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T11:44:56.057371Z 12a7d99 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b93ae3750d

ℹ️ 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".

Comment thread install.ps1 Outdated
Comment on lines +7784 to +7786
if ($legacyOk -and -not (Test-VenvBaseIsUvManaged -VenvDir $OldVenv)) {
substep "legacy environment runs on a Python uv did not install -- creating a fresh environment; the old one stays at $OldVenv" "Yellow"
} elseif ($legacyOk) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor Python overrides when migrating legacy environments

When a healthy legacy .venv is based anywhere in uv's store, this condition migrates and reuses it without checking its Python version. Consequently, a legacy Python 3.12 environment survives even when the user requests an exact --python 3.13.9 or sets UNSLOTH_TORCH_UPGRADE=1; the requested 3.13 runtime is downloaded but never used because the later venv-creation branch sees the migrated interpreter. Check the legacy environment's minor/patch against the request, or rebuild it when an explicit/upgrade request requires another version; the same issue exists in the CWD-relative migration branch.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 9409b1a. Both legacy branches now call Test-LegacyVenvReusable, which also requires the pyvenv.cfg version to match the resolved interpreter: same minor, or the exact patch when --python / UNSLOTH_PYTHON named one. Since an upgrade or explicit request changes the resolved minor, a legacy 3.12 environment is rebuilt on the requested Python instead of being migrated. Covered by test_a_legacy_environment_is_reused_only_on_the_resolved_python.

A legacy .venv / ~/unsloth_studio on a uv-managed base was moved in and kept
even when --python, UNSLOTH_PYTHON or UNSLOTH_TORCH_UPGRADE asked for another
version. It is now reused only when its pyvenv.cfg version matches the
resolved interpreter's minor (its exact patch when one was requested).
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 9409b1a282

ℹ️ 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".

…venv.cfg, older cached patch past a skip

- A legacy .venv / ~/unsloth_studio reinstall keeps its Python minor, as the
  current layout does.
- A legacy environment is reused only on a uv build of the selected
  architecture.
- pyvenv.cfg is read as UTF-8 (uv writes it without a BOM; Windows
  PowerShell 5.1 read it as ANSI and rejected a non-ASCII store path).
- Past a skipped patch the resolver tries the next one, then an older one,
  so an offline machine with 3.13.7 cached still installs.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 12a7d99c80

ℹ️ 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".

danielhanchen added a commit to LeoBorcherding/unsloth that referenced this pull request Oct 12, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

pre-commit.ci run

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.

1 participant