Repository navigation
Installer: allow torch 2.11.x on the CUDA install path (fresh install + studio) - #6959
Conversation
The CUDA torch repair path (_ensure_cuda_torch) installs torch/torchvision/ torchaudio from an exclusive --index-url, so _CUDA_TORCH_PKG_SPEC decides exactly which torch the Studio venv gets. It was capped at torch<2.11.0, so on a cu128/cu130 host the venv resolved torch 2.10.x even though the CUDA indexes now publish torch 2.11.0. That left the Studio venv a torch minor behind the torch 2.11.0 Docker base image, so the CUDA dedup step would relink base libs under a mismatched torch. Raise the upper bound to <2.12.0 (torchvision <0.27.0, torchaudio <2.12.0) so the CUDA install path lands on torch 2.11.x, matching the rocm7.2 spec and the base image. The torchao selector already maps torch 2.11 -> torchao 0.17.0, and _ensure_flash_attn degrades gracefully when no prebuilt wheel matches (Blackwell skips it outright; non-Blackwell prints a warning and continues), so no other pin needs to move. Add test_cuda_torch_spec.py to lock the bound (torch 2.11.x in, 2.12.x out) and assert the CUDA and rocm7.2 upper bounds stay in lockstep.
There was a problem hiding this comment.
Code Review
This pull request updates the CUDA PyTorch package specifications in install_python_stack.py to allow the PyTorch 2.11.x family, aligning the upper bounds with the ROCm 7.2 specifications and the PyTorch 2.11.0 base image. It also adds a new test suite in test_cuda_torch_spec.py to verify these version bounds. The reviewer suggested using strict=True in the zip function within the test to ensure that any length mismatch between the CUDA and ROCm package specifications is caught.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| for cuda_pkg, rocm_pkg in zip(mod._CUDA_TORCH_PKG_SPEC, rocm72): | ||
| assert _upper(cuda_pkg) == _upper( | ||
| rocm_pkg | ||
| ), f"CUDA {cuda_pkg!r} upper bound must match rocm7.2 {rocm_pkg!r}" |
There was a problem hiding this comment.
To prevent the test from silently passing if _CUDA_TORCH_PKG_SPEC and rocm72 ever differ in length in the future, use strict=True in zip. This ensures any mismatch in the number of packages is caught immediately.
| for cuda_pkg, rocm_pkg in zip(mod._CUDA_TORCH_PKG_SPEC, rocm72): | |
| assert _upper(cuda_pkg) == _upper( | |
| rocm_pkg | |
| ), f"CUDA {cuda_pkg!r} upper bound must match rocm7.2 {rocm_pkg!r}" | |
| for cuda_pkg, rocm_pkg in zip(mod._CUDA_TORCH_PKG_SPEC, rocm72, strict=True): | |
| assert _upper(cuda_pkg) == _upper(rocm_pkg), ( | |
| f"CUDA {cuda_pkg!r} upper bound must match rocm7.2 {rocm_pkg!r}" | |
| ) |
There was a problem hiding this comment.
Applied in f08ef5e, thanks. strict=True makes a future length mismatch between the CUDA and rocm7.2 specs fail loudly instead of silently truncating via zip.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f08ef5e730
ℹ️ 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".
| "torch>=2.4,<2.11.0", | ||
| "torchvision>=0.19,<0.26.0", | ||
| "torchaudio>=2.4,<2.11.0", | ||
| "torch>=2.4,<2.12.0", |
There was a problem hiding this comment.
Update the fresh CUDA install constraint as well
For a fresh Linux/WSL CUDA install this widened spec is never consulted: install.sh still defaults TORCH_CONSTRAINT to torch>=2.4,<2.11.0, only relaxes it for */rocm7.2, then installs CUDA PyTorch with that constraint; the subsequent install_python_stack.py pass inherits UNSLOTH_TORCH_BACKEND=cuda and _ensure_cuda_torch returns for a healthy CUDA torch. So cu128/cu130 fresh installs still resolve 2.10.x even when the CUDA index has 2.11.x, leaving the base-image mismatch this change is meant to fix in the common install path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9f4123e. Correct: _CUDA_TORCH_PKG_SPEC only feeds _ensure_cuda_torch (the ROCm-poisoning repair path), so a fresh CUDA install kept torch>=2.4,<2.11.0 from install.sh and resolved 2.10.x on cu12x/cu13x. Extended the case "$TORCH_INDEX_URL" block with a /cu[0-9] branch -> torch>=2.4,<2.12.0 (>=2.4 floor kept so older indexes like cu118 still resolve; /cpu and older ROCm stay <2.11.0). Added behavioral tests for cu118/124/126/128/130, rocm7.2, and /cpu.
…l matches the base Raising _CUDA_TORCH_PKG_SPEC alone was not enough: that spec only feeds _ensure_cuda_torch(), the ROCm-poisoning repair path that early-returns on a normal NVIDIA host. A fresh CUDA install (including the studio Docker build, which runs `bash install.sh --local`) takes its torch from install.sh's TORCH_CONSTRAINT, which was still capped at torch>=2.4,<2.11.0, so cu12x/cu13x resolved torch 2.10.x and the venv landed a minor behind the torch 2.11.0 base image. Extend the existing `case "$TORCH_INDEX_URL"` block (which already relaxes rocm7.2) with a `*/cu[0-9]*` branch that widens the ceiling to <2.12.0, keeping the >=2.4 floor so an older CUDA index (e.g. cu118) that tops out below 2.11 still resolves. The CPU wheel and older ROCm tags stay on <2.11.0 (the glob does not match /cpu). torchvision/torchaudio are bare on this install line and resolve their compatible companions via wheel metadata, matching the rocm7.2 pattern. Add behavioral tests (Python + shell) exercising the case block: cu118/124/126/ 128/130 widen to <2.12.0, rocm7.2 stays 2.11.x, and /cpu plus older ROCm keep the default <2.11.0.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9f4123e0d1
ℹ️ 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".
| case "$TORCH_INDEX_URL" in | ||
| */rocm7.2) TORCH_CONSTRAINT="torch>=2.11.0,<2.12.0" ;; | ||
| */rocm7.2) TORCH_CONSTRAINT="torch>=2.11.0,<2.12.0" ;; | ||
| */cu[0-9]*) TORCH_CONSTRAINT="torch>=2.4,<2.12.0" ;; |
There was a problem hiding this comment.
Match CUDA constraint on the final index leaf
When UNSLOTH_PYTORCH_MIRROR includes a path segment like /cu128 but get_torch_index_url appends a non-CUDA leaf such as /cpu or /rocm7.1, this pattern still matches because the trailing * consumes the rest of the URL. That widens TORCH_CONSTRAINT even though the _torch_index_leaf classification just above would identify the install as non-CUDA, so CPU/older-ROCm mirrors can unexpectedly resolve torch 2.11 despite this block's comment that those paths stay <2.11.0; match against _torch_index_leaf or otherwise anchor the final segment instead.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a5b6f70. Correct: /cu[0-9] matched a cu segment anywhere in the URL, so a mirror base containing e.g. cu128 with a /cpu or /rocm7.1 leaf would still widen. Now keyed off _torch_index_leaf (the final segment the backend classification just above already computes), so only a real cu*/rocm7.2 leaf is affected. Verified .../cu128/cpu and .../cu128/whl/rocm7.1 keep <2.11.0; added regression tests.
|
@codex review |
…ull URL The `*/cu[0-9]*` glob matched a `cu<digit>` segment anywhere in TORCH_INDEX_URL, so a custom UNSLOTH_PYTORCH_MIRROR whose base path contains e.g. cu128 but whose final leaf is cpu or an older ROCm tag would still widen TORCH_CONSTRAINT to <2.12.0, contradicting the block's own comment and letting a CPU / older-ROCm mirror resolve torch 2.11.x. Match on _torch_index_leaf (the final path segment the backend classification just above already computes) so only a real cu*/ rocm7.2 leaf is affected; cpu and older ROCm keep the default <2.11.0. Update the Python + shell tests to mirror the leaf-anchored case and add regression cases for a mirror base that contains cu128 but resolves to a cpu / rocm7.1 leaf.
|
@codex review |
|
@codex review |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs 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". |
# Conflicts: # studio/install_python_stack.py
Released unsloth wheels can pin an older torch than Step 1 installed (unsloth 2026.7.2 declares torch<2.11.0), so the with-deps resolve from PyPI silently downgrades the pinned +cuXXX torch trio to PyPI's default wheel. The flavor guard cannot catch every such swap: PyPI's torch 2.10 default is itself cu128-flavored, so the cuXXX tag comparison still matches while the version silently drops. Freeze the just-installed trio with uv --overrides (overrides replace dependency requirements during resolution), keeping torch 2.11.0+cuXXX in place while unsloth's other dependencies resolve normally. Verified on the cu128 path: without the override torch drops 2.11.0+cu128 -> 2.10.0; with it the trio survives and unsloth 2026.7.2 + unsloth-zoo install cleanly.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0755bec1f5
ℹ️ 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".
| "unsloth-zoo @ git+https://github.com/unslothai/unsloth-zoo" | ||
| else | ||
| run_install_cmd_retry "install unsloth" uv pip install --python "$_VENV_PY" \ | ||
| ${_UNSLOTH_TORCH_OVERRIDES:+--overrides "$_UNSLOTH_TORCH_OVERRIDES"} \ |
There was a problem hiding this comment.
Preserve existing UV_OVERRIDE files
When _UNSLOTH_TORCH_OVERRIDES is set, this command-line --overrides value replaces rather than merges any UV_OVERRIDE already exported for the process (the uv help shows --overrides is the CLI form of UV_OVERRIDE, and verified behavior is CLI-only). On macOS arm64, lines 1457-1480 export UV_OVERRIDE=.../overrides-darwin-arm64.txt, and this same generic install also adds mlx-lm!=0.31.3; masking the Darwin override means the resolver no longer applies the repo’s transformers/anyio/mlx-lm overrides for that run. Please merge the torch pins with the existing override file(s), or pass both override files, instead of replacing the environment override.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a545eab. Correct: --overrides is the CLI form of UV_OVERRIDE, so it replaced the darwin-arm64 overrides file that the macOS path exports before reaching this same generic install. The trio pins and any UV_OVERRIDE files are now concatenated into the one temp file, so both keep applying; test extended.
The CLI --overrides flag is the command-line form of UV_OVERRIDE, so passing it replaced any overrides file already exported for the process; macOS arm64 exports UV_OVERRIDE=overrides-darwin-arm64.txt for the same generic install path and would have lost those pins. Concatenate any UV_OVERRIDE files into the temp trio file so both keep applying.
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
Four follow-ups to the Step-2 --overrides guard, all empirically verified: 1. The migrated-environment with-deps unsloth install resolved unsloth>=2026.7.2 (which pins torch<2.11.0) without the overrides file, so a migrated CUDA venv on torch 2.11 was silently downgraded -- the exact bug this branch fixes on the fresh path. The overrides build is now a function (_build_unsloth_torch_overrides, reading the trio installed at call time) invoked by both with-deps paths; the migrated no-torch path installs --no-deps and stays unguarded. 2. The overrides temp file is now cleaned by the EXIT trap (same pattern as _UV_OVERRIDE_TMPDIR, pre-initialized empty so an inherited value can never reach the trap's rm); previously any Step-2 failure leaked it. 3. Folding UV_OVERRIDE files used cat, which joins the last requirement of a file lacking a trailing newline onto the next file's first requirement (reproduced: idna==3.10certifi==2025.1.31 makes uv fail parsing). 4. Inherited torch/torchvision/torchaudio override lines are now filtered out when folding: uv intersects duplicate overrides rather than last-wins (verified on uv 0.10.12: direct conflict is unsatisfiable, transitive conflict silently backtracks), so a conflicting inherited trio pin would break the resolve the generated exact pins protect. Both 3 and 4 are handled by a single newline-terminating awk filter that preserves non-trio overrides (torchmetrics, torchao, ...). test_unsloth_torch_override.sh extended: migrated-path coverage, trap assertion, and a functional fold test (14 checks).
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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 |
1 similar comment
|
@codex review |
|
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". |
# Conflicts: # install.sh
Re-running `curl -fsSL https://unsloth.ai/install.sh | sh` over an existing install rebuilds the venv for clean state, which silently moved users to the newest torch in range (2.10 -> 2.11 once the constraint widened). A torch the user already validated must survive an unsloth update. Before the old venv is moved aside for rollback, its torch version is probed (last stdout line only, so sitecustomize noise cannot corrupt it). After the index leaf is chosen, _previous_torch_pin turns that version into a torch==X.Y.Z pin, but only when it cannot do harm: - cu*/cpu leaves only; rocm leaves keep their floors (rocm7.2 must land 2.11 for the Strix _grouped_mm fix) and the Radeon wheel-matching path is untouched. - The wheel's flavor tag must match the freshly chosen leaf, so a flavor change (cpu -> cuda, cu126 -> cu130) still installs the correct new build. - The base must look like a release, so probe noise never becomes a pin. - UNSLOTH_TORCH_UPGRADE=1 opts out and restores the old always-newest behavior; the substep line advertises it. The supported range is kept in _PREV_FALLBACK_CONSTRAINT: if the exact release is not resolvable from the chosen index (custom mirrors prune old wheels), the install warns and falls back to the newest supported release instead of failing the whole run. The later flavor-mismatch repair reuses TORCH_CONSTRAINT, so a mid-install clobber is repaired back to the kept release rather than the newest one. Verified end to end: a venv seeded with torch 2.10.0+cu130 re-run through the full installer finishes with torch 2.10.0+cu130 (previously 2.11.0+cu130). Tests: tests/sh/test_previous_torch_pin.sh covers keep/flavor-change/rocm/ noise/opt-out plus wiring (probe ordering before venv replacement, fallback present, SKIP_TORCH gate).
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 26da79f390
ℹ️ 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 [ "$(_torch_flavor_tag "$_ptp_ver")" = "$_ptp_leaf" ]; then | ||
| echo "torch==$_ptp_base" |
There was a problem hiding this comment.
Constrain kept torch pins to the supported window
When an existing cu*/cpu venv has a matching-flavor torch outside the installer's active range (for example 2.3.x from an older/manual install, or 2.12.x after a manual upgrade), this branch emits torch==... solely on flavor match. That replaces the bounds computed just above (torch>=2.4,<2.12.0 for CUDA and the macOS floor) and the subsequent install will keep an unsupported torch if the wheel is present, so a rerun can leave Studio on a torch version the installer otherwise deliberately excludes. Please check _ptp_base against the current constraint before returning the exact pin.
Useful? React with 👍 / 👎.
| run_install_cmd_retry "install unsloth" uv pip install --python "$_VENV_PY" \ | ||
| ${_UNSLOTH_TORCH_OVERRIDES:+--overrides "$_UNSLOTH_TORCH_OVERRIDES"} \ |
There was a problem hiding this comment.
Keep the PyTorch index when applying torch overrides
On fresh CUDA/ROCm installs, _build_unsloth_torch_overrides writes exact installed versions such as torch==2.11.0+cu128 from the PyTorch wheel index, but this Step-2 uv pip install applies that file while resolving against the normal index only. I checked uv pip install --help: --overrides "Override versions using the given requirements files" and --default-index is the package-index URL; without passing the PyTorch index or --torch-backend, uv tries to resolve those local-version pins from PyPI and the install fails before Unsloth is installed.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Checked empirically on this exact path. Step 1 installs the trio from the PyTorch index, then _build_unsloth_torch_overrides pins the versions that are already installed in the venv, so uv satisfies the override from site-packages and never needs a PyPI candidate for torch. Reproduced both ways: (1) full installer run on a cu130 host with the overrides file containing torch==2.10.0+cu130 resolved Step 2 against the default index and finished with torch unchanged, exit 0; (2) minimal case, venv with torch==2.10.0+cu130 installed, then uv pip install --overrides <file with torch==2.10.0+cu130> torchmetrics against PyPI only: resolved in 35ms, installed torchmetrics, torch stayed 2.10.0+cu130. The failure mode you describe would need an override pin that is not already installed, which this file cannot produce by construction.
Review caught that _previous_torch_pin pinned the previous venv's torch on
flavor match alone, so a release outside the installer's active range (a
2.3.x manual install below the >=2.4 floor, or a 2.12.x manual upgrade above
the ceiling) replaced the bounds computed just above it and a rerun kept a
torch the installer otherwise deliberately excludes.
New _torch_release_in_window checks the probed base against the active
TORCH_CONSTRAINT ("torch>=A.B[,<C.D.F]") at major.minor granularity, which
is exact for the windows this script uses (ceilings are always X.Y.0; a
non-.0 ceiling would only make it conservative). Anything unparseable
answers no, so probe noise or a malformed window fails toward the supported
range instead of becoming a pin. _previous_torch_pin takes the active
constraint as a third argument and refuses out-of-window releases; the
in-window keep behavior is unchanged.
Tests: out-of-window rows (2.3.x floor, 2.12.x ceiling, boundary keeps, cpu
and macOS windows, malformed/empty windows) plus direct
_torch_release_in_window coverage.
|
@codex review |
|
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". |
… + studio) (unslothai#6959) * Studio: allow torch 2.11.x on the CUDA install path The CUDA torch repair path (_ensure_cuda_torch) installs torch/torchvision/ torchaudio from an exclusive --index-url, so _CUDA_TORCH_PKG_SPEC decides exactly which torch the Studio venv gets. It was capped at torch<2.11.0, so on a cu128/cu130 host the venv resolved torch 2.10.x even though the CUDA indexes now publish torch 2.11.0. That left the Studio venv a torch minor behind the torch 2.11.0 Docker base image, so the CUDA dedup step would relink base libs under a mismatched torch. Raise the upper bound to <2.12.0 (torchvision <0.27.0, torchaudio <2.12.0) so the CUDA install path lands on torch 2.11.x, matching the rocm7.2 spec and the base image. The torchao selector already maps torch 2.11 -> torchao 0.17.0, and _ensure_flash_attn degrades gracefully when no prebuilt wheel matches (Blackwell skips it outright; non-Blackwell prints a warning and continues), so no other pin needs to move. Add test_cuda_torch_spec.py to lock the bound (torch 2.11.x in, 2.12.x out) and assert the CUDA and rocm7.2 upper bounds stay in lockstep. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * test: use zip(strict=True) so a spec length mismatch fails loudly * install.sh: widen the CUDA torch ceiling to <2.12.0 so a fresh install matches the base Raising _CUDA_TORCH_PKG_SPEC alone was not enough: that spec only feeds _ensure_cuda_torch(), the ROCm-poisoning repair path that early-returns on a normal NVIDIA host. A fresh CUDA install (including the studio Docker build, which runs `bash install.sh --local`) takes its torch from install.sh's TORCH_CONSTRAINT, which was still capped at torch>=2.4,<2.11.0, so cu12x/cu13x resolved torch 2.10.x and the venv landed a minor behind the torch 2.11.0 base image. Extend the existing `case "$TORCH_INDEX_URL"` block (which already relaxes rocm7.2) with a `*/cu[0-9]*` branch that widens the ceiling to <2.12.0, keeping the >=2.4 floor so an older CUDA index (e.g. cu118) that tops out below 2.11 still resolves. The CPU wheel and older ROCm tags stay on <2.11.0 (the glob does not match /cpu). torchvision/torchaudio are bare on this install line and resolve their compatible companions via wheel metadata, matching the rocm7.2 pattern. Add behavioral tests (Python + shell) exercising the case block: cu118/124/126/ 128/130 widen to <2.12.0, rocm7.2 stays 2.11.x, and /cpu plus older ROCm keep the default <2.11.0. * install.sh: key the CUDA torch widening off the index leaf, not the full URL The `*/cu[0-9]*` glob matched a `cu<digit>` segment anywhere in TORCH_INDEX_URL, so a custom UNSLOTH_PYTORCH_MIRROR whose base path contains e.g. cu128 but whose final leaf is cpu or an older ROCm tag would still widen TORCH_CONSTRAINT to <2.12.0, contradicting the block's own comment and letting a CPU / older-ROCm mirror resolve torch 2.11.x. Match on _torch_index_leaf (the final path segment the backend classification just above already computes) so only a real cu*/ rocm7.2 leaf is affected; cpu and older ROCm keep the default <2.11.0. Update the Python + shell tests to mirror the leaf-anchored case and add regression cases for a mirror base that contains cu128 but resolves to a cpu / rocm7.1 leaf. * install: freeze the torch trio during the with-deps unsloth installs Released unsloth wheels can pin an older torch than Step 1 installed (unsloth 2026.7.2 declares torch<2.11.0), so the with-deps resolve from PyPI silently downgrades the pinned +cuXXX torch trio to PyPI's default wheel. The flavor guard cannot catch every such swap: PyPI's torch 2.10 default is itself cu128-flavored, so the cuXXX tag comparison still matches while the version silently drops. Freeze the just-installed trio with uv --overrides (overrides replace dependency requirements during resolution), keeping torch 2.11.0+cuXXX in place while unsloth's other dependencies resolve normally. Verified on the cu128 path: without the override torch drops 2.11.0+cu128 -> 2.10.0; with it the trio survives and unsloth 2026.7.2 + unsloth-zoo install cleanly. * install: fold UV_OVERRIDE env files into the torch-trio overrides file The CLI --overrides flag is the command-line form of UV_OVERRIDE, so passing it replaced any overrides file already exported for the process; macOS arm64 exports UV_OVERRIDE=overrides-darwin-arm64.txt for the same generic install path and would have lost those pins. Concatenate any UV_OVERRIDE files into the temp trio file so both keep applying. * install: extend the torch-trio overrides guard to migrated installs Four follow-ups to the Step-2 --overrides guard, all empirically verified: 1. The migrated-environment with-deps unsloth install resolved unsloth>=2026.7.2 (which pins torch<2.11.0) without the overrides file, so a migrated CUDA venv on torch 2.11 was silently downgraded -- the exact bug this branch fixes on the fresh path. The overrides build is now a function (_build_unsloth_torch_overrides, reading the trio installed at call time) invoked by both with-deps paths; the migrated no-torch path installs --no-deps and stays unguarded. 2. The overrides temp file is now cleaned by the EXIT trap (same pattern as _UV_OVERRIDE_TMPDIR, pre-initialized empty so an inherited value can never reach the trap's rm); previously any Step-2 failure leaked it. 3. Folding UV_OVERRIDE files used cat, which joins the last requirement of a file lacking a trailing newline onto the next file's first requirement (reproduced: idna==3.10certifi==2025.1.31 makes uv fail parsing). 4. Inherited torch/torchvision/torchaudio override lines are now filtered out when folding: uv intersects duplicate overrides rather than last-wins (verified on uv 0.10.12: direct conflict is unsatisfiable, transitive conflict silently backtracks), so a conflicting inherited trio pin would break the resolve the generated exact pins protect. Both 3 and 4 are handled by a single newline-terminating awk filter that preserves non-trio overrides (torchmetrics, torchao, ...). test_unsloth_torch_override.sh extended: migrated-path coverage, trap assertion, and a functional fold test (14 checks). * installer: tighten comments * install: keep the existing torch release when re-running the installer Re-running `curl -fsSL https://unsloth.ai/install.sh | sh` over an existing install rebuilds the venv for clean state, which silently moved users to the newest torch in range (2.10 -> 2.11 once the constraint widened). A torch the user already validated must survive an unsloth update. Before the old venv is moved aside for rollback, its torch version is probed (last stdout line only, so sitecustomize noise cannot corrupt it). After the index leaf is chosen, _previous_torch_pin turns that version into a torch==X.Y.Z pin, but only when it cannot do harm: - cu*/cpu leaves only; rocm leaves keep their floors (rocm7.2 must land 2.11 for the Strix _grouped_mm fix) and the Radeon wheel-matching path is untouched. - The wheel's flavor tag must match the freshly chosen leaf, so a flavor change (cpu -> cuda, cu126 -> cu130) still installs the correct new build. - The base must look like a release, so probe noise never becomes a pin. - UNSLOTH_TORCH_UPGRADE=1 opts out and restores the old always-newest behavior; the substep line advertises it. The supported range is kept in _PREV_FALLBACK_CONSTRAINT: if the exact release is not resolvable from the chosen index (custom mirrors prune old wheels), the install warns and falls back to the newest supported release instead of failing the whole run. The later flavor-mismatch repair reuses TORCH_CONSTRAINT, so a mid-install clobber is repaired back to the kept release rather than the newest one. Verified end to end: a venv seeded with torch 2.10.0+cu130 re-run through the full installer finishes with torch 2.10.0+cu130 (previously 2.11.0+cu130). Tests: tests/sh/test_previous_torch_pin.sh covers keep/flavor-change/rocm/ noise/opt-out plus wiring (probe ordering before venv replacement, fallback present, SKIP_TORCH gate). * install: constrain kept torch pins to the supported window Review caught that _previous_torch_pin pinned the previous venv's torch on flavor match alone, so a release outside the installer's active range (a 2.3.x manual install below the >=2.4 floor, or a 2.12.x manual upgrade above the ceiling) replaced the bounds computed just above it and a rerun kept a torch the installer otherwise deliberately excludes. New _torch_release_in_window checks the probed base against the active TORCH_CONSTRAINT ("torch>=A.B[,<C.D.F]") at major.minor granularity, which is exact for the windows this script uses (ceilings are always X.Y.0; a non-.0 ceiling would only make it conservative). Anything unparseable answers no, so probe noise or a malformed window fails toward the supported range instead of becoming a pin. _previous_torch_pin takes the active constraint as a third argument and refuses out-of-window releases; the in-window keep behavior is unchanged. Tests: out-of-window rows (2.3.x floor, 2.12.x ceiling, boundary keeps, cpu and macOS windows, malformed/empty windows) plus direct _torch_release_in_window coverage. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Summary
The Studio installer's CUDA torch repair path (
_ensure_cuda_torch) installstorch/torchvision/torchaudiofrom an exclusive--index-url(no PyPI fallback), so_CUDA_TORCH_PKG_SPECdecides exactly which torch the Studio venv ends up on. It was capped attorch<2.11.0, so on a cu128/cu130 host the venv resolved torch 2.10.x even though the CUDA indexes now publish torch 2.11.0.That leaves the Studio venv one torch minor behind the torch 2.11.0 base image: the CUDA dedup step then relinks base libraries under a mismatched torch. This raises the upper bound so the CUDA path lands on torch 2.11.x, matching both the
rocm7.2spec and the base image.What changes
_CUDA_TORCH_PKG_SPECinstudio/install_python_stack.py:The companions keep the same one-major window (
<0.27.0/<2.12.0) so the exclusive index cannot pull a torch-2.12-era torchvision that would ABI-mismatch at runtime. This mirrors the existingrocm7.2spec (torch>=2.11.0,<2.12.0).Why nothing else needs to move
_select_torchao_specalready maps torch 2.11.x totorchao==0.17.0(with tests), so it tracks the newer torch automatically._ensure_flash_attndegrades gracefully with no torch 2.11 wheel. Blackwell (sm_100+) skips flash-attn outright; a non-Blackwell host with no matching prebuilt wheel prints "No compatible flash-attn prebuilt wheel found" and continues. No hard failure.>=2.4,<2.12.0, so they are left untouched; only fresh CUDA installs move up.Tests
Adds
studio/backend/tests/test_cuda_torch_spec.py:rocm7.2upper bounds stay in lockstep (so they are bumped together at 2.12.x).Update: also widen install.sh's fresh CUDA cap
Review surfaced that
_CUDA_TORCH_PKG_SPEConly feeds_ensure_cuda_torch(), the ROCm-poisoning repair path (it early-returns on a normal NVIDIA host). A fresh CUDA install, including the Studio Docker build'sbash install.sh --local, takes its torch frominstall.sh'sTORCH_CONSTRAINT, which was stilltorch>=2.4,<2.11.0, so cu12x/cu13x resolved torch 2.10.x.Extended the existing
case "$TORCH_INDEX_URL"block (which already relaxesrocm7.2) with a*/cu[0-9]*branch widening the ceiling to<2.12.0, keeping the>=2.4floor so an older CUDA index (e.g. cu118) still resolves. The CPU wheel and older ROCm tags stay on<2.11.0(the glob does not match/cpu). Added Python + shell behavioral tests for the case block (cu118/124/126/128/130 widen; rocm7.2 stays 2.11.x;/cpuand older ROCm keep the default).Update: keep the existing torch release when the installer is re-run
Re-running
curl -fsSL https://unsloth.ai/install.sh | shover an existing install rebuilds the Studio venv for clean state, which meant the widened cap silently moved users from a torch they had already validated (2.10.x) to the newest in range (2.11.x). The installer now probes the old venv's torch version before the venv is replaced and pinstorch==X.Y.Zfor the fresh install when it is safe to do so:cu*/cpuindex leaves whose flavor tag matches the previous wheel. A flavor change (cpu to cuda, cu126 to cu130) still installs the correct new build, and ROCm leaves keep their floors (rocm7.2must land torch 2.11 for the Strix_grouped_mmfix).UNSLOTH_TORCH_UPGRADE=1opts out and restores the previous always-newest behavior; the install output advertises this next to the "keeping it" line.Verified end to end: a venv seeded with torch 2.10.0+cu130 and re-run through the full installer finishes on torch 2.10.0+cu130 (previously it finished on 2.11.0+cu130). Unit coverage in
tests/sh/test_previous_torch_pin.sh.Also merged current
maininto the branch (conflict-free apart from the unsloth version floor bumps, resolved keeping both sides' intent).