Skip to content

Studio: torch 2.13 for new Linux cu130 Python 3.13 installs, existing installs keep their torch - #12150

Merged
danielhanchen merged 18 commits into
mainfrom
studio-torch-213-cu130
Oct 2, 2026
Merged

danielhanchen merged 18 commits into
mainfrom
studio-torch-213-cu130

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

New Studio installs on Linux x86_64 with an NVIDIA driver on the cu130 route and Python 3.13 now get torch 2.13, together with the prebuilt-wheels-cu13 flash-attn 2.8.4, causal-conv1d 1.7.0 and mamba-ssm 2.3.2.post1 wheels built for it. Existing installs keep the torch they have.

What changes

New installs (install.sh): one new route, used only when all of these hold:

  • the resolved torch index is cu130 (driver >= 13.0, no pre-Turing GPU, which is capped to cu126 before this point)
  • Linux or WSL on x86_64
  • the venv is CPython 3.13, since the prebuilt wheels are cp313 only
  • the newest unsloth on PyPI declares a torch range that contains 2.13.0

That route installs torch>=2.13.0,<2.14.0, torchvision>=0.28.0,<0.29.0 and torchaudio 2.11. torchaudio 2.11 is the last release (stable ABI, no torch pin), and vLLM 0.30 and SGLang 0.5.20 use the same pairing: both pin torch 2.13.0. Every other route keeps its current window unchanged: cu126, cu128, CPU, ROCm, XPU, macOS, aarch64, Windows, and Python 3.11/3.12.

Why the PyPI check: unsloth studio update first runs the setup code bundled in the installed release. That code re-resolves unsloth under the release's own torch cap. With 2026.9.11 (torch<2.13.0), a torch 2.13 install was swapped for PyPI's generic torch 2.12.1 on the first update and lost the matching prebuilt kernels (reproduced below). Until a release admits 2.13, the route stays off and new installs get exactly what they get today. Any fetch or parse failure answers no. UNSLOTH_PYPI_JSON_URL can point the check at a mirror.

Existing installs:

  • Kept-release pin: it is now checked against its own torch>=2.4,<2.15.0 window, not the new-install spec, so a re-run keeps any 2.4 to 2.14 release. Before this, raising the default would also have moved every 2.11 user.
  • torchaudio pairing: a kept torch minor of 12 or newer now pairs with torchaudio 2.11.* instead of a 2.12.* / 2.13.* that does not exist.
  • studio update repairs (_ensure_cuda_torch, _ensure_expected_torch_flavor): on the cu130 route they reinstall the resident release instead of the <2.12 range, which would have downgraded a 2.13 install.
  • studio update core package step: pins a resident torch >= 2.13 through UV_OVERRIDE, the same way install.sh already freezes the trio for every with-deps unsloth install.
  • Opting in: UNSLOTH_TORCH_UPGRADE=1 or a fresh home still moves an existing install to the new default.
  • Desktop "Repair installation": the manual repair in Settings now runs the installer with UNSLOTH_TORCH_UPGRADE=1, so a user who asks for a reinstall gets the newest supported torch. The automatic startup repair is unchanged and keeps the resident release.
  • Legacy homes: an old ~/.unsloth/studio/.venv whose interpreter is missing or broken still counts as an existing install, so it keeps its recorded torch instead of taking the new-install route.

Real installs on a B200 (driver 590, isolated HOME and UNSLOTH_STUDIO_HOME per cell)

"future PyPI" is PyPI's current unsloth metadata with only the torch cap changed to <2.15.0, served through UNSLOTH_PYPI_JSON_URL.

Cell Start Action Python torch torchvision flash-attn libtorch_cuda sha
main empty main installer 3.13.14 2.11.0+cu130 0.26.0 2.8.1 (upstream torch2.10) d5ea4f10
G empty this branch, live PyPI 3.13.14 2.11.0+cu130 0.26.0 2.8.1 d5ea4f10
A3 empty this branch, future PyPI 3.13.14 2.13.0+cu130 0.28.0 2.8.4 (prebuilt-wheels-cu13) 181dfc4f
H A3 installer re-run 3.13.14 2.13.0+cu130 0.28.0 2.8.4 181dfc4f
E A3, unsloth rolled back to 2026.9.10 studio update --local against PyPI's real <2.13.0 3.13.14 2.13.0+cu130 0.28.0 2.8.4 181dfc4f
E on main code same start studio update with main's setup code 3.13.14 2.12.1 (PyPI) 0.27.1 2.8.1 b6024fd9
C main install (2.11) this branch re-run, future PyPI 3.13.14 2.11.0+cu130 0.26.0 2.8.1 d5ea4f10
C same studio update --local 3.13.14 2.11.0+cu130 0.26.0 2.8.1 d5ea4f10
D 2.11 install UNSLOTH_TORCH_UPGRADE=1 re-run 3.13.14 2.13.0+cu130 0.28.0 2.8.4 181dfc4f
F empty --python 3.12, future PyPI 3.12.12 2.11.0+cu130 0.26.0 2.8.1 fd13a41b

Studio's own on-demand installers on the A3 venv pulled causal_conv1d-1.7.0+cu13torch2.13 and mamba_ssm-2.3.2.post1+cu13torch2.13 from the release, and both import.

On the A3 venv (torch 2.13.0+cu130), 20 LoRA SFT steps each on GPU 2, with a CUDA profiler pass on step 5:

Model Losses (first 3 ... last 2) Finite Peak memory flash-attn kernels in the profile
unsloth/Qwen3-0.6B 2.508, 2.022, 1.569 ... 1.82, 1.532 yes 1.88 GB flash_fwd_kernel, flash_bwd_dq_dk_dv_loop_seqk_parallel_kernel
unsloth/granite-4.0-h-350m 2.725, 2.471, 1.821 ... 2.174, 1.803 yes 13.04 GB forward, split-kv and backward kernels

Direct kernel checks on the same venv: flash-attn forward matches SDPA to 0.0081 max abs error, causal-conv1d forward runs, and mamba-ssm forward and backward run.

Rechecked on a B200 at the current head

Case Result
Fresh home, release admits 2.13 torch 2.13.0+cu130; flash-attn 2.8.4, causal-conv1d 1.7.0, mamba-ssm 2.3.2.post1 installed from prebuilt-wheels-cu13, each kernel matches its reference (bf16 flash-attn max error 0.016)
LoRA SFT on that install (unsloth/Qwen3-0.6B, 30 steps) all checks pass, loss 4.09 to 0.23, peak 1.38 GB
Main install (torch 2.11.0+cu130), then this installer existing install has torch 2.11.0+cu130 -- keeping it
Same home with UNSLOTH_TORCH_UPGRADE=1 (what the manual repair now sets) torch 2.13.0+cu130 with flash-attn 2.8.4

Tests

  • New tests/sh/test_cu130_torch213_route.sh (80 checks, including the legacy home cases) covers the route predicate across index, OS, arch, Python and PyPI answers, plus the preservation window, the torchaudio pairing, and the kept pin being evaluated against the preservation window. Against main's install.sh: 25 of 36 fail (before the PyPI gate checks were added).
  • New studio/backend/tests/test_cu130_repair_torch_specs.py (29 tests) covers the repair specs and the core-update freeze. Every non-cu130 route returns the identical spec object.
  • Desktop: only_a_manual_repair_asks_the_installer_for_a_newer_torch; all 654 cargo test tests pass.
  • Existing installer suites: all 80 tests/sh scripts pass. tests/python, tests/studio/install and the spec tests fail the same 5 tests on this branch and on its merge base (torchcodec provenance, RL config pickling and dependency-pass tests, which this venv cannot satisfy).

Release order

The published cap comes from the pip branch. #12152 raises it to <2.15.0, and #12151 adds the matching Core extras. This route turns itself on once a release with that ceiling is on PyPI, whatever order the PRs merge in.

Not tested here

  • Windows, macOS and ROCm installs are unchanged by construction (their windows and code paths are untouched) but were not run on hardware.
  • Pre-Turing GPUs never reach cu130 (capped earlier in the same script); this was not run on such a GPU.

Cloud and AMD runs

These ran from a branch combining this PR with #11491 and #12024: studio/setup.sh --local followed by a 5 step LoRA SFT on unsloth/Qwen2.5-0.5B-Instruct. Colab T4, L4, A100 and G4 all passed with finite losses on Colab's system torch 2.11.0+cu130, so an existing torch is kept. Kaggle 2x T4 passed on both GPUs with torch 2.10+cu128. On AMD Strix Halo gfx1151, torch stayed at 2.11.0+rocm7.13.0 on both base and head, re-running the installer kept it, and the training loss matched (NO_REGRESSION).

The switchboard (Studio journeys on merge base vs head) reported no functional regression: 47 SAME and one DOM-only difference with 0 changed pixels. The Desktop repair dialog text cannot be rendered on this host.

…eep existing torch

The prebuilt-wheels-cu13 release ships flash-attn, causal-conv1d and mamba-ssm for
torch 2.13 and 2.14 on cp313 linux_x86_64 cu13. New installs on exactly that route
now get torch 2.13 (the release vLLM and SGLang pin) with torchvision 0.28 and
torchaudio 2.11. Every other route keeps its window unchanged.

Existing installs keep their torch: the kept-release pin is evaluated against its
own 2.4-2.14 window instead of the new-install spec, the kept pairing asks for
torchaudio 2.11 once the torch minor is past it, and studio update repairs on the
cu130 route reinstall the resident release rather than a range.
…e torch >= 2.13 through core updates

studio update first runs the setup code of the installed release, which upgrades
unsloth under its own torch cap: with 2026.9.11 (torch<2.13.0) a torch 2.13 install
was swapped for PyPI's generic 2.12.1 and lost its prebuilt kernels. The 2.13 route
now also requires the newest unsloth on PyPI to admit torch 2.13, answering no on
any fetch or parse failure, and the core package update pins a resident torch
>= 2.13 via UV_OVERRIDE the way install.sh already does for every unsloth install.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 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-02T07:41:14.472842Z bf1cd08 Manual request
🔒 Security Review ✅ Completed 2026-09-28T08:44:47.063793Z d5e2e36 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: d5e2e36cd4

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 2590d3f327

ℹ️ 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 on lines +501 to +504
include = _OVERRIDE_INCLUDE.match(line)
if include and "://" not in include[2] and not os.path.isabs(include[2]):
line = f"{include[1]}{(base / include[2]).resolve()}{include[3]}"
lines.append(line)

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 Filter torch overrides in recursively included files

When an inherited UV_OVERRIDE contains -r nested.txt or -c nested.txt and that included file constrains torch, torchvision, or torchaudio, rewriting and retaining the include leaves that constraint active beside the newly generated exact pins. For example, a nested torch<2.13 conflicts with the generated torch==2.13.0+cu130, causing uv to report an unsatisfiable resolution; the newly disabled pip fallback then aborts every core update. The fresh case not covered by the earlier relative-path fix is that torch entries are filtered only from the top-level inherited file, not from files reached through these retained includes.

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.

Leaving this: a nested file in a user-supplied UV_OVERRIDE that caps torch below the installed release is a request uv should refuse, and install.sh's own merge filters only the top-level files the same way. Recursing through include chains here would go past what either installer does.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: cdc1933b74

ℹ️ 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.sh
_pypi_unsloth_admits_torch() {
_pua_off=$(printf '%s' "${UV_OFFLINE:-}" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]')
case "$_pua_off" in 1|t|true|y|yes|on) echo "no"; return ;; esac
if [ -n "${UV_EXCLUDE_NEWER:-}${UV_EXCLUDE_NEWER_PACKAGE:-}" ] || _mirror_configured uv; then

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 Disable the route for find-links package sources

When UV_FIND_LINKS (or find-links in uv configuration) supplies a newer/internal unsloth distribution, this condition does not reject the gate because _mirror_configured uv checks only index-related settings. The local uv 0.12.1 help pip install describes --find-links as locations providing candidate distributions in addition to registry indexes, so uv can select a release whose torch cap differs from the public-PyPI JSON checked here. The generated override then forces torch 2.13 anyway, and the first update can run that selected release's older setup and downgrade torch—the exact failure this gate is intended to prevent. Treat find-links as an alternate package source or inspect the release uv will actually select.

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.

Not changing this: an Unsloth Studio home that pulls unsloth itself from a find-links location is not a supported setup, and indexes and mirrors, which is where custom sources actually come from, already disable the route.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 38edbb55c9

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

# Conflicts:
#	studio/install_python_stack.py
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: cc868cb288

ℹ️ 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.sh
Comment on lines +7071 to +7073
if { [ "$_EXISTING_INSTALL" = false ] || [ "${UNSLOTH_TORCH_UPGRADE:-0}" = "1" ]; } \
&& [ "$(_pypi_unsloth_admits_torch "2.13.0")" = "yes" ]; then
_CU130_NEW_INSTALL_ROUTE=true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep the resident torch when the upgrade gate closes

When an existing Linux x86_64/cu130/Python 3.13 home already has torch 2.13 or 2.14, the Settings repair passes UNSLOTH_TORCH_UPGRADE=1. If this PyPI gate returns no because of a transient metadata timeout, offline/cutoff settings, or a configured mirror, _CU130_NEW_INSTALL_ROUTE remains false, but the same upgrade variable makes _previous_torch_pin return empty. The installer consequently falls back to the old <2.12 constraint and downgrades the working installation to torch 2.11, losing its matching kernels. Preserve the resident release unless the newer route has actually passed its gate.

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 bf1cd08: when UNSLOTH_TORCH_UPGRADE=1 is set and the 2.13 route stays closed, a resident release above the default range is now kept instead of reinstalled at 2.11. Covered for an unreachable and a capped PyPI in tests/sh/test_cu130_torch213_route.sh.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: bf1cd08d13

ℹ️ 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 danielhanchen/unsloth-staging-2 that referenced this pull request Oct 2, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 2, 2026
@danielhanchen
danielhanchen merged commit eaef459 into main Oct 2, 2026
@danielhanchen
danielhanchen deleted the studio-torch-213-cu130 branch October 2, 2026 10:40
danielhanchen added a commit to LeoBorcherding/unsloth that referenced this pull request Oct 11, 2026
…isting installs keep their torch (unslothai#13263)

* Studio: torch 2.13 for new Windows x64 cu130 Python 3.13 installs, existing installs keep their torch

Windows port of unslothai#12150. install.ps1 gives a new install torch 2.13 when the
torch index is cu130, the machine and the venv interpreter are both x64, the
venv is CPython 3.13, and the newest unsloth on PyPI admits torch 2.13 (no on
UV_OFFLINE, UV_EXCLUDE_NEWER*, a configured uv index, or any fetch/parse
failure; UNSLOTH_PYPI_JSON_URL points the check elsewhere). That is the only
Windows route the prebuilt-wheels-cu13 kernel wheels can serve.

Existing installs keep their release: on that route the preservation window
widens to <2.15, every earlier layout (occupied venv, legacy .venv with or
without a working interpreter, CWD-relative venv) counts as an existing home,
and UNSLOTH_TORCH_UPGRADE=1 opts in. An upgrade with the route closed keeps
a resident release above the default range instead of moving it down.

A kept torch 2.12+ now pairs with torchaudio 2.11 (the last release) in
install.ps1 and in setup.ps1's kept-release paths. setup.ps1 picks the
triton-windows minor from the installed torch (2.13 -> 3.7, 2.14 -> 3.8,
otherwise <3.7; Windows on ARM unchanged). install_python_stack.py's repair
specs and core-update torch freeze cover native Windows x64 as well as Linux.

* install.ps1: keep an occupied venv's torch from version.py when its interpreter cannot answer

* Windows: the missing-Triton hint names the triton-windows range for the resident torch

* Keep the CWD-relative legacy venv's torch on migration; Windows-on-ARM Triton hint

* Trim comments in the Windows torch 2.13 install route

* Keep the resident torch on every Windows repair path: forced setup reinstall, migrated venv, CWD venv without python.exe; bounded fallback; UV_OFFLINE through Test-UvEnvFlag

* Gate the cu130 torch 2.13 route on --package unsloth and ignore prerelease resident torch

* Skip the core-update torch freeze when the override path cannot be made space-free; match --package unsloth case-insensitively in install.sh

* Never let a setup or update retry move torch to another release; keep the resident torch on unforced setup runs

* Keep the torch freeze file user-private and pin a resident torch only within the index's published range

* Give the Windows torch freeze file a current-user-only ACL; freeze emulated x64 venvs on Windows on ARM too
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants