diff --git a/install.ps1 b/install.ps1 index 854df34a1eb5..a1e74443a9b3 100644 --- a/install.ps1 +++ b/install.ps1 @@ -9943,10 +9943,12 @@ main() } } - # Port of install.sh's cu130 torch 2.13 route (the only one prebuilt-wheels-cu13 serves). + # Port of install.sh's cu130 torch 2.13 / 2.14 route (the only one prebuilt-wheels-cu13 serves). + # New homes take torch 2.14, the newest on whl/cu130; vLLM is never installed into this venv. $script:Cu130TorchCeiling = "2.15.0" - $script:Cu130NewInstallTorchSpec = "torch>=2.13.0,<2.14.0" - $script:Cu130NewInstallVisionSpec = "torchvision>=0.28.0,<0.29.0" + $script:Cu130NewInstallTorchSpec = "torch>=2.14.0,<2.15.0" + $script:Cu130NewInstallVisionSpec = "torchvision>=0.29.0,<0.30.0" + $script:Cu130NewInstallTorchFloor = "2.14.0" # Local facts only: decides the keep window, so a PyPI outage cannot shrink it. function Test-Cu130Torch213Platform { @@ -9960,7 +9962,7 @@ main() return ($lines[-1].ToLowerInvariant() -eq "3.13 win-amd64") } - # An existing home never takes 2.13 unasked; UNSLOTH_TORCH_UPGRADE=1 (Settings > Repair) asks. + # An existing home never takes 2.14 unasked; UNSLOTH_TORCH_UPGRADE=1 (Settings > Repair) asks. # The PyPI check reads unsloth's metadata, so a `--package` other than unsloth keeps the default. function Resolve-Cu130TorchRoute { param([string]$IndexUrl, [string]$PythonExe, [Parameter(Mandatory = $true)][string]$DefaultSpec, [bool]$ExistingInstall, [string]$PackageName = "unsloth") @@ -9968,7 +9970,7 @@ main() if (-not (Test-Cu130Torch213Platform -IndexUrl $IndexUrl -PythonExe $PythonExe)) { return $result } $result.PreserveSpec = "torch>=2.4,<$($script:Cu130TorchCeiling)" if ($PackageName -eq "unsloth" -and (-not $ExistingInstall -or $env:UNSLOTH_TORCH_UPGRADE -eq '1') -and - (Test-PypiUnslothAdmitsTorch -Want "2.13.0")) { + (Test-PypiUnslothAdmitsTorch -Want $script:Cu130NewInstallTorchFloor)) { $result.NewInstall = $true } return $result @@ -10591,11 +10593,11 @@ print(*pair) substep "existing install has torch $script:PrevTorchVer -- keeping it (set UNSLOTH_TORCH_UPGRADE=1 to get the newest release)" } } - # A kept release that fails to reinstall falls back to the pre-route default below, never to 2.13. + # A kept release that fails to reinstall falls back to the pre-route default below, never to 2.14. if (-not $script:PrevTorchPin -and $_cu130NewInstallRoute) { $_pinTorchSpec = $script:Cu130NewInstallTorchSpec $_pinVisionSpec = $script:Cu130NewInstallVisionSpec - substep "cu130 + Python 3.13: installing torch 2.13, which the prebuilt flash-attn / causal-conv1d / mamba-ssm wheels are built for" + substep "cu130 + Python 3.13: installing torch 2.14, which the prebuilt flash-attn / causal-conv1d / mamba-ssm wheels are built for" } if ($SkipTorch) { substep "skipping PyTorch (--no-torch flag set)." "Yellow" diff --git a/install.sh b/install.sh index d35a25ce401f..5085ef99229b 100755 --- a/install.sh +++ b/install.sh @@ -4364,7 +4364,10 @@ fi TORCHVISION_CONSTRAINT="torchvision>=0.19,<${_TORCHVISION_CEILING}" TORCHAUDIO_CONSTRAINT="torchaudio>=2.4,<${_TORCHAUDIO_CEILING}" _CU130_TORCH_CEILING="2.15.0" -_CU130_NEW_INSTALL_TORCH="torch>=2.13.0,<2.14.0" +# New cu130 homes: torch 2.14 (newest on whl/cu130; inside the release cap). vLLM is never installed +# into this venv: a Studio engine shares torch only on an exact match, else gets its own env. +_CU130_NEW_INSTALL_TORCH="torch>=2.14.0,<2.15.0" +_CU130_NEW_INSTALL_FLOOR="2.14.0" # Apple Silicon: 2.13 is the first with fused MPS attention (mflux needs >=2.13); 2.15 lacks cp310/torchvision. _MACOS_TORCH_CEILING="2.15.0" _MACOS_NEW_INSTALL_TORCH="torch>=2.13.0,<2.14.0" @@ -5936,10 +5939,10 @@ _torch_release_in_window() { _cu130_torch213_route() { [ "$(_cu130_torch213_platform "$1")" = "yes" ] || { echo "no"; return; } [ "$(_cu130_torch213_host_ok)" = "yes" ] || { echo "no"; return; } - _pypi_unsloth_admits_torch "2.13.0" + _pypi_unsloth_admits_torch "$_CU130_NEW_INSTALL_FLOOR" } -# New installs only: torch 2.13 has no cp313t wheel, and the kernel wheels need glibc 2.35. +# New installs only: torch 2.13 / 2.14 have no cp313t wheel, and the kernel wheels need glibc 2.35. _cu130_torch213_host_ok() { _cth_gil=$("$VENV_DIR/bin/python" -c "import sysconfig; print('gil-disabled' if sysconfig.get_config_var('Py_GIL_DISABLED') else 'gil-enabled')" 2>/dev/null || echo "") [ "$_cth_gil" = "gil-enabled" ] || { echo "no"; return; } @@ -7031,18 +7034,18 @@ case "$_torch_index_leaf" in ;; esac fi # _torch_index_pinned guard (Radeon + Strix reroute) -# New installs on this route get 2.13; preservation keeps 2.4-2.14 installs on their release. +# New installs on this route get 2.14; preservation keeps 2.4-2.14 installs on their release. _PRESERVE_TORCH_CONSTRAINT="$TORCH_CONSTRAINT" _CU130_NEW_INSTALL_ROUTE=false _MACOS_NEW_INSTALL_ROUTE=false if [ "$SKIP_TORCH" = false ] && [ "$(_cu130_torch213_platform "$TORCH_INDEX_URL")" = "yes" ]; then _PRESERVE_TORCH_CONSTRAINT="torch>=2.4,<${_CU130_TORCH_CEILING}" - # An existing home never takes 2.13 unasked, even when its torch could not be read or kept. + # An existing home never takes 2.14 unasked, even when its torch could not be read or kept. # The PyPI check reads unsloth's metadata, so a --package other than unsloth keeps the default. if [ "$(printf '%s' "$PACKAGE_NAME" | tr '[:upper:]' '[:lower:]')" = "unsloth" ] \ && { [ "$_EXISTING_INSTALL" = false ] || [ "${UNSLOTH_TORCH_UPGRADE:-0}" = "1" ]; } \ && [ "$(_cu130_torch213_host_ok)" = "yes" ] \ - && [ "$(_pypi_unsloth_admits_torch "2.13.0")" = "yes" ]; then + && [ "$(_pypi_unsloth_admits_torch "$_CU130_NEW_INSTALL_FLOOR")" = "yes" ]; then _CU130_NEW_INSTALL_ROUTE=true fi elif [ "$SKIP_TORCH" = false ] && [ "$(_macos_torch213_platform "$TORCH_INDEX_URL")" = "yes" ]; then @@ -7075,7 +7078,7 @@ if [ "$SKIP_TORCH" = false ]; then fi if [ -z "$_PREV_TORCH_PIN" ] && [ "$_CU130_NEW_INSTALL_ROUTE" = true ]; then TORCH_CONSTRAINT="$_CU130_NEW_INSTALL_TORCH" - TORCHVISION_CONSTRAINT="torchvision>=0.28.0,<0.29.0" + TORCHVISION_CONSTRAINT="torchvision>=0.29.0,<0.30.0" fi if [ -z "$_PREV_TORCH_PIN" ] && [ "$_MACOS_NEW_INSTALL_ROUTE" = true ]; then TORCH_CONSTRAINT="$_MACOS_NEW_INSTALL_TORCH" diff --git a/studio/backend/tests/test_cu130_repair_torch_specs.py b/studio/backend/tests/test_cu130_repair_torch_specs.py index 1da29fdecc6b..43d7e68c27b9 100644 --- a/studio/backend/tests/test_cu130_repair_torch_specs.py +++ b/studio/backend/tests/test_cu130_repair_torch_specs.py @@ -1,10 +1,10 @@ # SPDX-License-Identifier: AGPL-3.0-only # Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0 -"""`studio update` torch repairs on the cu130 torch 2.13 route keep the resident release. +"""`studio update` torch repairs on the cu130 torch 2.13 / 2.14 route keep the resident release. install.sh and install.ps1 give new Linux x86_64 and Windows x64 cu130 Python 3.13 installs -torch 2.13; a repair on that route must not move an existing install to another torch, and every +torch 2.14; a repair on that route must not move an existing install to another torch, and every other route must get exactly the specs it got before. """ @@ -53,6 +53,7 @@ def _route( ("2.12.1", ("torch==2.12.1", "torchvision==0.27.*", "torchaudio==2.11.*")), ("2.13.0", ("torch==2.13.0", "torchvision==0.28.*", "torchaudio==2.11.*")), ("2.14.0", ("torch==2.14.0", "torchvision==0.29.*", "torchaudio==2.11.*")), + ("2.14.1", ("torch==2.14.1", "torchvision==0.29.*", "torchaudio==2.11.*")), ], ) @pytest.mark.parametrize( @@ -155,11 +156,13 @@ def test_both_cuda_repairs_use_the_route_aware_specs(mod): [ ("linux", "2.13.0", True), ("linux", "2.14.0", True), + ("linux", "2.14.1", True), ("linux", "2.12.1", False), ("linux", "2.11.0", False), ("linux", None, False), ("win32", "2.13.0", True), ("win32", "2.14.0", True), + ("win32", "2.14.1", True), ("win32", "2.11.0", False), ("darwin", "2.13.0", False), ], @@ -378,3 +381,46 @@ def test_a_directory_whose_acl_cannot_be_set_is_skipped(monkeypatch, tmp_path, m monkeypatch.setattr(mod, "_restrict_to_current_user", lambda path: False) assert mod._write_space_free_override("torch==2.13.0\n") == ("", None) assert list(temp.iterdir()) == [] and list(venv.iterdir()) == [Path(name)] + + +def _assigned(path: Path, pattern: str) -> str: + import re + + found = re.findall(pattern, path.read_text(encoding = "utf-8"), re.M) + assert len(found) == 1, (path.name, pattern, found) + return found[0] + + +@pytest.mark.parametrize( + "script, torch_pattern, vision_pattern", + [ + ( + "install.sh", + r'^_CU130_NEW_INSTALL_TORCH="([^"]+)"$', + r'^if \[ -z "\$_PREV_TORCH_PIN" \] && \[ "\$_CU130_NEW_INSTALL_ROUTE" = true \]; then\n' + r'\s*TORCH_CONSTRAINT="\$_CU130_NEW_INSTALL_TORCH"\n\s*TORCHVISION_CONSTRAINT="([^"]+)"$', + ), + ( + "install.ps1", + r'^\s*\$script:Cu130NewInstallTorchSpec = "([^"]+)"\s*$', + r'^\s*\$script:Cu130NewInstallVisionSpec = "([^"]+)"\s*$', + ), + ], +) +def test_new_cu130_homes_take_the_newest_minor_a_repair_keeps( + monkeypatch, mod, script, torch_pattern, vision_pattern +): + """A fresh cu130 home gets torch 2.14 (2.14.1 on whl/cu130), the top of the repair window, + and the repair then keeps exactly that release instead of moving it.""" + repo = _INSTALL_SCRIPT.parents[1] + torch_spec = _assigned(repo / script, torch_pattern) + vision_spec = _assigned(repo / script, vision_pattern) + assert torch_spec == "torch>=2.14.0,<2.15.0" + assert vision_spec == "torchvision>=0.29.0,<0.30.0" + assert torch_spec.endswith(f",<2.{mod._CU130_PRESERVE_TORCH_CEILING_MINOR}.0") + _route(monkeypatch, mod, torch = "2.14.1") + assert mod._cuda_repair_torch_specs(CU130, mod._CUDA_TORCH_PKG_SPEC) == ( + "torch==2.14.1", + "torchvision==0.29.*", + "torchaudio==2.11.*", + ) diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py index 878dec1eb4dd..89c98476c8f3 100644 --- a/studio/install_python_stack.py +++ b/studio/install_python_stack.py @@ -552,7 +552,8 @@ def _torch_index_leaf(url: str) -> str: "torchaudio>=2.4,<2.12.0", ) -# Mirrors install.sh / install.ps1's cu130 route: a repair keeps a resident 2.9-2.14 release. +# Mirrors install.sh / install.ps1's cu130 route: a repair keeps a resident 2.9-2.14 release, and +# new homes there take 2.14 (_CU130_NEW_INSTALL_TORCH), the newest minor this window keeps. _CU130_PRESERVE_TORCH_CEILING_MINOR = 15 _CU130_FIRST_TORCH_MINOR = 9 # download.pytorch.org/whl/cu130 starts at torch 2.9.0 @@ -599,7 +600,7 @@ def _cuda_repair_torch_specs( ) -> tuple[str, str, str]: """``default``, except that the cu130 torch 2.13 route keeps a resident release it serves. - Never installs 2.13 itself: whether a release admits it is install.sh's PyPI decision.""" + Never installs 2.14 itself: whether a release admits it is install.sh's PyPI decision.""" if not _is_cu130_torch213_route(index_url): return default release = _resident_torch_release() diff --git a/tests/sh/test_cu130_torch213_route.sh b/tests/sh/test_cu130_torch213_route.sh index c46d08762c0c..b424438d829e 100644 --- a/tests/sh/test_cu130_torch213_route.sh +++ b/tests/sh/test_cu130_torch213_route.sh @@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: AGPL-3.0-only # Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0 -# New Linux x86_64 cu130 Python 3.13 installs get torch 2.13; existing 2.4-2.14 installs keep theirs. +# New Linux x86_64 cu130 Python 3.13 installs get torch 2.14; existing 2.4-2.14 installs keep theirs. set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" @@ -9,7 +9,7 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" INSTALL_SH="${1:-$SCRIPT_DIR/../../install.sh}" _FUNC_FILE=$(mktemp) { - for fn in _mirror_uv_project_config _mirror_configured _run_bounded _pypi_unsloth_admits_torch _torch_index_url_leaf _cu130_torch213_route _cu130_torch213_platform _cu130_torch213_host_ok _torchaudio_for_torch_minor _torch_release_in_window _previous_torch_pin _dir_has_entries; do + for fn in _mirror_uv_project_config _mirror_configured _run_bounded _pypi_unsloth_admits_torch _torch_index_url_leaf _cu130_torch213_route _cu130_torch213_platform _cu130_torch213_host_ok _macos_torch213_platform _torchaudio_for_torch_minor _torch_release_in_window _previous_torch_pin _dir_has_entries; do sed -n "/^${fn}()/,/^}/p" "$INSTALL_SH" echo "" done @@ -18,6 +18,9 @@ _FUNC_FILE=$(mktemp) . "$_FUNC_FILE" rm -f "$_FUNC_FILE" unset UNSLOTH_TORCH_UPGRADE +# The route specs come from install.sh itself, so a change there is what gets tested. +_SPEC_LINES=$(grep -E '^_CU130_(TORCH_CEILING|NEW_INSTALL_TORCH|NEW_INSTALL_FLOOR)="[^"$`]*"$' "$INSTALL_SH") +eval "$_SPEC_LINES" VENV_DIR=$(mktemp -d) mkdir -p "$VENV_DIR/bin" @@ -79,9 +82,21 @@ GLIBC_MINOR=35; _ARCH=x86_64 rm -f "$VENV_DIR/bin/python" assert_eq "no venv python never" "no" "$(_cu130_torch213_route "$CU130")" -echo "=== route: only once the PyPI release admits torch 2.13 ===" +echo "=== new-install specs ===" +assert_eq "all three route specs are plain assignments" "3" "$(printf '%s\n' "$_SPEC_LINES" | grep -c .)" +assert_eq "new cu130 homes take torch 2.14" "torch>=2.14.0,<2.15.0" "${_CU130_NEW_INSTALL_TORCH:-}" +assert_eq "PyPI gate asks for the spec floor" "2.14.0" "${_CU130_NEW_INSTALL_FLOOR:-}" +assert_eq "preservation still keeps every 2.14" "2.15.0" "${_CU130_TORCH_CEILING:-}" +assert_eq "spec floor is the new-install floor" "yes" \ + "$([ "torch>=${_CU130_NEW_INSTALL_FLOOR:-x},<2.15.0" = "${_CU130_NEW_INSTALL_TORCH:-}" ] && echo yes)" +assert_eq "no cu130 gate asks PyPI for 2.13" "" \ + "$(sed -n '/^_cu130_torch213_route()/,/^}/p; /^if \[ "\$SKIP_TORCH" = false \] && \[ "\$(_cu130_torch213_platform/,/^elif/p' "$INSTALL_SH" | grep -F '"2.13.0"')" + +echo "=== route: only once the PyPI release admits torch 2.14 ===" _stub_python 3.13 -assert_eq "release admits 2.13" "yes" "$(_cu130_torch213_route "$CU130")" +assert_eq "release admits 2.14" "yes" "$(_cu130_torch213_route "$CU130")" +_pypi_fixture "torch<2.14.0,>=2.4.0" +assert_eq "release capped below 2.14 (admits 2.13)" "no" "$(_cu130_torch213_route "$CU130")" _pypi_fixture "torch<2.13.0,>=2.4.0" assert_eq "release still capped below 2.13" "no" "$(_cu130_torch213_route "$CU130")" _pypi_fixture "torch>=2.4.0" @@ -105,11 +120,16 @@ assert_eq "UV_INDEX_URL keeps the old window" "no" "$(UV_INDEX_URL=https://mirro _UVCFG="$VENV_DIR/uv.toml"; printf '[[index]]\nurl = "https://mirror.example/simple"\ndefault = true\n' > "$_UVCFG" assert_eq "uv.toml index keeps the old window" "no" "$(UV_CONFIG_FILE="$_UVCFG" _cu130_torch213_route "$CU130")" -echo "=== preservation never waits on PyPI; only a fresh home takes 2.13 ===" -_PRESERVE_BLOCK=$(sed -n '/^_PRESERVE_TORCH_CONSTRAINT="\$TORCH_CONSTRAINT"$/,/^ TORCHVISION_CONSTRAINT="torchvision>=0.28.0,<0.29.0"$/p' "$INSTALL_SH"; echo fi) +echo "=== preservation never waits on PyPI; only a fresh home takes 2.14 ===" +_PRESERVE_END='^ TORCHVISION_CONSTRAINT="torchvision>=0.29.0,<0.30.0"$' +_PRESERVE_BLOCK="" +if grep -q "$_PRESERVE_END" "$INSTALL_SH"; then + _PRESERVE_BLOCK=$(sed -n "/^_PRESERVE_TORCH_CONSTRAINT=\"\\\$TORCH_CONSTRAINT\"\$/,/$_PRESERVE_END/p" "$INSTALL_SH"; echo fi) +fi assert_eq "block found in install.sh" "yes" "$(printf '%s' "$_PRESERVE_BLOCK" | grep -q _CU130_NEW_INSTALL_ROUTE && echo yes)" +[ -n "$_PRESERVE_BLOCK" ] || _PRESERVE_BLOCK=":" substep() { :; } -_CU130_TORCH_CEILING="2.15.0"; _CU130_NEW_INSTALL_TORCH="torch>=2.13.0,<2.14.0"; SKIP_TORCH=false; TORCH_INDEX_URL="$CU130"; PACKAGE_NAME="unsloth" +SKIP_TORCH=false; TORCH_INDEX_URL="$CU130"; PACKAGE_NAME="unsloth" _run_block() { # $1 existing-install flag, $2 previous torch version _EXISTING_INSTALL="$1"; _PREV_TORCH_VER="$2" TORCH_CONSTRAINT="torch>=2.4,<2.12.0"; TORCHVISION_CONSTRAINT="torchvision>=0.19,<0.27.0" @@ -118,7 +138,7 @@ _run_block() { # $1 existing-install flag, $2 previous torch version for gate in unreachable capped open; do case "$gate" in unreachable) export UNSLOTH_PYPI_JSON_URL="http://127.0.0.1:9/unreachable" ;; - capped) _pypi_fixture "torch<2.13.0,>=2.4.0" ;; + capped) _pypi_fixture "torch<2.14.0,>=2.4.0" ;; open) _pypi_fixture "torch<2.15.0,>=2.4.0" ;; esac _run_block true "2.13.0+cu130" @@ -129,20 +149,26 @@ for gate in unreachable capped open; do _run_block true "" assert_eq "PyPI $gate: existing home with unreadable torch stays on the old default" "torch>=2.4,<2.12.0" "$TORCH_CONSTRAINT" _run_block false "" - want="torch>=2.4,<2.12.0"; [ "$gate" = open ] && want="torch>=2.13.0,<2.14.0" + want="torch>=2.4,<2.12.0"; tv="torchvision>=0.19,<0.27.0" + [ "$gate" = open ] && want="torch>=2.14.0,<2.15.0" && tv="torchvision>=0.29.0,<0.30.0" assert_eq "PyPI $gate: fresh home default" "$want" "$TORCH_CONSTRAINT" + assert_eq "PyPI $gate: fresh home torchvision" "$tv" "$TORCHVISION_CONSTRAINT" + _run_block true "2.14.1+cu130" + assert_eq "PyPI $gate: existing 2.14.1 kept" "torch==2.14.1" "$TORCH_CONSTRAINT" done UNSLOTH_TORCH_UPGRADE=1; _run_block true "2.11.0+cu130"; unset UNSLOTH_TORCH_UPGRADE -assert_eq "UNSLOTH_TORCH_UPGRADE=1 moves an existing home to 2.13" "torch>=2.13.0,<2.14.0" "$TORCH_CONSTRAINT" +assert_eq "UNSLOTH_TORCH_UPGRADE=1 moves an existing home to 2.14" "torch>=2.14.0,<2.15.0" "$TORCH_CONSTRAINT" +UNSLOTH_TORCH_UPGRADE=1; _run_block true "2.13.0+cu130"; unset UNSLOTH_TORCH_UPGRADE +assert_eq "UNSLOTH_TORCH_UPGRADE=1 moves a resident 2.13 to 2.14" "torch>=2.14.0,<2.15.0" "$TORCH_CONSTRAINT" PACKAGE_NAME="unsloth-fork"; _run_block false ""; PACKAGE_NAME="unsloth" assert_eq "--package other than unsloth: fresh home keeps the old default" "torch>=2.4,<2.12.0" "$TORCH_CONSTRAINT" assert_eq "--package other than unsloth: window still wide" "torch>=2.4,<2.15.0" "$_PRESERVE_TORCH_CONSTRAINT" PACKAGE_NAME="Unsloth"; _run_block false ""; PACKAGE_NAME="unsloth" -assert_eq "--package Unsloth is unsloth" "torch>=2.13.0,<2.14.0" "$TORCH_CONSTRAINT" +assert_eq "--package Unsloth is unsloth" "torch>=2.14.0,<2.15.0" "$TORCH_CONSTRAINT" for gate in unreachable capped; do case "$gate" in unreachable) export UNSLOTH_PYPI_JSON_URL="http://127.0.0.1:9/unreachable" ;; - capped) _pypi_fixture "torch<2.13.0,>=2.4.0" ;; + capped) _pypi_fixture "torch<2.14.0,>=2.4.0" ;; esac UNSLOTH_TORCH_UPGRADE=1 _run_block true "2.13.0+cu130" @@ -188,11 +214,12 @@ UNSLOTH_TORCH_UPGRADE=1 assert_eq "UNSLOTH_TORCH_UPGRADE=1 opts out" "" "$(_previous_torch_pin '2.11.0+cu130' "$PRESERVE")" unset UNSLOTH_TORCH_UPGRADE # The new-install spec must never be the preservation window: that would upgrade 2.11 users. -assert_eq "new-install spec alone would drop a kept 2.11" "" "$(_previous_torch_pin '2.11.0+cu130' 'torch>=2.13.0,<2.14.0')" +assert_eq "new-install spec alone would drop a kept 2.11" "" "$(_previous_torch_pin '2.11.0+cu130' "$_CU130_NEW_INSTALL_TORCH")" +assert_eq "new-install spec alone would drop a kept 2.13" "" "$(_previous_torch_pin '2.13.0+cu130' "$_CU130_NEW_INSTALL_TORCH")" assert_eq "kept pin is evaluated against the preservation window" "yes" \ "$(grep -q '_prev_pin=$(_previous_torch_pin "$_PREV_TORCH_VER" "$_PRESERVE_TORCH_CONSTRAINT")' "$INSTALL_SH" && echo yes)" -assert_eq "new-install spec is torch 2.13" "yes" \ - "$(grep -q '^_CU130_NEW_INSTALL_TORCH="torch>=2.13.0,<2.14.0"$' "$INSTALL_SH" && echo yes)" +assert_eq "new-install spec is torch 2.14" "yes" \ + "$(grep -q '^_CU130_NEW_INSTALL_TORCH="torch>=2.14.0,<2.15.0"$' "$INSTALL_SH" && echo yes)" echo "=== torchaudio pairing for a kept minor ===" assert_eq "2.10 -> 2.10" "torchaudio==2.10.*" "$(_torchaudio_for_torch_minor 10)" diff --git a/tests/studio/test_cu130_torch213_route.ps1 b/tests/studio/test_cu130_torch213_route.ps1 index dbd7ad7a407c..c44b61bd016a 100644 --- a/tests/studio/test_cu130_torch213_route.ps1 +++ b/tests/studio/test_cu130_torch213_route.ps1 @@ -1,7 +1,7 @@ #!/usr/bin/env pwsh # SPDX-License-Identifier: AGPL-3.0-only # Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0 -# install.ps1 gives new Windows x64 cu130 Python 3.13 installs torch 2.13 (the only route the +# install.ps1 gives new Windows x64 cu130 Python 3.13 installs torch 2.14 (the only route the # prebuilt-wheels-cu13 release covers) while an existing 2.4-2.14 install keeps its release. The # Windows port of tests/sh/test_cu130_torch213_route.sh. Helpers are extracted from install.ps1 by # AST; the interpreter, host arch, mirror check and PyPI fetch are stubs. @@ -34,6 +34,10 @@ foreach ($text in (Get-FunctionAsts $installPath @( } foreach ($text in (Get-FunctionAsts $setupPath @("Get-TritonWindowsSpec"))) { Invoke-Expression $text } $script:Cu130TorchCeiling = "2.15.0" +# The new-install specs come from install.ps1 itself, so a change there is what gets tested. +$_routeSpecs = [regex]::Matches((Get-Content -LiteralPath $installPath -Raw), '(?m)^\s*\$script:Cu130NewInstall(TorchSpec|VisionSpec|TorchFloor) = "[^"]*"\s*$') +if ($_routeSpecs.Count -ne 3) { throw "expected the three Cu130NewInstall assignments in install.ps1, found $($_routeSpecs.Count)" } +foreach ($m in $_routeSpecs) { Invoke-Expression $m.Value.Trim() } # Stubs. Functions shadow cmdlets, so Invoke-RestMethod here never reaches the network. $script:HostArch = "x86_64" @@ -139,6 +143,23 @@ try { Check ("requires_dist: " + $t.n) ((Test-RequiresDistAdmitsTorch -RequiresDist $t.r -Want "2.13.0") -eq $t.ok) } + Write-Host "=== new-install specs ===" + Check "new cu130 homes take torch 2.14" ($script:Cu130NewInstallTorchSpec -eq "torch>=2.14.0,<2.15.0") + Check "torch 2.14 pairs torchvision 0.29" ($script:Cu130NewInstallVisionSpec -eq "torchvision>=0.29.0,<0.30.0") + Check "the PyPI gate asks for the spec floor" ($script:Cu130NewInstallTorchFloor -eq "2.14.0") + Check "the route window still keeps every resident 2.14" ($script:Cu130TorchCeiling -eq "2.15.0") + Reset-Stubs + $script:RequiresDist = @("torch<2.14.0,>=2.4.0") + $r = Resolve-Cu130TorchRoute -IndexUrl $cu130 -PythonExe "py" -DefaultSpec $default -ExistingInstall $false + Check "a release capped below 2.14 keeps a new home on the default" ((-not $r.NewInstall) -and $r.PreserveSpec -eq "torch>=2.4,<2.15.0") + $script:RequiresDist = @("torch<2.15.0,>=2.4.0") + $r = Resolve-Cu130TorchRoute -IndexUrl $cu130 -PythonExe "py" -DefaultSpec $default -ExistingInstall $false + Check "a release admitting 2.14 moves a new home" ($r.NewInstall) + $installText = Get-Content -LiteralPath $installPath -Raw + Check "the gate asks PyPI for the spec floor, not 2.13" ( + $installText -match 'Test-PypiUnslothAdmitsTorch -Want \$script:Cu130NewInstallTorchFloor' -and + $installText -notmatch 'Test-PypiUnslothAdmitsTorch -Want "2\.13\.0"') + Write-Host "=== route decision ===" Reset-Stubs $r = Resolve-Cu130TorchRoute -IndexUrl $cu130 -PythonExe "py" -DefaultSpec $default -ExistingInstall $false @@ -217,7 +238,7 @@ try { $setup = Get-Content -LiteralPath $setupPath -Raw Check "the route is decided before preservation" ($install -match '(?s)Resolve-Cu130TorchRoute -IndexUrl \$TorchIndexUrl.*?\$_routeWindow = \$_preserveTorchSpec') Check "the route skips ROCm and --no-torch" ($install -match 'if \(-not \$SkipTorch -and -not \$ROCmIndexUrl\) \{\s*\$_cu130Route = Resolve-Cu130TorchRoute') - Check "2.13 applies only when nothing was kept" ($install -match '(?s)if \(-not \$script:PrevTorchPin -and \$_cu130NewInstallRoute\) \{\s*\$_pinTorchSpec = \$script:Cu130NewInstallTorchSpec\s*\$_pinVisionSpec = \$script:Cu130NewInstallVisionSpec') + Check "2.14 applies only when nothing was kept" ($install -match '(?s)if \(-not \$script:PrevTorchPin -and \$_cu130NewInstallRoute\) \{\s*\$_pinTorchSpec = \$script:Cu130NewInstallTorchSpec\s*\$_pinVisionSpec = \$script:Cu130NewInstallVisionSpec') Check "the generic CUDA install uses the hoisted specs" ($install -match '\$_torchSpecs = @\(\$_pinTorchSpec, \$_pinVisionSpec, \$_pinAudioSpec\)') Check "every earlier layout counts as an existing install" ( ([regex]::Matches($install, '\$script:ExistingInstall = \$true')).Count -eq 3)