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
Studio Windows repair hint: recommend Repair only where it reaches th…
…e managed torch

install.ps1 installs torch 2.13 only through the cu130 index on x64 with the Python 3.13 venv. Off that route there is no recommendation; a driver that does not support CUDA 13 gets a driver-update-first hint instead, since Repair alone would keep the old torch.

[skip ci]
  • Loading branch information
danielhanchen committed Nov 27, 2026
commit 7ceae54b34ace27eefb3ff5aaac93ec5ead34d89
39 changes: 39 additions & 0 deletions studio/backend/tests/test_windows_repair_recommendation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,54 @@ def _rec(
xformers = None,
caps = (RTX50,),
platform = "win32",
route_host = True,
driver = (13, 0),
):
versions = {"torch": torch, "xformers": xformers}
return wr.windows_repair_recommendation(
platform = platform,
dist_version = versions.get,
capabilities = lambda: dict(enumerate(caps)),
managed_route_host = lambda: route_host,
driver_cuda_version = lambda: driver,
)


def test_a_driver_too_old_for_the_managed_route_asks_for_a_driver_update_first():
# Repair alone would keep the cu128 torch, so the recommendation names the driver instead.
assert _rec(driver = (12, 8))["reason"] == "driver_older_than_managed"
assert _rec(driver = None)["reason"] == "torch_older_than_managed" # unknown driver: Repair


def test_a_host_off_the_managed_route_gets_no_recommendation():
# Windows on ARM, or a venv Python other than 3.13: Repair would not move torch.
assert _rec(route_host = False) is None


def test_the_driver_header_is_parsed_as_install_ps1_reads_it(monkeypatch):
from types import SimpleNamespace

from utils.hardware import gpu_query

header = "| NVIDIA-SMI 576.88 Driver Version: 576.88 CUDA Version: 12.9 |"
monkeypatch.setattr(gpu_query, "run_nvidia_smi", lambda *a, **k: SimpleNamespace(stdout = header))
wr._driver_cuda_version.cache_clear()
try:
assert wr._driver_cuda_version() == (12, 9)
finally:
wr._driver_cuda_version.cache_clear()


def test_the_route_gate_matches_install_ps1():
install = Path(__file__).resolve().parents[3] / "install.ps1"
body = re.search(
r"function Test-Cu130Torch213Platform \{.*?\n \}",
install.read_text(encoding = "utf-8"),
re.S,
).group(0)
assert '-ne "cu130"' in body and '-ne "x86_64"' in body and '"3.13 win-amd64"' in body


def test_an_old_torch_on_rtx50_recommends_repair():
rec = _rec()
assert rec["reason"] == "torch_older_than_managed"
Expand Down
43 changes: 42 additions & 1 deletion studio/backend/utils/hardware/windows_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from __future__ import annotations

import functools
import platform as _platform
import re
import sys
from typing import Callable, Optional
Expand All @@ -19,6 +21,8 @@
# The first xFormers whose sm_120 build ships the backward kernels, paired with that torch.
WINDOWS_MANAGED_XFORMERS_FLOOR = (0, 0, 35)
_SM120 = 12
# The managed torch comes from the cu130 index, which install.ps1 picks only for a driver supporting CUDA 13.0.
_MANAGED_ROUTE_DRIVER_CUDA = (13, 0)


def _dist_version(name: str) -> Optional[str]:
Expand All @@ -42,13 +46,44 @@ def _capabilities() -> dict:
return {}


@functools.lru_cache(maxsize = 1)
def _driver_cuda_version() -> Optional[tuple[int, int]]:
"""The CUDA version the driver supports, from nvidia-smi's header as install.ps1 reads it; None when
unreadable. Cached: the driver does not change under a running server."""
try:
from utils.hardware import gpu_query
from utils.hardware.nvidia import _nvidia_smi_executable

result = gpu_query.run_nvidia_smi(
[_nvidia_smi_executable()],
capture_output = True,
text = True,
encoding = "utf-8",
errors = "replace",
timeout = 5,
)
Comment on lines +66 to +70

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Hide the driver-probe subprocess on Windows

On a Windows desktop installation with an outdated torch/xFormers pair and an RTX 50-series GPU, the first /api/system request reaches this probe. Unlike get_compute_capabilities() in utils/hardware/nvidia.py, this invocation omits windows_hidden_subprocess_kwargs(), and gpu_query.run_nvidia_smi() forwards the arguments directly to subprocess.run without adding window-suppression flags. Because the desktop backend runs without a console, this creates a visible console window during an otherwise background status request. Pass the existing hidden-subprocess kwargs here as the other NVIDIA probes do.

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.

Fixed in df67a70: the probe now passes windows_hidden_subprocess_kwargs() and child_env_without_native_path_secret(), as nvidia.py's queries do; the parsing test asserts the hidden-window flags reach the call.

match = re.search(r"CUDA Version:\s*(\d+)\.(\d+)", result.stdout or "")
return (int(match.group(1)), int(match.group(2))) if match else None
except Exception: # noqa: BLE001 -- unknown driver
return None


def _managed_route_host() -> bool:
"""install.ps1's 2.13 route (Test-Cu130Torch213Platform): x64 Windows with the Python 3.13 venv."""
return _platform.machine().lower() in ("amd64", "x86_64") and sys.version_info[:2] == (3, 13)

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 Check the Python version Repair will select, not the running venv

On an x64 Windows installation still using Python 3.11 or 3.12, with an RTX 50-series GPU and a CUDA 13-capable driver, this suppresses the recommendation even though Repair can install the managed pair. The desktop installer sets UNSLOTH_TORCH_UPGRADE=1 (studio/src-tauri/src/install.rs), and install.ps1:1863–1870,6214–6226 consequently selects the default Python 3.13 rather than preserving the existing minor; it then replaces the current venv. Checking the running interpreter therefore excludes older homes that Repair would actually upgrade. Base eligibility on the interpreter Repair will select, while respecting an explicit Python override.

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.

Fixed in 8e2ada6: the route gate now uses the Python a Repair selects, UNSLOTH_PYTHON when set, else 3.13 (install.ps1 does not keep the existing minor under UNSLOTH_TORCH_UPGRADE=1), instead of the running interpreter. Covered by test_repair_builds_its_venv_with_the_python_install_ps1_selects.



def windows_repair_recommendation(
platform: str = sys.platform,
dist_version: Callable[[str], Optional[str]] = _dist_version,
capabilities: Callable[[], dict] = _capabilities,
managed_route_host: Callable[[], bool] = _managed_route_host,
driver_cuda_version: Callable[[], Optional[tuple[int, int]]] = _driver_cuda_version,
) -> Optional[dict]:
"""``{"reason", "torch", "xformers", "managed_torch", "managed_xformers"}`` when this Windows CUDA install
has an sm_120+ card and a torch (or an installed xFormers) older than the managed pair; else None."""
has an sm_120+ card and a torch (or an installed xFormers) older than the managed pair, and Repair can
reach that pair; else None. A driver too old for the cu130 route gets ``driver_older_than_managed``
instead, since Repair alone would keep the old torch."""
if platform != "win32":
return None
torch_version = dist_version("torch")
Expand All @@ -66,6 +101,12 @@ def windows_repair_recommendation(
reason = "xformers_older_than_managed"
else:
return None
# Only x64 with the Python 3.13 venv takes the managed torch; elsewhere Repair would not change it.
if not managed_route_host():
return None
driver = driver_cuda_version()
if driver is not None and driver < _MANAGED_ROUTE_DRIVER_CUDA:
reason = "driver_older_than_managed"
return {
"reason": reason,
"torch": torch_version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

/** `/api/system` `repair_recommendation`: an existing Windows home older than the managed torch / xFormers. */
export interface RepairRecommendation {
reason: "torch_older_than_managed" | "xformers_older_than_managed" | string;
reason:
| "torch_older_than_managed"
| "xformers_older_than_managed"
| "driver_older_than_managed"
| string;
torch?: string | null;
xformers?: string | null;
managed_torch?: string | null;
Expand All @@ -30,5 +34,8 @@ export function repairRecommendationText(
if (rec.reason === "xformers_older_than_managed") {
return t("settings.general.repairInstall.recommendedXformers" as never, values);
}
if (rec.reason === "driver_older_than_managed") {
return t("settings.general.repairInstall.recommendedDriver" as never, values);
}
return null;
}
2 changes: 2 additions & 0 deletions studio/frontend/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2456,6 +2456,8 @@ export const en = {
confirmAction: "Repair now",
recommendedTorch:
"Repair recommended: this install has PyTorch {torch}, older than the managed {managedTorch}. Training attention on RTX 50-series GPUs needs PyTorch {managedTorch} with xFormers {managedXformers}.",
recommendedDriver:
"PyTorch {torch} is older than the managed {managedTorch}, which training attention on RTX 50-series GPUs needs, but this GPU driver does not support CUDA 13. Update the GPU driver first, then repair the installation.",
recommendedXformers:
"Repair recommended: this install has xFormers {xformers}, older than the managed {managedXformers}, whose RTX 50-series build has the kernels training needs.",
},
Expand Down
9 changes: 9 additions & 0 deletions studio/frontend/tests/repair-recommendation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ test("an old xFormers on a current torch gets its own wording", () => {
assert.match(text ?? "", /xFormers 0\.0\.33, older than the managed 0\.0\.35/);
});

test("a driver too old for the managed route asks for a driver update first", () => {
const text = repairRecommendationText(
{ reason: "driver_older_than_managed", torch: "2.10.0+cu128", managed_torch: "2.13" },
t,
);
assert.match(text ?? "", /Update the GPU driver first, then repair/);
assert.doesNotMatch(text ?? "", /\{/);
});

test("nothing recommended, or an unknown reason, shows nothing", () => {
assert.equal(repairRecommendationText(null, t), null);
assert.equal(repairRecommendationText(undefined, t), null);
Expand Down