Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Skip the core-update torch freeze when the override path cannot be ma…
…de space-free; match --package unsloth case-insensitively in install.sh
  • Loading branch information
danielhanchen committed Oct 11, 2026
commit aad4e37b9adaff3d6ff71ef172ca9f3e466f156e
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7239,7 +7239,7 @@ if [ "$SKIP_TORCH" = false ] && [ "$(_cu130_torch213_platform "$TORCH_INDEX_URL"
_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.
# The PyPI check reads unsloth's metadata, so a --package other than unsloth keeps the default.
if [ "$PACKAGE_NAME" = "unsloth" ] \
if [ "$(printf '%s' "$PACKAGE_NAME" | tr '[:upper:]' '[:lower:]')" = "unsloth" ] \
&& { [ "$_EXISTING_INSTALL" = false ] || [ "${UNSLOTH_TORCH_UPGRADE:-0}" = "1" ]; } \
&& [ "$(_pypi_unsloth_admits_torch "2.13.0")" = "yes" ]; then
_CU130_NEW_INSTALL_ROUTE=true
Expand Down
20 changes: 20 additions & 0 deletions studio/backend/tests/test_cu130_repair_torch_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,26 @@ def test_core_update_freeze_restores_an_unset_override(monkeypatch, mod):
assert "UV_OVERRIDE" not in mod.os.environ


def test_core_update_freeze_stands_down_without_a_space_free_override_path(
monkeypatch, tmp_path, mod
):
monkeypatch.setattr(mod.sys, "platform", "win32")
monkeypatch.setattr(mod, "_is_windows_arm64", lambda: False)
monkeypatch.setattr(mod, "_resident_torch_release", lambda: "2.13.0")
monkeypatch.setattr(mod, "_resident_torch_trio_pins", lambda: ["torch==2.13.0+cu130"])
spaced = tmp_path / "John Smith"
spaced.mkdir()
monkeypatch.setattr(mod.tempfile, "tempdir", str(spaced))
# No 8.3 short name: uv_safe_path hands the spaced path back.
monkeypatch.setattr(mod, "_uv_safe_path", lambda path: str(path))
monkeypatch.delenv("UV_OVERRIDE", raising = False)
with mod._FreezeNewTorchForCoreUpdate() as freeze:
assert "UV_OVERRIDE" not in mod.os.environ
assert mod._TORCH_FREEZE_ACTIVE is False
assert freeze._path is None
assert list(spaced.iterdir()) == []


def test_both_core_updates_run_under_the_freeze():
source = _INSTALL_SCRIPT.read_text(encoding = "utf-8")
assert (
Expand Down
8 changes: 7 additions & 1 deletion studio/install_python_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,14 @@ def __enter__(self):
fd, name = tempfile.mkstemp(prefix = "unsloth-torch-overrides-", suffix = ".txt")
with os.fdopen(fd, "w", encoding = "utf-8") as handle:
handle.write("\n".join(lines) + "\n")
safe = _uv_safe_path(name)
if any(ch.isspace() for ch in safe):
# uv splits UV_OVERRIDE on whitespace: with no short name for a spaced %TEMP% the
# file cannot be named, so resolve unfrozen as before rather than fail the update.
Path(name).unlink(missing_ok = True)
return self
self._path = Path(name)
os.environ["UV_OVERRIDE"] = _uv_safe_path(self._path)
os.environ["UV_OVERRIDE"] = safe
global _TORCH_FREEZE_ACTIVE
_TORCH_FREEZE_ACTIVE = True
return self
Expand Down
2 changes: 2 additions & 0 deletions tests/sh/test_cu130_torch213_route.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ assert_eq "UNSLOTH_TORCH_UPGRADE=1 moves an existing home to 2.13" "torch>=2.13.
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"
for gate in unreachable capped; do
case "$gate" in
unreachable) export UNSLOTH_PYPI_JSON_URL="http://127.0.0.1:9/unreachable" ;;
Expand Down