Repository navigation
Studio on Windows: recommend Repair when an existing home is older than the managed torch / xFormers #19870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+672
−0
Merged
Studio on Windows: recommend Repair when an existing home is older than the managed torch / xFormers #19870
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c49e733
Studio on Windows: recommend Repair when an existing home is older th…
danielhanchen 7ceae54
Studio Windows repair hint: recommend Repair only where it reaches th…
danielhanchen 8e2ada6
Studio Windows repair hint: judge the Python a Repair selects, not th…
danielhanchen fb89fd7
Studio Windows repair hint: an index override off cu130 closes the ma…
danielhanchen df67a70
Studio Windows repair hint: launch the driver probe like the other nv…
danielhanchen 1aceba7
Studio Windows repair hint: never recommend the managed xFormers on i…
danielhanchen 03c5e73
Studio Windows repair hint: read the driver's CUDA version from eithe…
danielhanchen 5a046a6
Studio Windows repair hint: a package mirror or offline uv closes the…
danielhanchen c55eba0
Studio Windows repair hint: read uv config files in install.ps1's pre…
danielhanchen 24cbe58
Studio Windows repair hint: include the project config UV_PROJECT sel…
danielhanchen 339128d
Merge remote-tracking branch 'origin/main' into g103-studio-repair-hint
danielhanchen 84ee157
Repair hint: start uv config discovery from UV_WORKING_DIR as install…
danielhanchen 5e4e149
Repair hint: walk uv config discovery from Desktop's installer directory
danielhanchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Studio on Windows: recommend Repair when an existing home is older th…
…an the managed torch / xFormers An existing home keeps the torch it was installed with; only Repair moves it to the managed build. On RTX 50-series cards xFormers trains only with torch 2.13 and xFormers 0.0.35, so /api/system now reports repair_recommendation (torch-free: package metadata and the cached nvidia-smi capability query) for a Windows CUDA install with an sm_120+ card and an older torch or xFormers, and the Desktop Repair row shows a 'Repair recommended' line under it.
- Loading branch information
commit c49e733cf2c48da458fee9a67715537ea5efa390
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
studio/backend/tests/test_windows_repair_recommendation.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # SPDX-License-Identifier: AGPL-3.0-only | ||
| # Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0 | ||
|
|
||
| """An existing Windows home on an RTX 50-series card gets a Repair recommendation when its torch or | ||
| xFormers is older than the managed pair.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from utils.hardware import windows_repair as wr | ||
|
|
||
| RTX50, RTX40 = (12, 0), (8, 9) | ||
|
|
||
|
|
||
| def _rec( | ||
| torch = "2.10.0+cu128", | ||
| xformers = None, | ||
| caps = (RTX50,), | ||
| platform = "win32", | ||
| ): | ||
| versions = {"torch": torch, "xformers": xformers} | ||
| return wr.windows_repair_recommendation( | ||
| platform = platform, | ||
| dist_version = versions.get, | ||
| capabilities = lambda: dict(enumerate(caps)), | ||
| ) | ||
|
|
||
|
|
||
| def test_an_old_torch_on_rtx50_recommends_repair(): | ||
| rec = _rec() | ||
| assert rec["reason"] == "torch_older_than_managed" | ||
| assert rec["torch"] == "2.10.0+cu128" | ||
| assert (rec["managed_torch"], rec["managed_xformers"]) == ("2.13", "0.0.35") | ||
|
|
||
|
|
||
| def test_an_old_xformers_on_the_managed_torch_recommends_repair(): | ||
| assert _rec(torch = "2.13.0+cu130", xformers = "0.0.33")["reason"] == "xformers_older_than_managed" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "kwargs", | ||
| [ | ||
| dict(torch = "2.13.0+cu130", xformers = "0.0.35"), # the managed pair | ||
| dict(torch = "2.14.0+cu134"), # newer, no xFormers | ||
| dict(caps = (RTX40,)), # older cards train fine on this torch | ||
| dict(caps = ()), # no readable card | ||
| dict(torch = "2.10.0+cpu"), # a CPU wheel is a different repair | ||
| dict(torch = None), # no torch (Chat only) | ||
| dict(platform = "linux"), | ||
| dict(platform = "darwin"), | ||
| ], | ||
| ) | ||
| def test_nothing_is_recommended_otherwise(kwargs): | ||
| assert _rec(**kwargs) is None | ||
|
|
||
|
|
||
| def test_a_mixed_host_answers_for_its_rtx50_card(): | ||
| assert _rec(caps = (RTX40, RTX50))["reason"] == "torch_older_than_managed" | ||
|
|
||
|
|
||
| def test_the_floor_matches_install_ps1(): | ||
| """The managed torch floor is install.ps1's new-install CUDA spec; bumping one must bump the other.""" | ||
| install = Path(__file__).resolve().parents[3] / "install.ps1" | ||
| spec = re.search( | ||
| r'\$script:Cu130NewInstallTorchSpec = "torch>=(\d+)\.(\d+)', | ||
| install.read_text(encoding = "utf-8"), | ||
| ) | ||
| assert spec, "Cu130NewInstallTorchSpec not found in install.ps1" | ||
| assert (int(spec.group(1)), int(spec.group(2))) == wr.WINDOWS_MANAGED_TORCH_FLOOR | ||
|
|
||
|
|
||
| def test_system_route_ships_the_recommendation(monkeypatch): | ||
| import main | ||
|
|
||
| monkeypatch.setattr( | ||
| wr, "windows_repair_recommendation", lambda: {"reason": "torch_older_than_managed"} | ||
| ) | ||
| assert main._repair_recommendation() == {"reason": "torch_older_than_managed"} | ||
|
|
||
| def boom(): | ||
| raise RuntimeError("probe failed") | ||
|
|
||
| monkeypatch.setattr(wr, "windows_repair_recommendation", boom) | ||
| assert main._repair_recommendation() is None | ||
| src = Path(main.__file__).read_text(encoding = "utf-8") | ||
| assert '"repair_recommendation": _repair_recommendation(),' in src | ||
|
|
||
|
|
||
| def test_the_module_stays_torch_free(): | ||
| src = Path(wr.__file__).read_text(encoding = "utf-8") | ||
| assert "import torch" not in src |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # SPDX-License-Identifier: AGPL-3.0-only | ||
| # Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0 | ||
|
|
||
| """Windows: whether an existing install should be repaired onto the managed PyTorch. | ||
|
|
||
| An existing home keeps the torch it was installed with; only a repair (UNSLOTH_TORCH_UPGRADE=1) moves it to | ||
| the managed build. On RTX 50-series (sm_120) cards xFormers trains only with torch 2.13 and xFormers 0.0.35, | ||
| so an older home there runs attention on SDPA instead, or fails in the backward of an old xFormers build. | ||
| Torch-free: package metadata and the cached nvidia-smi capability query, so the polled /api/system may call it.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| import sys | ||
| from typing import Callable, Optional | ||
|
|
||
| # Lower bound of install.ps1's managed CUDA torch for new installs ($script:Cu130NewInstallTorchSpec). | ||
| WINDOWS_MANAGED_TORCH_FLOOR = (2, 13) | ||
| # The first xFormers whose sm_120 build ships the backward kernels, paired with that torch. | ||
| WINDOWS_MANAGED_XFORMERS_FLOOR = (0, 0, 35) | ||
| _SM120 = 12 | ||
|
|
||
|
|
||
| def _dist_version(name: str) -> Optional[str]: | ||
| try: | ||
| from importlib.metadata import version | ||
| return version(name) | ||
| except Exception: # noqa: BLE001 -- not installed or unreadable | ||
| return None | ||
|
|
||
|
|
||
| def _release(version: Optional[str]) -> Optional[tuple[int, ...]]: | ||
| match = re.match(r"(\d+(?:\.\d+)*)", version or "") | ||
| return tuple(int(p) for p in match.group(1).split(".")) if match else None | ||
|
|
||
|
|
||
| def _capabilities() -> dict: | ||
| try: | ||
| from utils.hardware.nvidia import get_compute_capabilities | ||
| return get_compute_capabilities() | ||
| except Exception: # noqa: BLE001 -- unreadable counts as no card | ||
| return {} | ||
|
|
||
|
|
||
| def windows_repair_recommendation( | ||
| platform: str = sys.platform, | ||
| dist_version: Callable[[str], Optional[str]] = _dist_version, | ||
| capabilities: Callable[[], dict] = _capabilities, | ||
| ) -> 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.""" | ||
| if platform != "win32": | ||
| return None | ||
| torch_version = dist_version("torch") | ||
| # Only CUDA builds: a CPU wheel is a different repair (the GPU verdict already says so). | ||
| if not torch_version or "+cu" not in torch_version: | ||
| return None | ||
| if not any(int(cap[0]) >= _SM120 for cap in capabilities().values()): | ||
| return None | ||
| torch_release = _release(torch_version) | ||
| xformers_version = dist_version("xformers") | ||
| xformers_release = _release(xformers_version) | ||
| if torch_release is not None and torch_release[:2] < WINDOWS_MANAGED_TORCH_FLOOR: | ||
| reason = "torch_older_than_managed" | ||
| elif xformers_release is not None and xformers_release < WINDOWS_MANAGED_XFORMERS_FLOOR: | ||
| reason = "xformers_older_than_managed" | ||
| else: | ||
| return None | ||
| return { | ||
| "reason": reason, | ||
| "torch": torch_version, | ||
| "xformers": xformers_version, | ||
| "managed_torch": ".".join(map(str, WINDOWS_MANAGED_TORCH_FLOOR)), | ||
| "managed_xformers": ".".join(map(str, WINDOWS_MANAGED_XFORMERS_FLOOR)), | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
studio/frontend/src/features/settings/components/repair-recommendation.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-only | ||
| // Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0 | ||
|
|
||
| /** `/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; | ||
| torch?: string | null; | ||
| xformers?: string | null; | ||
| managed_torch?: string | null; | ||
| managed_xformers?: string | null; | ||
| } | ||
|
|
||
| type Translate = (key: never, values?: Record<string, string>) => string; | ||
|
|
||
| /** The hint under the Repair row, or null when nothing is recommended or the reason is unknown. */ | ||
| export function repairRecommendationText( | ||
| rec: RepairRecommendation | null | undefined, | ||
| t: Translate, | ||
| ): string | null { | ||
| if (!rec) return null; | ||
| const values = { | ||
| torch: rec.torch ?? "", | ||
| xformers: rec.xformers ?? "", | ||
| managedTorch: rec.managed_torch ?? "", | ||
| managedXformers: rec.managed_xformers ?? "", | ||
| }; | ||
| if (rec.reason === "torch_older_than_managed") { | ||
| return t("settings.general.repairInstall.recommendedTorch" as never, values); | ||
| } | ||
| if (rec.reason === "xformers_older_than_managed") { | ||
| return t("settings.general.repairInstall.recommendedXformers" as never, values); | ||
| } | ||
| return null; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-only | ||
| // Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0 | ||
|
|
||
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
|
|
||
| import { readSrcAsync, registerBundlerResolver } from "./helpers/kit.ts"; | ||
|
|
||
| registerBundlerResolver(); | ||
|
|
||
| const { repairRecommendationText } = await import( | ||
| "../src/features/settings/components/repair-recommendation.ts" | ||
| ); | ||
| const { en } = await import("../src/i18n/locales/en.ts"); | ||
|
|
||
| const strings = en.settings.general.repairInstall as Record<string, string>; | ||
| const t = (key: never, values: Record<string, string> = {}) => { | ||
| const leaf = String(key).split(".").pop() as string; | ||
| return strings[leaf].replace(/\{(\w+)\}/g, (_m, name: string) => values[name] ?? `{${name}}`); | ||
| }; | ||
|
|
||
| test("an old torch names both versions and the managed pair", () => { | ||
| const text = repairRecommendationText( | ||
| { | ||
| reason: "torch_older_than_managed", | ||
| torch: "2.10.0+cu128", | ||
| xformers: "0.0.33", | ||
| managed_torch: "2.13", | ||
| managed_xformers: "0.0.35", | ||
| }, | ||
| t, | ||
| ); | ||
| assert.ok(text?.startsWith("Repair recommended:"), text ?? "null"); | ||
| assert.match(text, /PyTorch 2\.10\.0\+cu128/); | ||
| assert.match(text, /xFormers 0\.0\.35/); | ||
| assert.doesNotMatch(text, /\{/); | ||
| }); | ||
|
|
||
| test("an old xFormers on a current torch gets its own wording", () => { | ||
| const text = repairRecommendationText( | ||
| { reason: "xformers_older_than_managed", torch: "2.13.0+cu130", xformers: "0.0.33", managed_xformers: "0.0.35" }, | ||
| t, | ||
| ); | ||
| assert.match(text ?? "", /xFormers 0\.0\.33, older than the managed 0\.0\.35/); | ||
| }); | ||
|
|
||
| test("nothing recommended, or an unknown reason, shows nothing", () => { | ||
| assert.equal(repairRecommendationText(null, t), null); | ||
| assert.equal(repairRecommendationText(undefined, t), null); | ||
| assert.equal(repairRecommendationText({ reason: "something_new" }, t), null); | ||
| }); | ||
|
|
||
| test("the Repair row renders the hint below it", async () => { | ||
| const src = await readSrcAsync("features/settings/components/desktop-repair-control.tsx"); | ||
| assert.match(src, /repairRecommendationText\(system\.repair_recommendation, t\)/); | ||
| assert.match(src, /below=\{/); | ||
| // The hook runs before the early return, so hook order never changes. | ||
| assert.ok(src.indexOf("useSystemInfo(") < src.indexOf("if (!repair || repair.isExternalServer) return null;")); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On an RTX 50-series Windows host whose driver reports CUDA 12.8, this recommends Repair even though Repair cannot install the advertised PyTorch 2.13. In
install.ps1, driver-based selection choosescu128(lines 9717–9718), whereasTest-Cu130Torch213Platformallows the 2.13 route only forcu130with Python 3.13 (lines 9950–9960); otherwise the installer retains its defaulttorch>=2.4,<2.12.0constraint. Consequently, even a successfully repaired installation keeps showing this recommendation, sending users through a lengthy reinstall without resolving it. Check the managed route's prerequisites before recommending Repair, or explain the required driver upgrade instead.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 7ceae54: the recommendation now follows
Test-Cu130Torch213Platform. Off x64 with the Python 3.13 venv there is none. When the driver (nvidia-smi header, read as install.ps1 reads it) does not support CUDA 13, the reason isdriver_older_than_managedand the hint asks for a driver update first, then Repair. An unreadable driver still recommends Repair. Covered bytest_a_driver_too_old_for_the_managed_route_asks_for_a_driver_update_first,test_a_host_off_the_managed_route_gets_no_recommendation, and a test that the gate matchesinstall.ps1.