Skip to content

Windows torch release preservation and a torch 2.11 default across installers - #7256

Merged
danielhanchen merged 30 commits into
mainfrom
windows-torch-211
Sep 4, 2026
Merged

danielhanchen merged 30 commits into
mainfrom
windows-torch-211

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Jul 20, 2026 •

Copy link
Copy Markdown
Member

What this does

Follow-up to #6959, #6692 and #7250. Four installers, one theme: torch 2.11 becomes the default supported line, and Windows stops moving an existing torch when you re-run the installer.

1. Torch 2.11 is the default on wheel-backed platforms

install.sh centralizes the range in three variables:

_TORCH_CEILING="2.12.0"
_TORCHVISION_CEILING="0.27.0"
_TORCHAUDIO_CEILING="2.12.0"

The ceilings are exclusive, so the supported line is torch 2.11 / torchvision 0.26 / torchaudio 2.11, and the next bump is three lines. Two blocks that existed only to widen or re-narrow the old <2.11.0 default (the cu* case arm, and the companion narrowing under a pinned torch index with no flavor tag) became dead and are deleted.

install.ps1 and setup.ps1 widen to the same range, but they do not share a ceiling variable: it is roughly ten literal torch>=2.4,<2.12.0 / torchvision>=0.19,<0.27.0 / torchaudio>=2.4,<2.12.0 sites across the fresh install, both flavor repairs, the ROCm and XPU fallbacks, and setup.ps1's pinned non-cu leaf. tests/python/test_cross_platform_parity.py gained a loop that rejects the four old default literals, so a missed site fails rather than drifting.

studio/install_python_stack.py gains a rocm7.1 entry in _ROCM_TORCH_PKG_SPECS at the <2.12.0 window and widens the flavor-repair spec to match. _default, which covers rocm7.0 and earlier, stays at torch>=2.4,<2.11.0.

2. Windows torch release preservation

The Windows installer recreates the venv on every re-run, so irm install.ps1 | iex over an existing install resolved the newest torch instead of keeping the installed release. #7250 fixed this on Linux and macOS; this ports it to install.ps1.

New in install.ps1: Get-InstalledTorchVersionRaw, ConvertTo-TorchNumericRelease, Test-TorchReleaseInWindow, Get-PreviousTorchPin.

  • The probe reads the venv with importlib.metadata.version('torch') rather than import torch, over a process with a 30 second timeout, and runs before the rollback move.
  • ConvertTo-TorchNumericRelease strips only a +local tag and requires a strictly numeric public base, so 2.11.0.dev... and 2.9.0a0+git... return nothing and never pin.
  • Test-TorchReleaseInWindow parses a torch>=X,<Y constraint and fails closed on anything else, including torch==. The window it is given is the route's own: the fresh-install spec normally, Get-XpuTorchSpecs[0] on an XPU index, the ROCm floor on a ROCm index. That is why a raised gfx120X/Strix torch>=2.11.0,<2.12.0 floor correctly refuses to keep an older release.
  • On success it emits torch==<release> with minor-paired torchvision==0.<minor+15>.* and torchaudio==2.<minor>.*.

Wired at the AMD ROCm install, the Intel XPU install, the main CUDA/CPU install, and both flavor repairs. Each site tries the kept release first and falls back to the supported range with a [WARN] when it is not installable from the selected index. The kept release is exported as UNSLOTH_KEPT_TORCH for setup.ps1, whose ROCm, CPU and CUDA arms rebuild the trio from it with the same one-shot fallback, so the later Windows torch installs cannot undo the decision. setup.ps1's ROCm arm carries its own guard as well, refusing a kept release below 2.11 when the ROCm spec has a 2.11 floor. install.ps1 re-probes after setup.ps1 returns and warns on a minor-series mismatch, and clears the variable in Exit-InstallFailure, on every fallback, and in a new top-level finally.

UNSLOTH_TORCH_UPGRADE=1 is the opt-out that moves an existing install to the newest release.

3. A uv overrides file on Windows

New-UnslothTorchOverridesFile is new, and is the Windows twin of install.sh's existing _UNSLOTH_TORCH_OVERRIDES machinery. Before each with-deps unsloth install it freezes the exact installed torch== / torchvision== / torchaudio== versions into a uv --overrides file, folding in and trio-filtering any caller-supplied UV_OVERRIDE file. Without it a released unsloth wheel declaring torch<2.11.0 can silently downgrade the trio the installer just placed. The file is deleted after each install and again in the outer finally.

This applies on every Windows run, not only when a release is being preserved.

install.sh's side of the same feature is hardened: the merged overrides file is now written next to the caller's UV_OVERRIDE file so relative -r nested.txt includes still resolve, under umask 077 plus chmod 600, falling back to mktemp when there is no single unambiguous directory; and the trio filter became case-insensitive. The import torch fallback in the Linux preservation probe is now wrapped in _run_bounded, so a wedged driver cannot stall it.

4. Windows pre-Turing CUDA cap now matches Linux

Get-CudaFamilyCappedForPreTuring in both install.ps1 and setup.ps1 dropped its family split:

-  $legacyFloorSm = if ($Family -eq 'cu128') { 70 } else { 75 }
+  $legacyFloorSm = 75

install.sh's _nvidia_cu126_verdict has always used a flat sm_75 floor. The user-visible effect is that an sm_70 host (V100) on Windows with a cu128 selection is now capped to cu126, where it previously stayed on cu128. tests/studio/test_pre_turing_cap.ps1 was flipped to match.

5. Comment reduction

Comments and blank lines only, across the four installers. Measured at this head against the merge base: 1,090 comment lines removed, 3 blank lines added, 793 lines net.

file comment lines net lines
install.sh 1645 to 1288 -341
install.ps1 1632 to 1426 +22
studio/setup.ps1 1704 to 1312 -342
studio/install_python_stack.py 1244 to 1109 -132

Diffing comment-and-blank-stripped versions across each comment commit gives no code-line changes, apart from three lines where a full-line comment was folded into a trailing comment on an unchanged statement. sh -n install.sh passes.

Four suites had to be re-anchored from comment prose onto code, because the comment pass had broken them: tests/python/test_windows_xformers_installer.py, tests/studio/install/test_pr5940_followups.py, tests/studio/test_frontend_dist_cache.py, tests/sh/test_mac_intel_compat.sh.

Literals that deliberately do not track the ceiling

These are the places where the supported line and the route's real ceiling diverge, and each now carries a comment saying so.

where value why
install.sh gfx906 reroute torch>=2.4,<2.11.0 a rocm7.2 pick raises the floor to 2.11, which the rocm6.3 index (torch 2.9.x and below) cannot satisfy
install.sh three ROCm floors torch>=2.11.0,<2.12.0 rocm7.2 and the per-gfx indexes ship the 2.11 _grouped_mm fix; the floor is raised, not just the ceiling
install.sh xpu arm torch>=2.6,<2.11.0 XPU wheels stop at the 2.10 line
install.ps1 Get-XpuTorchSpecs torch>=2.6,<2.11.0 the ps1 twin of the xpu arm
install_python_stack.py _default torch>=2.4,<2.11.0 rocm7.0 and earlier

The gfx906 reroute and the install.sh xpu arm were already at <2.11.0; what changed is that they now diverge from the default instead of matching it, which is why they are called out.

Preservation is version-agnostic

The mechanism is a numeric release parse plus a window comparison, not a hardcoded version, so when the ceiling later moves to 2.12 an existing 2.11 install stays put. tests/studio/test_previous_torch_pin.ps1 covers two future <2.13.0 ceilings for exactly that reason.

Tests

New:

suite checks
tests/studio/test_previous_torch_pin.ps1 51, from 26 call sites (three are loops): accepted and rejected version forms, window semantics including raised ROCm floors and future ceilings, fail-closed on a malformed constraint, companion pairing, both UNSLOTH_TORCH_UPGRADE polarities, and 8 structural assertions (probe before rollback, importlib.metadata not import torch, per-run state reset for irm | iex, the UNSLOTH_KEPT_TORCH export, outer-finally cleanup)
tests/studio/test_torch_overrides_merge.ps1 12: non-ASCII survives, the file lands beside the caller's override so relative -r resolves, trio pinned first, caller trio lines dropped, no BOM, newline-terminated, nothing written under --no-torch
tests/studio/test_unsloth_torch_override.ps1 22: an AST walk over Invoke-InstallCommandRetry proving --overrides is on both with-deps unsloth installs
tests/sh/test_unsloth_torch_override.sh 19, the last 5 covering the adjacent-directory and case-insensitive-filter hardening

Updated: the constraint suites are rewritten to the ceiling scheme (the two cu*-arm tests are deleted with the arm, and a gfx906 single-occurrence test replaces them); parity, ROCm, CUDA-repair, flavor-invariant and XPU-arm64 suites are retargeted at the new variables and counts.

Run at this head, on Linux with pwsh 7:

  • tests/sh: test_unsloth_torch_override.sh 19/19, test_torch_constraint.sh 49/49, test_previous_torch_pin.sh 50/50, test_mac_intel_compat.sh 56/56. sh -n install.sh clean.
  • All three new ps1 suites pass.
  • pytest over the seven touched Python suites: 1009 passed, 1 skipped, 1 failed. The failure is test_tokenizers_and_torch_constraint.py::TestE2ETokenizersFix::test_negative_control_no_tokenizers, which fails identically on the merge base.

Live index resolution for the 2.11 trio was checked while developing this, but not re-run at this head, so those results are not reproduced here.

danielhanchen and others added 5 commits July 20, 2026 08:05
The Windows installer still capped torch at <2.11.0 everywhere, a
stability pin from before 2.11 support landed. Every other layer already
allows 2.11: install.sh widens cu<digits> leaves to <2.12.0, the Python
repair layer uses the <2.12.0 trio for CUDA and CPU, and setup.ps1's
bare specs on known cu leaves resolve 2.11 today.

The fresh-install and CUDA flavor-repair paths now widen the trio to
torch<2.12 / torchvision<0.27 / torchaudio<2.12 when the index leaf is a
cu<digits> family, and keep the 2.10 line otherwise (custom pins and the
CPU fallback are unchanged, matching install.sh's defaults). Verified by
uv dry-runs against cu126/cu128/cu130 for win_amd64: the trio resolves
paired at 2.11.0 / 0.26.0 / 2.11.0, and the existing triton-windows<3.7
constraint resolves 3.6.0.post26, the torch 2.11 pairing.

Parity test updated to assert the leaf-gated widen.
Collapse the multi-line rationale blocks that accreted across the torch
index, override, redaction and companion-pin work to single-line
constraints, and drop review-history narration. Comments and blank lines
only; the PowerShell files verify code-identical by token-stream
comparison against the previous commit, install.sh passes sh -n, and the
Python file passes the AST comments-only gate.

install.sh -258 lines, install.ps1 -235, studio/setup.ps1 -304,
studio/install_python_stack.py -182. One test touched:
tests/sh/test_mac_intel_compat.sh anchors its awk extraction on a
comment phrase that was shortened; the anchor now matches both wordings.

Full battery: parity/install-stack/pr5940 pytest suites, all sh suites
(host-defaults is the known pre-existing failure), and the four studio
ps1 suites all pass.
The Windows installer recreates the venv on every re-run (the existing
environment is moved aside for rollback and a fresh venv is created), so
irm install.ps1 | iex over an existing install resolved the newest torch
in range instead of keeping the installed release. This ports the
install.sh preservation merged in PR 7250:

- The installed torch version is probed (bounded process, drained
  streams, 30s timeout, last non-empty stdout line) BEFORE the rollback
  move, while the old interpreter still exists.
- Get-PreviousTorchPin mirrors _previous_torch_pin: numeric-strict base
  (nightly/dev/rc builds never pin), UNSLOTH_TORCH_UPGRADE=1 opt-out,
  and a release-in-window check against the route's final constraint,
  so a raised ROCm floor correctly rejects keeping an older release.
  The decision runs after every index and floor decision.
- The kept release installs as an exact pin with minor-paired
  companions (torchvision 0.minor+15, torchaudio 2.minor) at the main
  install, the AMD ROCm install and both flavor repairs; when the pinned
  release is not installable from the selected index the installer warns,
  clears the pin and falls back to the supported range. The CPU fallback
  cannot be reached with a live pin (the ROCm site resolves or clears it
  first) and keeps the plain range install.
- The with-deps unsloth installs now carry a uv overrides file with the
  exact installed trio (twin of _build_unsloth_torch_overrides), so
  dependency resolution cannot move torch after it was deliberately
  selected.
- The kept release is exported as UNSLOTH_KEPT_TORCH for setup.ps1,
  whose ROCm/CPU/CUDA torch installs substitute the kept trio when the
  env var is present (ROCm floors dominate; behavior without the env
  var is unchanged, so direct studio update runs are unaffected). After
  setup returns the installer re-probes and warns loudly if the kept
  release series changed, then clears the env var.

Preservation is version-agnostic (numeric parse + window comparison),
so a future ceiling bump to torch 2.12 keeps 2.11 installs in place.

New suite tests/studio/test_previous_torch_pin.ps1 (AST-extracted
helpers, 50+ checks incl. future-ceiling cases and structural wiring)
passes, along with the flavor/pin-hardening/pin-stale/node ps1 suites,
the parity and install-stack pytest suites, and the sh preservation and
constraint suites.
…latforms

Fresh installs now resolve the torch 2.11 trio (torch 2.11.0,
torchvision 0.26.0, torchaudio 2.11.0) everywhere the wheels exist,
verified by live index resolution for py3.11-3.13: Linux x86_64
(cpu, cu126, cu128, cu130, rocm7.1, rocm7.2), Linux aarch64 (cpu,
cu130), Windows x86_64 (cpu, cu126, cu128, cu130; triton-windows<3.7
resolves 3.6.0.post26, the 2.11 pairing) and macOS arm64. Existing
installs are unaffected: the release preservation on both installers
keeps the installed torch on re-runs (verified end to end against the
live cpu index: a seeded 2.10.0 venv stays 2.10.0 with paired 0.25/2.10
companions while a fresh venv resolves the 2.11 trio).

- install.sh: the supported range is centralized in _TORCH_CEILING /
  _TORCHVISION_CEILING / _TORCHAUDIO_CEILING and composed into the
  default constraints, so the next bump (torch 2.12) is a three-line
  change. The now-redundant cu* widen arm and custom-pin companion
  block collapse into the default; the curated ROCm >=2.11 floors stay
  literal.
- install.ps1: the hoisted default trio, the CUDA flavor repair and the
  ROCm CPU fallback all use the <2.12 trio (the leaf gate collapsed
  since cu and non-cu now share the range).
- setup.ps1: the unknown-leaf pinned CUDA trio widens to <2.12,
  matching the pinned cpu path.

Deliberately NOT widened: rocm6.4 (tops at torch 2.9.1) and rocm7.0
(2.10.0) by index content; macOS x86_64 (no >=2.4 wheels, stays
no-torch); the AMD per-arch repo.amd.com curated bounds for arches
outside the 2.11 allowlist.

Constraint suites updated to the ceiling scheme; parity suites updated
to the widened trio. All sh, ps1 and pytest installer suites pass (the
host-defaults suite and the tokenizers negative-control are known
pre-existing failures).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request bumps the default PyTorch ceiling constraint to <2.12.0 (allowing PyTorch 2.11) and updates companion package constraints (torchvision to <0.27.0 and torchaudio to <2.12.0) across the installation scripts and tests. It centralizes these version ceilings into variables in install.sh to simplify future updates, refactors and simplifies comments in install_python_stack.py, and adds a new PowerShell unit test for the Windows installer's torch preservation helpers. Feedback on the changes highlights a portability issue in tests/sh/test_torch_constraint.sh, where using a backslash-escaped pipe for alternation in grep is a non-portable GNU extension that fails on macOS; using grep -E with a standard pipe is recommended to ensure the test does not silently pass.

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.

Comment thread tests/sh/test_torch_constraint.sh Resolved

@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: 3f79b5e53d

ℹ️ 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 Resolved
Comment thread install.ps1 Resolved
Comment thread install.sh Resolved

@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

# rocm7.1 and earlier: torch 2.x below 2.11
"_default": (
"torch>=2.4,<2.11.0",

P2 Badge Align ROCm 7.1 repair specs with the new torch default

On Linux ROCm 7.1 hosts where studio update needs to repair a CPU/non-ROCm torch, _ensure_rocm_torch() selects the rocm7.1 tag and then falls through to _ROCM_TORCH_PKG_SPECS["_default"], which still caps the trio below 2.11. This conflicts with the changed install.sh default (<2.12.0) and the commit's stated ROCm 7.1 2.11 support, so a repair/update installs torch 2.10 while a fresh install selects 2.11. Add a rocm7.1 2.11 spec (or otherwise update this fallback) while retaining the older caps only for indexes that cannot provide 2.11.

ℹ️ 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 studio/setup.ps1
Comment on lines +2962 to +2966
if ($env:UNSLOTH_KEPT_TORCH -match '^\d+\.\d+(\.\d+)?$') {
$_keptMinor = [int](($env:UNSLOTH_KEPT_TORCH -split '\.')[1])
$cpuTorchSpec = "torch==$($env:UNSLOTH_KEPT_TORCH)"
$cpuVisionSpec = "torchvision==0.$($_keptMinor + 15).*"
$cpuAudioSpec = "torchaudio==2.$($_keptMinor).*"

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 Clear a stale kept-torch handoff before invoking setup

If a caller already has UNSLOTH_KEPT_TORCH in its environment—for example after an interrupted earlier irm ... | iex run—this new setup-side check applies that stale exact pin even when the current install found no preservable venv release or UNSLOTH_TORCH_UPGRADE=1 was requested. The parent only removes the variable after setup returns, so a fresh CPU/CUDA install can be silently pinned to the old value; clear this internal handoff variable before the preservation decision and set it only when Get-PreviousTorchPin succeeds.

Useful? React with 👍 / 👎.

Comment thread install.ps1 Resolved
Three review follow-ups:

- install.sh's existing-venv torch probe now reads the version from dist
  metadata via the bounded runner instead of importing torch: a wedged
  CUDA/ROCm driver can hang the import indefinitely, while the metadata
  read never touches the driver. A failed or timed-out probe simply
  yields no preservable version.

- install.ps1's New-UnslothTorchOverridesFile folds caller-supplied
  UV_OVERRIDE files into the temporary overrides file (minus their
  torch-trio lines), matching install.sh: --overrides replaces the env
  file wholesale, so without the merge a caller's own dependency
  overrides were silently dropped during the unsloth resolution.

- install.ps1 clears an inherited UNSLOTH_KEPT_TORCH before the pin
  decision and sets it only on a fresh Get-PreviousTorchPin result: an
  interrupted earlier run could leak a stale exact pin into setup.ps1
  even when the current run found nothing to preserve or the upgrade
  opt-in was set.

Verified: the metadata probe returns the installed release through the
bounded runner; the override filter keeps unrelated pins (numpy,
torchao) while dropping torch/torchvision/torchaudio lines in all spec
forms. Full sh, ps1 and pytest installer batteries pass (host-defaults
and the tokenizers negative-control are the known pre-existing
failures).
@chatgpt-codex-connector

This comment has been minimized.

@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

unsloth/install.sh

Lines 2179 to 2180 in 0a32590

if ! run_install_cmd_retry "install PyTorch (kept release)" uv pip install --python "$_VENV_PY" "$TORCH_CONSTRAINT" "$_itdi_tv" "$_itdi_ta" \
--default-index "$TORCH_INDEX_URL" "$@"; then

P2 Badge Pass the preserved torch pin to uv

When an existing venv has a preservable patch release such as torch 2.10.0, this kept-release path never supplies $_PREV_TORCH_PIN; it supplies the broad TORCH_CONSTRAINT instead. The wildcard companion pins can then resolve to a newer companion patch whose metadata selects a newer torch patch/minor, so the rerun silently upgrades the release it is meant to preserve (especially on mirrors exposing newer companion builds). Use $_PREV_TORCH_PIN in this install command and retain the existing range only for the fallback.

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

… failure

- test_torch_constraint.sh: use grep -E for the hardcoded-range guard. The BRE
  \| alternation is a GNU extension; on BSD/macOS grep it can be a literal, so
  the regression guard could silently no-op on a supported platform.
- install.ps1: clear UNSLOTH_KEPT_TORCH in Exit-InstallFailure. A non-Tauri
  irm | iex run throws while the caller session stays alive, so a leaked
  kept-torch handoff could let a later setup/update re-pin an abandoned exact
  torch release.
Reconcile PR #7256 (Windows torch 2.11 + release preservation, installer
comment reduction, torch 2.11 default line) with 77 commits of main install
rewrites. Base is main's newer install semantics; this branch's still-novel
contributions are layered on top.

Key decisions:
- install.ps1: kept main's rollback lifecycle (try/finally Restore-StudioVenvRollback,
  #7342) and the installed-version report (#7265); layered this branch's torch-2.11
  allowance (torch<2.12.0 on the Windows CUDA fresh-install, CPU fallback and flavor
  repairs), the release-preservation port (Get-InstalledTorchVersionRaw / kept-release
  installs / UNSLOTH_KEPT_TORCH handoff / torch-overrides freeze) and the Exit-InstallFailure
  UNSLOTH_KEPT_TORCH clear.
- install.sh: took main's newer AMD/Strix routing (per-arch index reroute #7264/#7300,
  runtime-less gfx inference #7305, KFD detection fix #7314, Radeon 8065S regex #7290,
  signal-restore trap #7342) and the #7365 unsloth pin bump; kept this branch's
  _TORCH_CEILING/_TORCHVISION_CEILING/_TORCHAUDIO_CEILING refactor widening the default
  ceiling to torch<2.12.0.
- studio/install_python_stack.py: deferred all five code conflicts to main's Strix
  inference logic (result is AST-identical to main; only comment reductions remain).
- studio/setup.ps1: took main's comment covering the whisper.cpp dictation markers
  (#7095); the UNSLOTH_KEPT_TORCH consumption handoff auto-merged intact.

Dropped as superseded by main: this branch's stale unsloth>=2026.7.4 pins (main #7365),
the older rocm7.1->rocm7.2 Strix reroute (main #7264/#7300), the narrow Radeon 80[0-9]0S
regex (main #7290), and the pre-inference has_hip_torch gate (main's rocm_torch_ready gate,
Codex P1 #7305). The two review-item fixes (grep -E in test_torch_constraint.sh,
UNSLOTH_KEPT_TORCH clear in Exit-InstallFailure) survive.
@chatgpt-codex-connector

This comment has been minimized.

@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: 96d8b99e65

ℹ️ 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 Resolved
Comment thread install.ps1 Resolved
Comment thread install.ps1
Comment on lines +2274 to +2276
$script:PrevTorchPin = Get-PreviousTorchPin -TorchVersion $script:PrevTorchVer -Constraint $_routeWindow
if ($script:PrevTorchPin) {
$env:UNSLOTH_KEPT_TORCH = $script:PrevTorchPin.Release.PublicBase

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 Clear the torch handoff in the outer failure cleanup

This process-scoped handoff is cleared by Exit-InstallFailure and on the normal path, but terminating exceptions that bypass that helper leave it set in the caller's session. For example, failure to create the temporary overrides file or failure to launch the setup executable after this assignment propagates through the outer rollback finally without reaching the clear at the end of setup; this matters for the documented irm | iex flow because the PowerShell session remains alive, and a later direct studio setup or update can consume the abandoned exact release. Remove UNSLOTH_KEPT_TORCH from the outer failure finally as well.

Useful? React with 👍 / 👎.

… failures

Three review follow-ups on the Windows port:

- The previous-release probe reads dist metadata rather than importing
  torch, matching install.sh. A broken CUDA/ROCm DLL (or an import slow
  enough to hit the timeout) made the probe return nothing, so the pin
  was never created and the installer replaced the venv with the newest
  supported release even though UNSLOTH_TORCH_UPGRADE was unset.

- The preservation state is reset at the top of the install instead of
  inside the existing-venv branch. Under the documented irm | iex flow
  the script scope IS the caller's session, so a second invocation
  against a different UNSLOTH_STUDIO_HOME with no existing venv skipped
  the branch and inherited the earlier run's release, pinning a fresh
  install to an unrelated venv's torch. The pin is reset with it, so the
  no-index fallback path cannot see a stale pin either.

- UNSLOTH_KEPT_TORCH is cleared from an outer finally around the
  installer entry point. The in-flow clears and Exit-InstallFailure
  cover the handled paths, but a terminating exception between the
  export and the end of setup left the handoff set in a session that
  outlives the installer, where a later studio setup or update would
  consume the abandoned exact pin.

Verified the metadata probe end to end (returns the installed release
through the bounded runner; a missing interpreter still yields null).
Three regression guards added to tests/studio/test_previous_torch_pin.ps1
for the metadata read, the pre-branch reset ordering and the outer
finally. Full sh, ps1 and pytest installer batteries pass (host-defaults
and the tokenizers negative-control are the known pre-existing
failures).
@chatgpt-codex-connector

This comment has been minimized.

@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: 1d1bd91326

ℹ️ 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 Resolved
Comment thread install.sh
Comment on lines +2052 to +2054
_TORCH_CEILING="2.12.0"
_TORCHVISION_CEILING="0.27.0"
_TORCHAUDIO_CEILING="2.12.0"

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 Keep the default on a torchcodec-compatible torch line

When a fresh wheel-backed install resolves the new torch 2.11 default, install_python_stack.py still unconditionally installs torchcodec==0.10.0 from studio/backend/requirements/extras-no-deps.txt with --no-deps. The repository's upstream-derived compatibility matrix pairs torchcodec 0.10 only with torch 2.10 and has no torch 2.11 pairing, so its native decoder can fail to load and disable_torchcodec_if_broken() then makes torchcodec unavailable to Transformers and Datasets. Add a torch-2.11-compatible codec selection before making 2.11 the default, or retain the prior torch line for installs that include the audio extras.

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.

The torchcodec pairing is right (upstream matrix: 0.10 -> torch 2.10, 0.11 -> torch 2.11), but torch 2.11 is not a new default and this PR does not introduce the mismatch.

origin/main already widens every CUDA leaf to the same ceiling:

install.sh:3189      cu[0-9]*)
install.sh:3190          TORCH_CONSTRAINT="torch>=2.4,<2.12.0"

and https://download.pytorch.org/whl/cu128 tops out at torch-2.11.0, so main already installs torch 2.11.0+cu128 alongside torchcodec==0.10.0. studio/backend/requirements/extras-no-deps.txt is untouched by this diff.

That also rules out the second suggested remedy: the audio extras install on CUDA hosts too, so "retain the prior torch line for installs that include the audio extras" would not change what those hosts already resolve. Pairing the codec properly needs a 2.11 row in both TORCH_TORCHCODEC and _TORCH_TORCHCODEC_MINORS (their equality is asserted by test_torchcodec_matrix_matches_notebook_validator), an audio-torch211 extra in pyproject.toml, and a torch-minor-keyed pin in the studio requirements. That is a separate change, tracked on its own, not a blocker for the ceiling bump.

Comment thread install.sh Resolved
The rocm7.1 leaf fell through to _ROCM_TORCH_PKG_SPECS["_default"], which caps
the trio below 2.11. Now that install.sh leaves a rocm7.1 leaf on the widened
default range, a fresh install resolves torch 2.11.0+rocm7.1 while the later
dependency pass force-reinstalled 2.10.0+rocm7.1 over it, so any repair or
`studio update` silently downgraded the environment.

download.pytorch.org/whl/rocm7.1 serves a paired 2.11 trio, verified with
uv pip compile --no-deps against that index:

  install.sh default range -> torch 2.11.0+rocm7.1, torchvision 0.26.0+rocm7.1,
                              torchaudio 2.11.0+rocm7.1
  _default repair spec     -> torch 2.10.0+rocm7.1, torchvision 0.25.0+rocm7.1,
                              torchaudio 2.10.0+rocm7.1

Give rocm7.1 its own entry carrying install.sh's default range rather than the
rocm7.2 tuple: only the _grouped_mm arches take the hard 2.11 floor, so
_ROCM_KNOWN_TORCH211_VERSIONS stays {(7, 2)}. _default keeps its literal <2.11
ceiling because rocm7.0 and older genuinely top out below it (rocm7.0 at 2.10.0,
rocm6.4 and rocm6.3 at 2.9.1, rocm6.2 at 2.5.1), and the stale index comments
are corrected to match what those indexes serve today.
@chatgpt-codex-connector

This comment has been minimized.

Three files conflicted, all on the gfx906 (MI50 / Radeon VII) work that landed
on main next to this branch's comment pass and torch 2.11 default rollout.

install.sh: kept main's _is_gfx906_bnb_skip / _gfx906_bnb_snapshot / _prune
helpers and the _gfx906_bnb_snapshot call in the migrated path, with this
branch's condensed comments. The gfx906 reroute keeps its literal
TORCH_CONSTRAINT="torch>=2.4,<2.11.0": the rocm6.3 index it routes to tops out
at torch 2.9.x, so it is now a deliberate narrower cap rather than a restatement
of the default, and the comment says so.

studio/install_python_stack.py: kept main's _runtime_is_gfx906 detection, the
rocm6.3 legacy override and the bnb skip/prune branch, again with the condensed
comments. _ROCM_TORCH_PKG_SPECS["_default"] stays at <2.11.0, which is what the
gfx906 path installs from.

tests: the two sides asserted opposite things about hard-coded torch ranges in
install.sh. This branch composes the default from _TORCH_CEILING and asserted
zero literals; main asserted the literal exists and only on a TORCH_CONSTRAINT=
assignment. Merged into the rule both wanted: a literal range is allowed only on
a curated per-index TORCH_CONSTRAINT= override, never on a pip/uv install line,
plus a separate check that the gfx906 reroute keeps its sub-2.11 cap. The same
resolution is applied to tests/sh/test_torch_constraint.sh, which asserted the
zero-literal count and would otherwise have gone red on main's new assignment.
danielhanchen added a commit that referenced this pull request Jul 27, 2026
Resolves 85 conflicted files, all of which trace to the branch's
pre-commit.ci commit 18673a5 rather than to any change this PR authored.

Why the code side takes 'pip':

At the merge base the pip branch's [tool.ruff] table had no line-length,
so ruff-format fell back to its 88 column default and the pre-commit.ci
run reformatted 682 files to 88 columns. Since then 3455b45 ("pip: track
main's packaging and tooling config") added line-length = 100 to pip,
matching main. The bot commit is therefore churn produced under a tooling
config the base branch has since corrected, and re-running the hook on the
merged tree reproduces pip's 100 column formatting, not the branch's.

It also carries no behaviour: all 682 files it touches are .py, and every
one of them is AST identical before and after, so dropping the reformat
drops formatting only. The resolved tree is byte identical to pip
everywhere except pyproject.toml.

pyproject.toml (no textual conflict, but two semantic points):

- torch>=2.4.0,<2.11.0 -> <2.12.0 was made independently on both sides,
  by this PR in cd50f9e and on pip in b22b243, with the identical value.
  The merged file keeps <2.12.0, so neither side is undone. This also
  matches the exclusive _TORCH_CEILING="2.12.0" that #7256 introduces in
  install.sh, which expands to torch>=2.4,<2.12.0.

- The huggingfacenotorch and amd extras are this PR's remaining novel
  content; pip has neither. They are re-applied on top of pip's file.
  The one deliberate rewrite is huggingfacenotorch's unsloth_zoo floor,
  from >=2026.7.4 to >=2026.7.6: b22b243 raised every other unsloth_zoo
  pin on pip to 2026.7.6, and main's own huggingfacenotorch already says
  2026.7.6, so keeping 2026.7.4 would have reintroduced a stale floor that
  the base branch had just retired. The amd extra is unchanged from main.

Line level preservation was checked in both directions: all 90477 lines
pip added since the merge base survive, and all 26 lines this branch added
survive except the single unsloth_zoo floor noted above.
Delete rather than reword. What goes: restatements of the line below them,
section banners, signature and usage echoes, duplicated facts repeated at a
second or third call site, and multi-line rationales that fit on one line.

What stays: invariants the code does not state, the wrong-alternative notes
(Get-Item -Force vs Test-Path on a broken junction, [Process]::Start vs
Start-Process -PassThru on PS 5.1, --list-gpu-code vs --list-gpu-arch), the
cross-file sync rules on the torch ceilings and the ROCm allowlists, and the
issue and PR citations.

738 added comment lines across the branch become 400.

Three comments are load-bearing for tests and are kept verbatim: the
"# Provision Node " terminator that test_frontend_dist_cache.py slices
setup.ps1 on, the "static --asic" mention that test_rocm_support.py greps in
both Windows installers, and the newest-trio loop marker that
test_previous_torch_pin.sh orders the Radeon kept-trio attempt against.

Comments, docstrings and whitespace only. Verified with comment_tools.py on
the Python files, bash -n on the shell files, PowerShell ParseFile on the ps1
files, and a diff review confirming no non-comment line moved. tests/sh
(57 files), tests/studio ps1 (24 files) and the tests/python plus tests/studio
pytest run all report the same results as before the pass.

@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: 4448d02161

ℹ️ 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
$_keptTorch = $script:PrevTorchPin.TorchSpec; $_keptVision = $script:PrevTorchPin.VisionSpec; $_keptAudio = $script:PrevTorchPin.AudioSpec
$_keptSpecs = @($_keptTorch, $_keptVision)
if ($_torchSpecs.Count -ge 3) { $_keptSpecs += $_keptAudio }
$torchInstallExit = Invoke-InstallCommandRetry -Label "install PyTorch (kept release)" { & $script:UvExe pip install --python $VenvPython @_keptSpecs --default-index $TorchIndexUrl }

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 Exclude inherited torch overrides from kept-release installs

When UV_OVERRIDE contains a torch entry (for example, torch<2.11), this kept-release command still inherits it. Checked uv 0.12.1 pip install --help, which identifies --overrides as [env: UV_OVERRIDE=]; a local dry run also confirms that such an override replaces even a direct exact requirement. Thus an existing 2.11.0 install can be resolved to 2.10.0 while this command returns success, leaving $script:PrevTorchPin set and causing the later overrides file to freeze the already-downgraded version. Filter or temporarily suppress inherited torch-trio overrides for all kept-release installs.

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.

Your uv mechanism is right and I reproduced it end to end, but I am not taking the fix, and the reasons matter more than the verdict.

Reproduced first, against both the pinned uv 0.12.1 and the local 0.11.32, with hand-built wheels and a metadata-accurate fake trio: UV_OVERRIDE is honoured with no explicit --overrides flag, an override line really does beat a direct exact requirement on the command line, and the kept-release command downgrades torch 2.11.0 to 2.10.0 and still exits 0, silently, with no uv warning at any verbosity. So the premise is sound.

Three things stop it though. First, the stated consequence does not hold: New-UnslothTorchOverridesFile does not read $script:PrevTorchPin at all, it shells out to importlib.metadata against the live venv, so it freezes torch==2.10.0, which is what is actually installed, and the resulting file is satisfiable. Nothing wrong is frozen. Second, the outcome is not specific to the kept-release path. I ran the non-kept fallback with its range specs under the same override and got the identical trio, because the override replaces torchvision's own declared torch==2.11.0 dependency too. Filtering only the kept-release command would change nothing about what lands and would make the two branches disagree. Third, the exposure is not introduced here: install.sh's kept-release path has the same shape and already had it at the merge base.

There is a real residual, and it is smaller than P2: PrevTorchPin and UNSLOTH_KEPT_TORCH stay stale at 2.11.0 because the exit code was 0, so the "keeping it" substep is untrue and setup.ps1 receives a pin that no longer matches reality. That is a message-accuracy problem, and the installer already self-reports it, the red "kept torch X but the environment now has torch Y" warning fires in exactly this scenario. I would rather fix that by re-validating the pin against the venv after the install than by overruling a caller who has explicitly told uv never to install torch 2.11, and it needs doing on both installers at once for parity. Tracking it as a follow-up rather than bolting a Windows-only half onto this branch.

One adjacent thing worth having on the record, since I found it while checking yours: an inherited override on a COMPANION, torchvision<0.26, makes the kept command genuinely unsatisfiable and the fallback fires correctly, but the warning then says torch==2.11.0 is not installable when the real blocker was torchvision. Same on the shell side.

…st on prose

Two things, one a review item and one collateral from the comment pass.

The override file. Before this branch the only path was
_UNSLOTH_TORCH_OVERRIDES=$(mktemp), which is 0600. The new beside-the-caller
branch creates it with `: > "$file"`, which under the common umask 022 gives
0644. The merge below it copies every inherited non-torch requirement in, and a
direct URL requirement can carry credentials, so another local user could read
them for the length of a torch install. Measured: `: >` gives 644 and the mktemp
fallback gives 600, so the two halves of the same decision disagreed.

Created under a scoped umask 077 now, plus an explicit chmod 600. The chmod is
not belt and braces: `: >` truncates a pre-existing file without touching its
mode, so a stale file left by a recycled PID would keep whatever it had. Measured
that too, and the test asserts it, because it is the part a later reader would
most likely delete as redundant.

install.ps1 needs no counterpart. It creates the file with New-Item, and NTFS
inherits the parent ACL rather than applying a umask.

The test collateral. test_xformers_step_runs_after_the_torch_flavor_repair
located the flavor-repair step by the exact text of its section header. Tightening
that comment inserted one word, "Enforce the" became "Enforce that the", and the
test went red without a single behavioural change. It now anchors on code that a
comment pass cannot touch: the Get-ExpectedTorchFlavorTag assignment, the pinned
xformers spec and the CI overlay variable. All three are unique in the file and
the ordering they assert is the same one.

19 pass in tests/sh/test_unsloth_torch_override.sh, up from 14, and the two new
static assertions fail at the previous head. The whole shell suite is green, 57
files, and tests/python plus tests/studio/install give 4766 passed with only the
pre-existing unrelated test_grpo_ddp_model_config failure.

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

ℹ️ 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
Comment on lines +5643 to +5645
$_pinTorchSpec = "torch>=2.4,<2.12.0"
$_pinVisionSpec = "torchvision>=0.19,<0.27.0"
$_pinAudioSpec = "torchaudio>=2.4,<2.12.0"

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 Pair torchcodec with the newly enabled Windows torch 2.11

On a fresh Windows install where this widened spec resolves torch 2.11, the later dependency pass still unconditionally installs torchcodec==0.10.0 from studio/backend/requirements/extras-no-deps.txt; that codec is paired with torch 2.10, while torch 2.11 requires the 0.11 line, so its native decoder becomes unusable for audio workflows. Fresh evidence beyond the prior rejection is that this diff newly changes the Windows installer from <2.11.0 to <2.12.0; the rebuttal only established that Linux CUDA already had that range. Select torchcodec according to the resolved torch minor, or keep Windows below 2.11 until the codec pin is updated.

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.

The pairing is right and I went further than the compatibility table to confirm it, but I am deferring the fix rather than taking it here.

Verified at symbol level instead of trusting the matrix. Of the 200 undefined _Z* symbols in torchcodec 0.10.0's native libs, exactly one resolves under torch 2.10 and not under 2.11: _ZN3c1013MessageLoggerC1EPKciib, c10::MessageLogger::MessageLogger(char const*, int, int, bool), which 2.11 replaces with the c10::SourceLocation overload. All ten libs in the wheel reference it, torch.ops.load_library goes through ctypes.CDLL which forces RTLD_NOW, so it is a hard failure at import, not a latent one. The win_amd64 wheel has the same break through c10.dll, and PE imports bind eagerly too, so Windows is not spared. torchcodec declares no Requires-Dist: torch at any version, and the step runs --no-deps anyway, so no resolver will ever catch this.

Where I disagree is the framing. This diff widens the population, it does not create the class: origin/main already forces torch>=2.11.0,<2.12.0 on Windows for gfx1150, gfx1151, gfx1152, gfx1200 and gfx1201 in both install.ps1 and studio/setup.ps1, as a floor rather than a ceiling, and already bounds the pinned Windows CPU route at <2.12.0. Those users pair torch 2.11 with torchcodec==0.10.0 today. The install also does not break: disable_torchcodec_if_broken() catches exactly the (ImportError, RuntimeError, OSError) this raises and makes torchcodec present-as-absent, and the trainer then routes audio through soundfile.

The complete fix is already open as #7474, which is what the earlier round deferred to: a 2.11 row in both _TORCH_TORCHCODEC_MINORS and TORCH_TORCHCODEC (their equality is asserted), an audio-torch211 extra, and a torchcodec spec selected from the venv's resolved torch minor after the final torch repair. Landing a half version here would collide with it, and a bare 2.11 row on its own would false-positive: 0.12 through 0.16 declare torch>=2.11 and are ABI-stable forward, so the guard has to short-circuit them.

One thing neither round has said out loud, and it is the part I like least: the guard is silent. _torchcodec_version_mismatch_hint returns None when the torch minor has no row, so on 2.11 the user gets no warning at all. That is the strongest argument for #7474 and the reason it is not being left to rot.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
…k it

Four tests in test_windows_amd_gpu_scan_fallback.py were failing with
`ValueError: substring not found` rather than an assertion that said anything.
The helper that slices install.ps1's `if (-not $HasROCm)` scan out of the shipped
source ended its slice on the comment `# Capture ROCm version for wheel
selection`, and the comment pass in f91e9c9 removed that line. Nothing about
the code under test changed; the extractor simply lost its landmark.

Both ends are now code. The start is found by locating the scan's own
`$amdAdapters = @(Get-CimInstance Win32_VideoController` and walking back to the
enclosing guard, which keeps the guard in the extracted block without depending
on the eight comment lines that sit between the two. The end is the next
statement, the hipconfig probe.

_arch_resolution_block had the same shape against studio/setup.ps1, keyed on
`# Arch resolution:` and `# Capture ROCm version early`. Those still exist, so its
tests were green, but it is the same landmine and it is fixed the same way rather
than left for the next pass to find.

Not related, and stated here so it is not read as this branch's: the four
failures in tests/studio/test_update_release_notes.py on the merge ref come from
main. The banner components and that test file are byte-identical to origin/main
on the merge, and they fail there; this branch does not touch either.

@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: 1408e608a8

ℹ️ 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
if ($env:UV_OVERRIDE) {
foreach ($ovFile in ($env:UV_OVERRIDE -split '\s+' | Where-Object { $_ })) {
if (Test-Path -LiteralPath $ovFile -PathType Leaf) {
$lines += @(Get-Content -LiteralPath $ovFile | Where-Object {

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 Decode inherited overrides as UTF-8 before merging

When this runs under supported Windows PowerShell 5.1 and a BOM-less UTF-8 UV_OVERRIDE contains a non-ASCII local path such as ./données/pkg.whl, Get-Content decodes it using the active ANSI code page. The later UTF-8 WriteAllText therefore preserves mojibake rather than the original path, and the Unsloth install cannot locate that requirement. uv 0.12.1 help pip install defines --overrides as requirements files and identifies UV_OVERRIDE as the same setting, so read the inherited file explicitly as UTF-8 before filtering it.

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.

Correct, and taken in 012a723. Windows PowerShell 5.1 is a supported engine here and Get-Content really does decode a BOM-less file with the active ANSI code page there, so the accented path came back as mojibake and the UTF-8 write preserved it faithfully.

The read now goes through System.IO.File.ReadAllLines, which does UTF-8 with BOM detection on both engines and matches exactly what the function writes. I passed it the Convert-Path result rather than the raw value, since .NET resolves a relative path against its own working directory rather than PowerShell's, and that call was already being made one line later for the directory.

One honest limit on the test. pwsh on Linux already defaults to UTF-8, so a round-trip assertion cannot fail on this runner even unfixed. The assertion that actually holds the fix in place is on the reader itself, and the test says so instead of implying the round trip proves it.

Comment thread install.ps1
if ($ovDirs.Count -eq 1) {
try {
$candidate = Join-Path $ovDirs[0] ("unsloth-torch-overrides-" + [guid]::NewGuid().ToString("N") + ".txt")
New-Item -ItemType File -Path $candidate -ErrorAction Stop | Out-Null

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 Restrict access to the adjacent Windows override file

When UV_OVERRIDE is stored in a shared directory but the source file has a restrictive explicit ACL, New-Item creates this merged copy with the directory's inherited ACL instead. Because the merge copies non-torch lines that may contain authenticated direct URLs, another local user can read those credentials for the duration of the install even though they could not read the original file. Create the temporary file with a current-user-only ACL or preserve the source file's access restrictions before writing inherited contents.

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.

Right, and it is the sibling of a fix already made on the shell side. 012a723.

New-Item takes the containing directory's inherited ACL, so a restrictive ACL on the caller's own override file is not carried over, and the merged copy holds their non-torch lines verbatim, direct URLs with credentials included. install.sh creates its equivalent under umask 077 with an explicit chmod 600 after it, and this had no counterpart at all.

The copy now disables inheritance and carries a single current-user FullControl rule, applied to both the adjacent-directory file and the GetTempFileName fallback rather than only the first, since the fallback is the one that lands in a shared %TEMP% on a multi-user box. It is best effort and swallowed, matching the shell side's || true, which also makes it a clean no-op off Windows.

Comment thread install.ps1 Outdated
if (-not $f) { $f = [System.IO.Path]::GetTempFileName() }
# UTF-8 without a BOM, not -Encoding ascii, which would rewrite a non-ASCII path in the caller's override as "?".
# WriteAllText adds no trailing newline: terminate the last line or two requirements join into one.
[System.IO.File]::WriteAllText($f, (($lines -join "`n") + "`n"), (New-Object System.Text.UTF8Encoding($false)))

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 Track the override path before writing it

If WriteAllText throws after creating $f—for example because the disk fills during the write—the function never returns, so the assignment to $script:TorchOverridesFile at the call site never occurs and the outer cleanup cannot remove this file; a partial write can therefore leave copied authenticated requirement URLs behind. Fresh evidence after the earlier cleanup fix is that the current revision still keeps the path only in local $f until after the potentially failing write. Assign the tracked path before writing or delete $f in a helper-local failure handler.

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.

Correct, and the ordering is a one-line matter, so taken. 012a723.

The path lived only in the local until the function returned, so a throw from WriteAllText left the outer cleanup with nothing to remove, and what stayed on disk was a partial copy of the caller's override. $script:TorchOverridesFile is now assigned the moment the file exists, and a failed write deletes it and clears the record before rethrowing, so neither half is left half-done.

A test asserts the ordering from the AST rather than by substring, because the property that matters is that the assignment precedes the write, and a later edit could satisfy a substring check while reversing it.

Three defects in New-UnslothTorchOverridesFile, all of them the PowerShell twin
of things install.sh already does.

Get-Content decodes a BOM-less file with the active ANSI code page on Windows
PowerShell 5.1, which is a supported engine here, so a non-ASCII local path in the
caller's UV_OVERRIDE came back as mojibake and the UTF-8 write preserved it. uv
then looked for a requirement that does not exist. The read goes through
System.IO.File.ReadAllLines instead, which does UTF-8 with BOM detection on both
engines and matches what we write.

The merged copy carries the caller's non-torch lines, and one of those can be an
authenticated direct URL. New-Item takes the containing directory's inherited ACL,
so a restrictive ACL on the source override was not carried over and a shared
override directory exposed the credentials for the length of the install. The
copy now has inheritance disabled and a single current-user FullControl rule.
That is the same reasoning as the umask 077 plus explicit chmod 600 on the shell
side, and it is best effort in the same way, a no-op off Windows.

WriteAllText can throw, a full disk being the obvious way, and until the call
site's assignment ran the outer cleanup had no path to remove, so a partially
written copy of the caller's override stayed on disk. The path is now recorded in
$script:TorchOverridesFile as soon as the file exists, and a failed write deletes
it and clears the record before rethrowing.

Five tests added to tests/studio/test_torch_overrides_merge.ps1. Two are
behavioural, two assert the AST ordering and the failure handler, and one pins the
reader. The split is deliberate: all three effects are Windows-only, and pwsh on
Linux already defaults to UTF-8, so a round-trip test would pass here even
unfixed. The test says so rather than implying it proves more than it does.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

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

Copy link
Copy Markdown
Member Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 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: 012a723fca

ℹ️ 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
# Place the merge next to the caller's override when they share one writable directory (as install.ps1 does), else fall back to mktemp.
_ov_dir=""
_ov_dir_ok=1
for _ov_file in ${UV_OVERRIDE:-}; do

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 Prevent glob expansion when reading UV_OVERRIDE paths

When an override filename contains shell metacharacters and a matching sibling exists—for example, UV_OVERRIDE=/dir/override[1].txt beside /dir/override1.txt—this unquoted expansion iterates over the sibling rather than the literal configured file, so the generated file silently drops or replaces the caller's overrides. uv pip install --help describes this variable as “Override versions using the given requirements files [env: UV_OVERRIDE=]”, and uv 0.12.1 itself successfully reads the literal bracketed filename; disable pathname expansion while splitting the environment value or otherwise preserve each literal path.

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.

Correct, and it is the one real drift between install.sh and install.ps1 in this change, which makes it worth more than its P2. Fixed in 0270a1e.

I measured it rather than reasoning from the shell rules. With ov[1].txt holding idna==3.6 and ov1.txt holding idna==3.7 in the same directory, the idiom as it stood iterated ov1.txt and folded idna==3.7 into the merge, while uv 0.11.32 given UV_OVERRIDE=ov[1].txt resolved idna==3.6. So the generated file actively contradicted the file uv would have read on its own, and since --overrides replaces UV_OVERRIDE, uv never got a second chance to see the real one. Your reading of the mechanism is exactly right: word splitting is fine and is what uv's space-separated list needs, pathname expansion is the part that bites.

Two things I would add to the report. The site count is one short: 5182 picks the output directory, but the second walk at 5215 is the one that copies content, so both had to be covered and the guard now spans them. And I confirmed no set -f was already in effect up the chain, which the item depends on: install.sh has set -e and set -euo pipefail, and its only two set -f sites, _dir_has_entries and _path_has_dir, save and restore locally and enclose neither loop.

The restore is an if rather than the [ ... ] && set +f form those two sites use, and that detail is load-bearing: they are each followed by a return, whereas this one is the last command of the case arm, so under set -e a false test would make the whole function exit non-zero. I checked that both ways in a shell before picking the form. There is also a new test that a space-separated UV_OVERRIDE still folds every file, since quoting the variable would stop the globbing too and would silently fold only the first.

Worth noting the repo already treats this hazard as in scope: _path_has_dir carries a comment saying field splitting also globs and that a directory holding *, ? or [ would otherwise match an unrelated entry. This was the same bug one function over.

Comment thread install.ps1
$ovDirs = @()
if ($env:UV_OVERRIDE) {
foreach ($ovFile in ($env:UV_OVERRIDE -split '\s+' | Where-Object { $_ })) {
if (Test-Path -LiteralPath $ovFile -PathType Leaf) {

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 Reject missing inherited override files

When UV_OVERRIDE contains a nonexistent path, this condition silently skips it and still creates a generated torch-only overrides file; the later --overrides option replaces the environment setting, so installation succeeds without any of the caller's intended constraints. This changes uv's normal behavior—uv pip install --help identifies UV_OVERRIDE as the environment form of the overrides-file option, and uv 0.12.1 reports File not found for such a path—so fail the install rather than discarding a missing inherited file.

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.

The premise is true and I verified it, but I am not making this change.

uv 0.11.32 does report error: File not found for a nonexistent UV_OVERRIDE path, so the divergence you describe is real. What it is not is a bug reachable on well-formed input: a path naming a file that does not exist is malformed, and nothing is lost by skipping it because there is no content there to lose. That is the difference between this and the globbing item beside it, where a real file's real contents were silently swapped for another file's.

On the merits I also think proceeding is the better behaviour. A stale exported UV_OVERRIDE left in a long-lived shell is common, and failing the entire Unsloth install over it would take down the torch pinning this merge exists to apply, for a reason the user never asked about. Skipping costs them nothing they had.

install.sh does the identical thing at its two walks, so this is a deliberate and consistent policy across both installers rather than a Windows-side oversight.

Comment thread install.ps1
if ($script:TorchOverridesFile) {
$baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (local)" { & $script:UvExe pip install --python $VenvPython --upgrade-package unsloth --overrides $script:TorchOverridesFile "$_unslothReleaseInstallSpec" "unsloth-zoo>=2026.9.1" }
Remove-Item -LiteralPath $script:TorchOverridesFile -Force -ErrorAction SilentlyContinue
$script:TorchOverridesFile = $null

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 Retain the override path when deletion fails

When the first Remove-Item fails transiently—for example, because an antivirus scanner or indexer still has the generated file open on Windows—SilentlyContinue suppresses the failure and this assignment immediately forgets the path. The outer finally therefore cannot retry deletion, leaving a file that may contain copied authenticated requirement URLs on disk; clear the tracked path only after confirming the file was removed. The generic install arm repeats the same sequence.

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.

The sibling half of this is right and I checked it, but it does not clear the bar for a change.

Both arms really are the same two lines, and the outer finally really is gated on if ($script:TorchOverridesFile), so a Remove-Item that SilentlyContinue swallows does leave the finally with nothing to retry. Credit for finding the second site rather than just the first; that is the pattern that has caused most of the real bugs in this PR.

Where it stops is the outcome. Nothing is executed wrongly, no call is dropped, no content is wrong and nothing crashes. What is left behind is a file after a deletion that had already failed, and the finally runs in the same process moments later, so an antivirus or indexer handle strong enough to defeat Remove-Item -Force would in all likelihood still be holding it. The retry buys very little for the extra state it adds.

install.sh has the same rm -f then clear sequence in both of its arms, so the two installers agree here. I would rather leave them agreeing than harden one side only, which is how the drift I did fix this round got in.

Both walks over UV_OVERRIDE split it unquoted, so field splitting is followed by
pathname expansion. uv reads the literal name, so a caller override called ov[1].txt
sitting beside an ov1.txt made both loops iterate the sibling instead: the merge
picked up the wrong requirements, and because --overrides replaces UV_OVERRIDE, uv
never saw the file the caller actually configured.

Measured rather than argued. With ov[1].txt holding idna==3.6 and ov1.txt holding
idna==3.7, the idiom as it stood iterated ov1.txt and folded idna==3.7 in, while uv
0.11.32 given the same UV_OVERRIDE resolved idna==3.6. So the merged file contradicted
the file uv would have read on its own.

Pathname expansion is now off for both walks and restored afterwards, the same shape
_path_has_dir already uses for PATH, whose comment describes this hazard in the same
terms. set -f leaves field splitting alone, so a space-separated list of override
files still folds every one of them, and there is now a test for that because it is
the property this guard could plausibly break.

The restore is an if rather than the [ ... ] && set +f form the other two sites use.
Those two are followed by a return; this one is the last command of the case arm, so
under set -e a false test would make the whole function exit non-zero.

install.ps1 splits on \s+ and tests with -LiteralPath, so the Windows half never had
this. It was a drift between the two implementations rather than a shared bug.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

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

Copy link
Copy Markdown

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

Reviewed commit: 0270a1ef92

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

Second pass over the prose this PR added. Long single-line explanations are cut
to the point they make, and the multi-line blocks in install.sh's UV_OVERRIDE
merge, install.ps1's New-UnslothTorchOverridesFile and the two override tests
collapse to one or two lines each. Net 30 lines removed, code untouched.

install.sh keeps the "independent Apple Silicon venv" wording verbatim:
tests/sh/test_mac_intel_compat.sh extracts that guard with an awk pattern
anchored on that exact substring, so the comment is part of the contract. Its
neighbouring note in the test now says so instead of describing the pattern as
loose.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@danielhanchen
danielhanchen merged commit 617975f into main Sep 4, 2026
92 checks passed
@danielhanchen
danielhanchen deleted the windows-torch-211 branch September 4, 2026 07:07
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.

4 participants