diff --git a/pyproject.toml b/pyproject.toml index f60e42a07a5f..93fd8df9394b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,9 +28,10 @@ dependencies = [ "unsloth_zoo>=2026.9.8", "wheel>=0.42.0", "packaging", - # Ceiling tracks the newest torch an extra pins: the cu126/cu130-torch212x leaves - # ask for 2.12.x, which a <2.12.0 base made unresolvable against itself. - "torch>=2.4.0,<2.13.0", + # Ceiling tracks the newest torch an extra pins: the cu126/cu130-torch2140 leaves ask + # for 2.14.0, and Studio installs torch 2.13 on the cu130 route, which a <2.13.0 base + # would downgrade on the next `unsloth studio update`. + "torch>=2.4.0,<2.15.0", "torchvision", "numpy", "tqdm", diff --git a/tests/test_released_torch_ceiling.py b/tests/test_released_torch_ceiling.py new file mode 100644 index 000000000000..3a26ca657875 --- /dev/null +++ b/tests/test_released_torch_ceiling.py @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: AGPL-3.0-only +# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. + +"""The released torch range must admit what Studio installs and every torch an extra pins. + +`unsloth studio update` re-resolves unsloth under this range: an installed torch outside it +is swapped for PyPI's default on the next update. Studio installs torch 2.13 on the Linux +cu130 Python 3.13 route once this range admits it. +""" + +import sys +from pathlib import Path + +import pytest +from packaging.requirements import Requirement +from packaging.version import Version + +tomllib = pytest.importorskip("tomllib" if sys.version_info >= (3, 11) else "tomli") + +_PYPROJECT = tomllib.loads( + (Path(__file__).resolve().parents[1] / "pyproject.toml").read_text(encoding = "utf-8") +) + + +def _base_torch() -> Requirement: + reqs = [Requirement(r) for r in _PYPROJECT["project"]["dependencies"]] + torch = [r for r in reqs if r.name == "torch"] + assert len(torch) == 1, torch + return torch[0] + + +@pytest.mark.parametrize("release", ["2.4.0", "2.11.0", "2.12.1", "2.13.0", "2.14.0"]) +def test_the_released_range_admits_every_supported_torch(release): + assert Version(release) in _base_torch().specifier + + +def test_the_released_range_stops_before_an_unvalidated_minor(): + assert Version("2.15.0") not in _base_torch().specifier + + +def test_every_torch_an_extra_pins_is_inside_the_released_range(): + spec = _base_torch().specifier + pinned = set() + for extra in _PYPROJECT["project"].get("optional-dependencies", {}).values(): + for raw in extra: + req = Requirement(raw) + if req.name != "torch" or req.url: + continue + for s in req.specifier: + if s.operator == "==": + pinned.add(Version(s.version.split("+", 1)[0])) + outside = sorted(str(v) for v in pinned if v not in spec) + assert not outside, f"extras pin torch outside the released range: {outside}"