Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio installer (Windows): avoid unavailable CUDA torchao wheels (#16016)
oobabooga8b974d6d1844
diff --git a/studio/backend/tests/test_torchao_select.py b/studio/backend/tests/test_torchao_select.pyindex 4f46a21c5f6..93f100a7fe9 100644--- a/studio/backend/tests/test_torchao_select.py+++ b/studio/backend/tests/test_torchao_select.py@@ -96,6 +96,7 @@ def test_an_old_torch_install_on_torchao_014_is_repinned(monkeypatch, installed)"""An existing torch <= 2.8 install keeps torchao 0.14 until its next dependency pass, whichmust force 0.15.0 over it even when the pass has evidence to skip satisfied steps."""mod = _load_module(monkeypatch)+ monkeypatch.setattr(mod, "IS_WINDOWS", False)monkeypatch.setattr(mod, "_installed_distribution_version", lambda _name: installed)monkeypatch.setattr(mod, "_may_skip_on_evidence", lambda: True)calls = []@@ -197,7 +198,7 @@ def _torchao_installer_source():def test_the_torchao_step_pins_the_index_and_retries_without_it():"""a lagging accelerator leaf retries the default index, but failure there remains fatal."""body = _torchao_installer_source()- assert "index = None if default_index else _torch_accelerator_index_url(torch_version)" in body+ assert "index = None if default_index else _torchao_index_url(torch_version)" in bodyassert '"--index-url", index, spec' in bodyassert "retrying from the default index" in body# The unpinned attempt is pip_install, not pip_install_try: still fatal on failure.@@ -269,6 +270,69 @@ def test_the_wanted_tag_follows_the_index_that_will_be_pinned(monkeypatch):assert mod._torch_index_tag("2.13.0+cu128") == "cu128"+_PYTORCH_WHL = "https://download.pytorch.org/whl"+_MIRROR_WHL = "https://mirror.example/whl"+++ "is_windows, torch_version, family, url, base, expected",+ [+ (True, "2.13.0+cu130", "", "", _PYTORCH_WHL, None),+ (True, "2.12.0+cu126", "", "", _PYTORCH_WHL, None),+ (True, "2.10.0+cu128", "", "", _PYTORCH_WHL, None),+ (True, "2.13.0+cu128", "cu130", "", _PYTORCH_WHL, None),+ # The cpu and xpu leaves serve Windows a py3-none-any wheel.+ (True, "2.12.0+cpu", "", "", _PYTORCH_WHL, f"{_PYTORCH_WHL}/cpu"),+ (True, "2.14.0+xpu", "", "", _PYTORCH_WHL, f"{_PYTORCH_WHL}/xpu"),+ (True, "2.13.0+cu130", "cpu", "", _PYTORCH_WHL, f"{_PYTORCH_WHL}/cpu"),+ (True, "2.13.0", "", "", _PYTORCH_WHL, None),+ # Mirrors and explicit indexes stay pinned.+ (True, "2.13.0+cu130", "", "", _MIRROR_WHL, f"{_MIRROR_WHL}/cu130"),+ (True, "2.13.0+cu130", "", f"{_MIRROR_WHL}/cu130", _PYTORCH_WHL, f"{_MIRROR_WHL}/cu130"),+ # Not a CUDA leaf, though it starts with "cu".+ (True, "2.13.0+cu130", "current", "", _PYTORCH_WHL, f"{_PYTORCH_WHL}/current"),+ (False, "2.13.0+cu130", "", "", _PYTORCH_WHL, f"{_PYTORCH_WHL}/cu130"),+ (False, "2.12.0+cu126", "", "", _PYTORCH_WHL, f"{_PYTORCH_WHL}/cu126"),+ ],+)+def test_windows_cuda_takes_torchao_unpinned(+ monkeypatch, is_windows, torch_version, family, url, base, expected+):+ mod = _load_module(monkeypatch)+ monkeypatch.setattr(mod, "IS_WINDOWS", is_windows)+ monkeypatch.setattr(mod, "_PYTORCH_WHL_BASE", base)+ monkeypatch.setenv("UNSLOTH_TORCH_INDEX_FAMILY", family)+ monkeypatch.setenv("UNSLOTH_TORCH_INDEX_URL", url)+ assert mod._torchao_index_url(torch_version) == expected+++def test_a_windows_cuda_update_leaves_the_installed_torchao_alone(monkeypatch):+ """The untagged wheel the first run installs must satisfy the next run's tag check."""+ mod = _load_module(monkeypatch)+ monkeypatch.setattr(mod, "IS_WINDOWS", True)+ monkeypatch.delenv("UNSLOTH_TORCH_INDEX_URL", raising = False)+ monkeypatch.delenv("UNSLOTH_TORCH_INDEX_FAMILY", raising = False)+ monkeypatch.delenv(mod._FULL_DEPS_ENV, raising = False)+ notes: list[str] = []+ calls: list[tuple] = []+ monkeypatch.setattr(mod, "_note", notes.append)+ monkeypatch.setattr(mod, "pip_install", lambda *a, **k: calls.append(a))+ monkeypatch.setattr(mod, "pip_install_try", lambda *a, **k: calls.append(a) or True)++ installed = {"torchao": None}+ monkeypatch.setattr(mod, "_installed_distribution_version", lambda n: installed.get(n))+ monkeypatch.setattr(mod, "_PASS_EVIDENCE", None)+ mod._install_torchao_for_torch("2.13.0+cu130")+ assert len(calls) == 1 and "--index-url" not in calls[0], calls+ assert not any("did not serve" in n for n in notes), notes++ installed["torchao"] = "0.18.0"+ monkeypatch.setattr(mod, "_PASS_EVIDENCE", {"pass_inputs": {}, "step_results": {}})+ mod._install_torchao_for_torch("2.13.0+cu130")+ assert len(calls) == 1, calls+ assert mod._STEP_RESULTS.get("torchao") == "skipped"++def test_every_torchao_call_site_asks_for_the_pinned_tag():"""Passing the torch version rather than the pinned tag would reintroduce the drift thehelper exists to remove, so no call site may spell it any other way."""@@ -276,6 +340,7 @@ def test_every_torchao_call_site_asks_for_the_pinned_tag():assert source.count("_pin_needs_reinstall(") == 3 # the def plus both call sitesassert '_torch_index_tag(torch_version) if index else ""' in sourceassert '_torch_index_tag(_label_after) if _ao_index else ""' in source+ assert "_ao_index = _torchao_index_url(_label_after)" in sourcedef test_no_torchao_install_can_resolve_a_dependency():diff --git a/studio/install_python_stack.py b/studio/install_python_stack.pyindex c0d41032c4d..99fe163e7f2 100644--- a/studio/install_python_stack.py+++ b/studio/install_python_stack.py@@ -1094,6 +1094,17 @@ def _torchcodec_index_url(torch_version: "str | None", spec: str = "") -> "str |return _torch_accelerator_index_url(torch_version, _TORCHCODEC_INDEX_TAGS)+def _torchao_index_url(torch_version: "str | None") -> "str | None":+ """_torch_accelerator_index_url, but None on Windows for download.pytorch.org's cuNNN leaves:+ they serve torchao for Linux only, so the pin always fails and the untagged fallback then+ fails every later update's tag check. Mirrors, explicit indexes and cpu/xpu stay pinned."""+ url = _torch_accelerator_index_url(torch_version)+ tag = _torch_index_tag(torch_version)+ if IS_WINDOWS and tag and _is_cuda_family_leaf(tag) and url == f"{_PYTORCH_DEFAULT_WHL}/{tag}":+ return None+ return url++def _torch_index_tag(torch_version: "str | None", substitutions: "dict[str, str] | None" = None) -> "str | None":@@ -5434,7 +5445,7 @@ def _install_torchao_for_torch(torch_version: "str | None", default_index: bool"""spec = _select_torchao_spec(torch_version)# See _TORCHAO_DEFAULT_SPEC. Unlike torchcodec, rocm leaves do publish torchao.- index = None if default_index else _torch_accelerator_index_url(torch_version)+ index = None if default_index else _torchao_index_url(torch_version)# --no-deps guards the second caller, which runs right after the torch repair.args = ["--no-deps", "--no-cache-dir"]needs_reinstall = _pin_needs_reinstall(spec, _torch_index_tag(torch_version) if index else "")@@ -5498,7 +5509,7 @@ def _resync_torch_coupled_packages(label_before: str) -> bool:try:_spec = _select_torchao_spec(_label_after)# Same pin as step 4, or PyPI's build lands over it; ==0.18.0 never equals 0.18.0+cu130.- _ao_index = _torch_accelerator_index_url(_label_after)+ _ao_index = _torchao_index_url(_label_after)_ao_args = ["--force-reinstall", "--no-deps", "--no-cache-dir"]if _pin_needs_reinstall(_spec, _torch_index_tag(_label_after) if _ao_index else ""):_note(f"torch {_label_after} after repair -- reinstalling {_spec}")diff --git a/tests/studio/install/test_cuda_repair.py b/tests/studio/install/test_cuda_repair.pyindex 375686edb18..09424f2eb1f 100644--- a/tests/studio/install/test_cuda_repair.py+++ b/tests/studio/install/test_cuda_repair.py@@ -1600,6 +1600,7 @@ class TestThePackagesTiedToTheTorchReleaseAreResettled:resident_xformers = None,installed_spec = False,torchao_install_fails = False,+ is_windows = False,):calls = {"torchao": [], "removed": []}@@ -1609,6 +1610,7 @@ class TestThePackagesTiedToTheTorchReleaseAreResettled:return not torchao_install_failswith (+ patch.object(stack_mod, "IS_WINDOWS", is_windows),patch.object(stack_mod, "_probe_installed_torch_version", return_value = after),# "Already matching" means the exact wheel the pin would fetch, local tag included.patch.object(@@ -1664,6 +1666,10 @@ class TestThePackagesTiedToTheTorchReleaseAreResettled:assert calls["torchao"], "the leaf moved, so the pinned build has to be re-selected"assert any("cu128" in " ".join(c) for c in calls["torchao"]), calls["torchao"]+ def test_windows_re_selects_torchao_unpinned(self):+ calls = self._resync("2.10.0+cu124", "2.10.0+cu130", is_windows = True)+ assert calls["torchao"] and not any("--index-url" in c for c in calls["torchao"])+def test_a_cpu_to_xpu_move_re_pins_torchao(self):"""Neither side names a CUDA major, so None == None skipped the resync entirely."""calls = self._resync("2.10.0+cpu", "2.10.0+xpu")