Repository navigation
Installer: preserve the previous torch release across every flavor and vendor on re-runs - #7250
Conversation
…vendor A re-run of curl | sh over an existing install was supposed to keep the user's validated torch release, but the pin required the old build's local flavor tag to match the freshly chosen index leaf. That gate was wrong in practice: a PyPI-sourced torch reports a BARE version (on Linux the PyPI wheel IS a CUDA build), which classified as cpu and never matched a cu leaf, so a healthy 2.10 on a cu130 host was silently moved to 2.11 (reproduced end to end); the same happened for any flavor drift such as cu128 to cu130 after a driver upgrade, and AMD ROCm leaves were excluded from preservation entirely. The rule is now release-based and flavor-agnostic: the probed previous release is pinned whenever it sits inside the final constraint window, and the pin installs from the freshly chosen index, so the flavor always follows the machine (NVIDIA cu*, AMD rocm/gfx, Intel/CPU, mac) while the release follows the user. The pin is evaluated AFTER every index and constraint decision including the Strix reroute, so raised floors (rocm7.2 / Strix gfx need torch 2.11 for the _grouped_mm fix) correctly reject an older release and win. UNSLOTH_TORCH_UPGRADE=1 still opts out, out-of-window releases are never kept, and probe noise never becomes a pin. The kept-release install with its range fallback (for indexes that do not carry the exact release) is factored into _install_torch_default_index and used by every --default-index torch path: the default NVIDIA/CPU/mac path and all three ROCm-index fallbacks, which previously bypassed the fallback. The Radeon-repo direct-wheel path keeps its curated per-arch wheel set (those wheels are already exact-pinned per rocm release). Platform coverage: install.sh serves Linux, WSL (including the WoA fallback), and macOS for all vendors; native Windows install.ps1 still caps at <2.11.0 everywhere, so the silent 2.10-to-2.11 move cannot occur there (2.11 alignment is a separate follow-up). Verified: 35-check unit suite rewritten to the new spec (any-flavor keep, floor rejection, noise, window edges, opt-out, wiring including pin-after-reroute and helper coverage); end-to-end matrix against sandboxed UNSLOTH_STUDIO_HOME installs on a cu130 host covering PyPI bare, cu128 drift, cu130 same-flavor, out-of-window 2.3, the upgrade opt-out, the hidden-GPU cpu leaf, and a fresh-install control.
|
@codex review |
There was a problem hiding this comment.
Code Review
This pull request refactors the PyTorch version preservation logic in install.sh to keep the previous release regardless of its flavor tag (such as CPU, CUDA, or ROCm), allowing the newly selected index to determine the correct flavor. It introduces a helper function _install_torch_default_index to handle installation and fallback paths consistently, and moves the pin evaluation to occur after all constraint decisions. Unit tests in tests/sh/test_previous_torch_pin.sh have been updated accordingly. There are no review comments, so no feedback is provided.
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.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 895379ef93
ℹ️ 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".
| substep "[WARN] Radeon repo lacks a compatible wheel set for this Python; falling back to ROCm index ($TORCH_INDEX_URL)" "$C_WARN" | ||
| run_install_cmd_retry "install PyTorch" uv pip install --python "$_VENV_PY" \ | ||
| "$TORCH_CONSTRAINT" torchvision torchaudio \ | ||
| --default-index "$TORCH_INDEX_URL" | ||
| _install_torch_default_index |
There was a problem hiding this comment.
Preserve the pin when Radeon wheel selection succeeds
On a re-run for a Radeon ROCm host, _previous_torch_pin now sets _PREV_TORCH_PIN, but this helper is only used when the Radeon listing fails. When the listing succeeds, the adjacent else installs the newest compatible wheel trio selected by _pick_radeon_wheel, without consulting the pin. Thus an existing in-window Radeon install such as torch 2.9 is still upgraded whenever the repo also offers 2.10, contrary to the new cross-vendor release-preservation behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, the Radeon direct-wheel path bypassed the pin entirely. Fixed in 7f76c11: when _PREV_TORCH_PIN is set and the listing still offers a torch wheel for the kept release's minor, the trio search now starts at that minor instead of the newest common one, so an in-window 2.9 install stays on the 2.9 / 0.24 / 2.9 trio even when the repo also carries 2.10. Radeon wheels are patch-curated per rocm release, so the minor is the unit of preservation on this path; raised rocm7.2 / Strix floors still win because the pin is window-checked against the final constraint upstream, and gaps keep the existing downward search plus ROCm-index fallback. Verified with a simulated listing carrying both trios and added a structural wiring check to test_previous_torch_pin.sh.
There was a problem hiding this comment.
Correct, and this is fixed at head (7f76c11): the Radeon direct-wheel path now seeds the trio search at the kept minor from _PREV_TORCH_PIN when that release is still listed, so a re-run over an in-window install no longer upgrades. Covered by tests/sh/test_previous_torch_pin.sh (Radeon trio search honors the kept release).
The Radeon repo path installs an explicit wheel trio selected by _pick_radeon_wheel, bypassing --default-index, so the kept-release pin only took effect when the listing failed and the install fell back to the ROCm index. On a re-run over an in-window Radeon install the trio search started at the newest common minor and silently moved the user forward (2.9 to 2.10 whenever the repo offered both). The trio search now starts at the kept release's minor when _PREV_TORCH_PIN is set and the listing still offers a torch wheel for that minor. Radeon wheels are patch-curated per rocm release, so the minor is the unit of preservation there; the raised rocm7.2 / Strix floors still win because the pin is window-checked against the final constraint before this point, and gaps keep the existing downward search / ROCm-index fallback. Verified with a simulated listing carrying both a 2.9 and a 2.10 trio: no pin selects the 2.10 trio, a kept 2.9 release selects the matched 2.9 / 0.24 / 2.9 trio, and an unavailable minor degrades to the newest trio. Added a structural wiring check to test_previous_torch_pin.sh (now 36 checks).
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f76c1155e
ℹ️ 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 [ "$_prev_kept_minor" -lt "$_target_minor" ] && \ | ||
| [ -n "$(_pick_radeon_wheel "torch" "2.${_prev_kept_minor}." 2>/dev/null)" ]; then | ||
| _target_minor=$_prev_kept_minor |
There was a problem hiding this comment.
Preserve the exact Radeon pinned release
On the Radeon direct-wheel path, this only clamps the minor and _pick_radeon_wheel then selects the newest patch, while the downward loop can select an older complete trio. Thus a rerun from 2.10.0 can silently become 2.10.1 when both patches exist, or even 2.9.x when the listing has a 2.10 torch wheel but lacks its matching vision/audio trio. That bypasses the exact _PREV_TORCH_PIN and its range-fallback behavior used by the other vendor paths, defeating the stated release-preservation guarantee for Radeon users.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right, the minor clamp still allowed patch drift and the gap search could settle below the kept minor. Fixed in e555c06: the kept release now gets an exact-first trio attempt before the newest-trio search (kept patch, else the newest patch of the kept minor for listings that pruned it, with the paired vision/audio wheels), and any gap warns and falls back to the unchanged newest-trio search, mirroring _install_torch_default_index. A rerun now installs either the kept release or the same set a fresh install would choose, never something in between. Verified against synthetic listings covering both of your scenarios plus a pruned-patch case; wiring checks added to the unit suite.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd1b3e0193
ℹ️ 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".
| # Install torch from TORCH_INDEX_URL honoring a kept-release pin: with _PREV_TORCH_PIN | ||
| # set, TORCH_CONSTRAINT is the exact previous release; fall back to the supported range | ||
| # if the index lacks it (pruned mirror) rather than failing. Used by every --default-index | ||
| # path (NVIDIA cu*, AMD rocm/gfx fallbacks, cpu/mac) so preservation is uniform. |
There was a problem hiding this comment.
Apply the pin fallback to ROCm repair installs
The new ROCm pinning makes the later fresh-install repair path reachable with TORCH_CONSTRAINT=torch==X.Y.Z, but the repair at install.sh:3139 still invokes uv pip install directly instead of this helper. If the Radeon direct-wheel install succeeded with a newer patch in the kept minor and the subsequent Unsloth resolution replaces it with a non-ROCm wheel, an older pinned patch absent from the generic ROCm index makes that repair fail and abort the rerun rather than falling back to _PREV_FALLBACK_CONSTRAINT. Route that repair through the same fallback logic (or add equivalent handling).
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, a pinned release absent from the generic ROCm index would have aborted the repair. Fixed in e555c06: both ROCm repair sites (migrated and fresh paths) now route through _install_torch_default_index, which accepts pass-through uv args (--force-reinstall) and falls back to _PREV_FALLBACK_CONSTRAINT when the pin does not resolve; the helper also clears the pin once the fallback fires so later paths stay consistent.
|
@codex review |
1 similar comment
|
@codex review |
…repairs The minor-level clamp on the Radeon direct-wheel path still allowed patch drift (a kept 2.10.0 could become 2.10.1 when the listing carried both) and the downward gap search could settle below the kept minor, both breaking the exact preservation guarantee the other vendor paths honor. The kept release now gets an exact-first trio attempt before the newest-trio search: pick the kept patch (else the newest patch of the kept minor, for listings that pruned the exact patch) together with the paired torchvision/torchaudio wheels for that minor. Any gap warns and falls back to the unchanged newest-trio search, mirroring _install_torch_default_index, so a rerun installs either the kept release or the same set a fresh install would choose, never something in between. The two ROCm torch repair sites (torch overwritten by dependency resolution, on the migrated and fresh paths) installed TORCH_CONSTRAINT directly, so a pinned release missing from the generic ROCm index would abort the rerun instead of falling back. Both now route through _install_torch_default_index, which passes extra uv args through (--force-reinstall) and clears the pin once the fallback fires so later paths stay consistent. Verified against synthetic listings: both patches listed keeps exactly 2.10.0; a kept minor missing vision/audio warns and yields the newest complete trio rather than a silent undercut; a pruned patch stays on the kept minor; no pin keeps the existing newest-trio behavior. Unit suite now 39 checks, all passing.
|
@codex review |
A survey of published torch version strings (PyPI bare, +cpu, +cu116 through +cu132, +rocmX.Y and +rocmX.Y.Z, +xpu, nightly .devYYYYMMDD, source a0+git, rc tags) showed one gap: nightly, dev, rc, and source builds passed the loose release-shape check, producing a pin such as torch==2.11.0.dev20250704 that no stable index carries. The range fallback rescued the install, but it printed "keeping it" and then burned a doomed resolve first. The base must now be a plain numeric X.Y[.Z] release, so those builds skip the pin and go straight to the newest supported release. Added unit checks for +xpu and three-component +rocm7.2.1 tags (both already preserved correctly) and for nightly, a0 source, and rc builds (never pinned). Suite now 44 checks, all passing.
…e substitutions Three fixes from a 12-way review pass over the preservation work: The kept-release install left torchvision and torchaudio unconstrained next to the exact torch pin. torchvision exact-pins its torch in wheel metadata so it always paired correctly, but torchaudio no longer does: a kept torch 2.9.0 on cu130 resolved torchaudio 2.11.0 (verified with uv dry-runs). The helper now pairs both companions to the kept minor (torchvision 0.minor+15, torchaudio 2.minor); if the index lacks the paired set the existing range fallback fires. Verified resolving correctly on cu130, cu126, and rocm6.4. The wrong-flavor repair at the end of the install was the one remaining default-index torch install outside the helper. It runs under set -e, so a retained pin absent from the repair index (reachable when the Radeon direct-wheel path installed the kept release and dependency resolution later overwrote it) aborted the installer at the last step instead of falling back. It now routes through the helper with its reinstall flags passed through. The Radeon kept-release path installed a same-series build silently when the listing had pruned the exact patch; it now prints what it is substituting. Unit suite extended with wiring checks for all three (46 checks, all passing).
|
@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". |
…d vendor on re-runs (unslothai#7250) * install: preserve the previous torch release across every flavor and vendor A re-run of curl | sh over an existing install was supposed to keep the user's validated torch release, but the pin required the old build's local flavor tag to match the freshly chosen index leaf. That gate was wrong in practice: a PyPI-sourced torch reports a BARE version (on Linux the PyPI wheel IS a CUDA build), which classified as cpu and never matched a cu leaf, so a healthy 2.10 on a cu130 host was silently moved to 2.11 (reproduced end to end); the same happened for any flavor drift such as cu128 to cu130 after a driver upgrade, and AMD ROCm leaves were excluded from preservation entirely. The rule is now release-based and flavor-agnostic: the probed previous release is pinned whenever it sits inside the final constraint window, and the pin installs from the freshly chosen index, so the flavor always follows the machine (NVIDIA cu*, AMD rocm/gfx, Intel/CPU, mac) while the release follows the user. The pin is evaluated AFTER every index and constraint decision including the Strix reroute, so raised floors (rocm7.2 / Strix gfx need torch 2.11 for the _grouped_mm fix) correctly reject an older release and win. UNSLOTH_TORCH_UPGRADE=1 still opts out, out-of-window releases are never kept, and probe noise never becomes a pin. The kept-release install with its range fallback (for indexes that do not carry the exact release) is factored into _install_torch_default_index and used by every --default-index torch path: the default NVIDIA/CPU/mac path and all three ROCm-index fallbacks, which previously bypassed the fallback. The Radeon-repo direct-wheel path keeps its curated per-arch wheel set (those wheels are already exact-pinned per rocm release). Platform coverage: install.sh serves Linux, WSL (including the WoA fallback), and macOS for all vendors; native Windows install.ps1 still caps at <2.11.0 everywhere, so the silent 2.10-to-2.11 move cannot occur there (2.11 alignment is a separate follow-up). Verified: 35-check unit suite rewritten to the new spec (any-flavor keep, floor rejection, noise, window edges, opt-out, wiring including pin-after-reroute and helper coverage); end-to-end matrix against sandboxed UNSLOTH_STUDIO_HOME installs on a cu130 host covering PyPI bare, cu128 drift, cu130 same-flavor, out-of-window 2.3, the upgrade opt-out, the hidden-GPU cpu leaf, and a fresh-install control. * install: honor the kept torch release on the Radeon direct-wheel path The Radeon repo path installs an explicit wheel trio selected by _pick_radeon_wheel, bypassing --default-index, so the kept-release pin only took effect when the listing failed and the install fell back to the ROCm index. On a re-run over an in-window Radeon install the trio search started at the newest common minor and silently moved the user forward (2.9 to 2.10 whenever the repo offered both). The trio search now starts at the kept release's minor when _PREV_TORCH_PIN is set and the listing still offers a torch wheel for that minor. Radeon wheels are patch-curated per rocm release, so the minor is the unit of preservation there; the raised rocm7.2 / Strix floors still win because the pin is window-checked against the final constraint before this point, and gaps keep the existing downward search / ROCm-index fallback. Verified with a simulated listing carrying both a 2.9 and a 2.10 trio: no pin selects the 2.10 trio, a kept 2.9 release selects the matched 2.9 / 0.24 / 2.9 trio, and an unavailable minor degrades to the newest trio. Added a structural wiring check to test_previous_torch_pin.sh (now 36 checks). * install: tighten comments in the torch preservation paths * install: exact kept release on the Radeon path, pin fallback in ROCm repairs The minor-level clamp on the Radeon direct-wheel path still allowed patch drift (a kept 2.10.0 could become 2.10.1 when the listing carried both) and the downward gap search could settle below the kept minor, both breaking the exact preservation guarantee the other vendor paths honor. The kept release now gets an exact-first trio attempt before the newest-trio search: pick the kept patch (else the newest patch of the kept minor, for listings that pruned the exact patch) together with the paired torchvision/torchaudio wheels for that minor. Any gap warns and falls back to the unchanged newest-trio search, mirroring _install_torch_default_index, so a rerun installs either the kept release or the same set a fresh install would choose, never something in between. The two ROCm torch repair sites (torch overwritten by dependency resolution, on the migrated and fresh paths) installed TORCH_CONSTRAINT directly, so a pinned release missing from the generic ROCm index would abort the rerun instead of falling back. Both now route through _install_torch_default_index, which passes extra uv args through (--force-reinstall) and clears the pin once the fallback fires so later paths stay consistent. Verified against synthetic listings: both patches listed keeps exactly 2.10.0; a kept minor missing vision/audio warns and yields the newest complete trio rather than a silent undercut; a pruned patch stays on the kept minor; no pin keeps the existing newest-trio behavior. Unit suite now 39 checks, all passing. * install: never pin nightly/dev/source torch builds on a rerun A survey of published torch version strings (PyPI bare, +cpu, +cu116 through +cu132, +rocmX.Y and +rocmX.Y.Z, +xpu, nightly .devYYYYMMDD, source a0+git, rc tags) showed one gap: nightly, dev, rc, and source builds passed the loose release-shape check, producing a pin such as torch==2.11.0.dev20250704 that no stable index carries. The range fallback rescued the install, but it printed "keeping it" and then burned a doomed resolve first. The base must now be a plain numeric X.Y[.Z] release, so those builds skip the pin and go straight to the newest supported release. Added unit checks for +xpu and three-component +rocm7.2.1 tags (both already preserved correctly) and for nightly, a0 source, and rc builds (never pinned). Suite now 44 checks, all passing. * install: pair kept-release companions, protect the flavor repair, note substitutions Three fixes from a 12-way review pass over the preservation work: The kept-release install left torchvision and torchaudio unconstrained next to the exact torch pin. torchvision exact-pins its torch in wheel metadata so it always paired correctly, but torchaudio no longer does: a kept torch 2.9.0 on cu130 resolved torchaudio 2.11.0 (verified with uv dry-runs). The helper now pairs both companions to the kept minor (torchvision 0.minor+15, torchaudio 2.minor); if the index lacks the paired set the existing range fallback fires. Verified resolving correctly on cu130, cu126, and rocm6.4. The wrong-flavor repair at the end of the install was the one remaining default-index torch install outside the helper. It runs under set -e, so a retained pin absent from the repair index (reachable when the Radeon direct-wheel path installed the kept release and dependency resolution later overwrote it) aborted the installer at the last step instead of falling back. It now routes through the helper with its reinstall flags passed through. The Radeon kept-release path installed a same-series build silently when the listing had pruned the exact patch; it now prints what it is substituting. Unit suite extended with wiring checks for all three (46 checks, all passing).
What
Makes the re-run torch preservation from #6959 release-based and flavor-agnostic, so a
curl | shover an existing install keeps the user's validated torch release on every vendor and platform combination instead of only when the old build's local version tag happens to match the newly chosen index leaf.The bug (reproduced in production and end to end)
A user re-ran the installer over a Studio install holding torch 2.10 on a cu130 host and got silently moved to 2.11. Root cause: the pin required
_torch_flavor_tag(old) == new leaf. A PyPI-sourced torch reports a bare version with no+cuXXXlocal tag (and on Linux the PyPI wheel IS a CUDA build), which classifies ascpuand can never match acu130leaf. The same gate also discarded the release on any flavor drift (+cu128old,cu130newly detected after a driver upgrade), and AMD ROCm leaves were excluded from preservation entirely.The fix
_previous_torch_pinnow pins the probed previous RELEASE whenever it sits inside the final constraint window, regardless of the old flavor tag. The pin installs from the freshly chosen index, so the flavor always follows the machine (NVIDIA cu*, AMD rocm/gfx, Intel/CPU, mac) while the release follows the user._grouped_mmfix, which puts an old 2.10 out of window there and correctly rejects it._install_torch_default_indexand used by every--default-indextorch path, including the three ROCm-index fallbacks that previously had no fallback. The Radeon-repo direct-wheel path keeps its curated per-arch wheel set, which is already exact-pinned per rocm release.UNSLOTH_TORCH_UPGRADE=1still opts out; out-of-window releases (2.3.x manual installs, 2.12.x manual upgrades) are never kept; probe noise never becomes a pin.Platform coverage
install.shserves Linux, WSL (including the Windows-on-ARM fallback), and macOS for all of NVIDIA / AMD / Intel / CPU (Intel hosts resolve to the cpu leaf; Intel Macs keep their 2.6 floor). Native Windowsinstall.ps1still caps at<2.11.0on every path, so the silent 2.10-to-2.11 move cannot occur there; aligning it to 2.11 with the same preservation is a separate follow-up.Verification
UNSLOTH_STUDIO_HOMEinstalls on a real cu130 host (driver CUDA 13.1), 7/7 pass:2.10.0(PyPI bare)2.10.0+cu1302.10.0+cu1282.10.0+cu1302.10.0+cu1302.10.0+cu1302.3.0+cu1182.11.0+cu1302.10.0+cu130UNSLOTH_TORCH_UPGRADE=12.11.0+cu1302.10.0(PyPI bare)2.10.0+cpu2.11.0+cu130, no pin linetest_torch_constraint.shandtest_get_torch_index_url.shunchanged and passing.