Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
53 changes: 53 additions & 0 deletions tests/test_released_torch_ceiling.py
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +32 to +34

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 Add the torch ceiling guard to a CI test command

This new module is not executed by the current CI configuration: pyproject.toml:1203 restricts default discovery to tests/security, while the root-test commands in .github/workflows/consolidated-tests-ci.yml explicitly enumerate other modules and never name this file. Consequently, a later change can violate the torch ceiling or extra-pin invariants while CI remains green; add this module to an appropriate explicit pytest invocation.

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.

This module already runs in CI: studio-backend-ci.yml's Repo tests (CPU, rest) shard walks tests/ minus the named subtrees, and collecting that selection picks up all 7 tests here (it is also the job that flagged this file's encoding earlier).



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}"
Loading