Skip to content

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.

Studio/CLI: report Rosetta, skip audio.cpp CUDA on pre-Turing GPUs, pass doctor on MPS/XPU, hide XPU from token preview (#14374)

Daniel Han0c817e5a6c97
diff --git a/studio/backend/core/training/token_preview.py b/studio/backend/core/training/token_preview.py
index 81eff505411..e0309e3f89a 100644
--- a/studio/backend/core/training/token_preview.py
+++ b/studio/backend/core/training/token_preview.py
@@ -27,9 +27,11 @@ FIRST_REQUEST_TIMEOUT_S = 300.0
REQUEST_TIMEOUT_S = 60.0
# Applied in the child before anything imports torch: a CUDA context alone costs hundreds of MB of
# VRAM, and the preview only tokenizes. UNSLOTH_ALLOW_CPU lets Unsloth's chat templates import there.
+# torch-xpu: an empty ZE_AFFINITY_MASK means every device, so hide Level Zero via the SYCL selector.
_NO_ACCELERATOR_ENV = {
"CUDA_VISIBLE_DEVICES": "",
"HIP_VISIBLE_DEVICES": "",
+ "ONEAPI_DEVICE_SELECTOR": "opencl:cpu",
"UNSLOTH_ALLOW_CPU": "1",
}
diff --git a/studio/backend/tests/test_chat_only_reason.py b/studio/backend/tests/test_chat_only_reason.py
index cc5065cc427..fa919ff46ef 100644
--- a/studio/backend/tests/test_chat_only_reason.py
+++ b/studio/backend/tests/test_chat_only_reason.py
@@ -12,6 +12,7 @@ reinstall/update dropped MLX.
from __future__ import annotations
import sys
+import types
from pathlib import Path
import pytest
@@ -178,6 +179,8 @@ def test_apple_silicon_no_torch_install_with_usable_mlx_enables_training(monkeyp
def test_intel_mac_reason(monkeypatch):
monkeypatch.setattr(hw, "is_apple_silicon", lambda: False)
+ # Pinned: a translated (Rosetta) test Python would otherwise answer "rosetta".
+ monkeypatch.setattr(hw, "_running_under_rosetta", lambda: False)
monkeypatch.setattr(hw, "_has_mlx", lambda: False)
monkeypatch.setattr(hw.platform, "system", lambda: "Darwin")
hw.detect_hardware()
@@ -185,6 +188,62 @@ def test_intel_mac_reason(monkeypatch):
assert hw.CHAT_ONLY_REASON == "intel_mac"
+def _fake_sysctl(arm64: str, calls: list):
+ def run(cmd, *args, **kwargs):
+ calls.append(cmd)
+ return types.SimpleNamespace(returncode = 0, stdout = arm64 + "\n", stderr = "")
+
+ return run
+
+
+ "machine, arm64, expected",
+ [
+ ("x86_64", "1", "rosetta"),
+ ("x86_64", "0", "intel_mac"),
+ ],
+)
+def test_rosetta_reason(monkeypatch, machine, arm64, expected):
+ calls = []
+ monkeypatch.setattr(hw, "_ROSETTA", None, raising = False)
+ monkeypatch.setattr(hw, "is_apple_silicon", lambda: False)
+ monkeypatch.setattr(hw, "_has_mlx", lambda: False)
+ monkeypatch.setattr(hw.platform, "system", lambda: "Darwin")
+ monkeypatch.setattr(hw.platform, "machine", lambda: machine)
+ monkeypatch.setattr(hw.subprocess, "run", _fake_sysctl(arm64, calls))
+ hw.detect_hardware()
+ assert hw.CHAT_ONLY is True
+ assert hw.CHAT_ONLY_REASON == expected
+ assert calls == [["sysctl", "-n", "hw.optional.arm64"]]
+
+
+def test_rosetta_probe_fails_open_to_intel_mac(monkeypatch):
+ def boom(*args, **kwargs):
+ raise OSError("no sysctl")
+
+ monkeypatch.setattr(hw, "_ROSETTA", None, raising = False)
+ monkeypatch.setattr(hw, "is_apple_silicon", lambda: False)
+ monkeypatch.setattr(hw, "_has_mlx", lambda: False)
+ monkeypatch.setattr(hw.platform, "system", lambda: "Darwin")
+ monkeypatch.setattr(hw.platform, "machine", lambda: "x86_64")
+ monkeypatch.setattr(hw.subprocess, "run", boom)
+ hw.detect_hardware()
+ assert hw.CHAT_ONLY_REASON == "intel_mac"
+
+
+def test_native_arm64_mac_never_probes_rosetta(monkeypatch):
+ calls = []
+ monkeypatch.setattr(hw, "_ROSETTA", None, raising = False)
+ monkeypatch.setattr(hw, "_has_mlx", lambda: False)
+ monkeypatch.setattr(hw.platform, "system", lambda: "Darwin")
+ monkeypatch.setattr(hw.platform, "machine", lambda: "arm64")
+ monkeypatch.setattr(hw.subprocess, "run", _fake_sysctl("1", calls))
+ monkeypatch.setattr(hw, "_has_usable_mlx_stack", lambda: False, raising = False)
+ hw.detect_hardware()
+ assert hw.CHAT_ONLY_REASON == "mlx_unavailable"
+ assert ["sysctl", "-n", "hw.optional.arm64"] not in calls
+
+
def test_cpu_only_non_mac_reason(monkeypatch):
monkeypatch.setattr(hw, "is_apple_silicon", lambda: False)
monkeypatch.setattr(hw, "_has_mlx", lambda: False)
diff --git a/studio/backend/tests/test_export_capability.py b/studio/backend/tests/test_export_capability.py
index bb90de94126..79f206e1b4e 100644
--- a/studio/backend/tests/test_export_capability.py
+++ b/studio/backend/tests/test_export_capability.py
@@ -38,6 +38,19 @@ def _patch(monkeypatch, *, torch: bool, device, apple: bool):
monkeypatch.setattr(hw, "_has_torch", lambda: torch)
monkeypatch.setattr(hw, "get_device", lambda: device)
monkeypatch.setattr(hw, "is_apple_silicon", lambda: apple)
+ monkeypatch.setattr(hw, "_running_under_rosetta", lambda: False)
+
+
+def test_rosetta_export_gives_the_native_arm64_remedy(monkeypatch):
+ # is_apple_silicon() is False in an x86_64 process, so this fell through to no_accelerator.
+ _patch(monkeypatch, torch = True, device = hw.DeviceType.CPU, apple = False)
+ monkeypatch.setattr(hw, "_running_under_rosetta", lambda: True)
+ monkeypatch.setattr(hw.platform, "system", lambda: "Darwin")
+ monkeypatch.setattr(hw, "current_chat_only_verdict", lambda: ("rosetta", None))
+ cap = hw.export_capability()
+ assert cap["export_supported"] is False
+ assert cap["export_unsupported_reason"] == "rosetta"
+ assert "arm64" in cap["export_unsupported_message"]
def test_cpu_with_torch_unsupported_no_accelerator(monkeypatch):
diff --git a/studio/backend/tests/test_token_preview.py b/studio/backend/tests/test_token_preview.py
index c4891da32cb..2b111aaab0f 100644
--- a/studio/backend/tests/test_token_preview.py
+++ b/studio/backend/tests/test_token_preview.py
@@ -250,6 +250,47 @@ def test_a_quit_that_races_the_spawn_reaps_the_new_worker(monkeypatch):
assert stopped and isinstance(stopped[-1], _Proc), "the adopted worker was left running"
+def test_the_worker_env_hides_every_accelerator_only_in_the_child(monkeypatch):
+ """CUDA, HIP and SYCL are hidden only in the worker env, never in the parent's os.environ."""
+ import multiprocessing as mp_module
+
+ from core.training import account_jobs
+ from utils import process_lifetime
+
+ service = token_preview._TokenPreviewService()
+ envs = []
+
+ class _Proc:
+ pid = 4243
+
+ def __init__(self, **kwargs):
+ pass
+
+ def start(self):
+ pass
+
+ def is_alive(self):
+ return True
+
+ monkeypatch.delenv("ONEAPI_DEVICE_SELECTOR", raising = False)
+ monkeypatch.setattr(process_lifetime, "is_process_shutting_down", lambda: False)
+ monkeypatch.setattr(process_lifetime, "adopt_pid", lambda pid: None)
+ monkeypatch.setattr(
+ account_jobs,
+ "account_process_spec",
+ lambda module, fn, env, kw: envs.append(env) or ((), {}),
+ )
+ monkeypatch.setattr(token_preview._CTX, "Process", _Proc)
+ monkeypatch.setattr(token_preview._CTX, "Queue", lambda: mp_module.Queue())
+ service._spawn_locked(("k",), {})
+ assert envs, "the worker was not spawned"
+ env = envs[0]
+ assert env["CUDA_VISIBLE_DEVICES"] == "" and env["HIP_VISIBLE_DEVICES"] == ""
+ assert env["ONEAPI_DEVICE_SELECTOR"] == "opencl:cpu"
+ assert env.get("ZE_AFFINITY_MASK") != ""
+ assert "ONEAPI_DEVICE_SELECTOR" not in os.environ
+
+
def test_a_supplied_cache_folder_is_never_the_tokenizer_source(captured):
_call_route(
TokenPreviewRequest.model_validate(
diff --git a/studio/backend/tests/test_video_capability.py b/studio/backend/tests/test_video_capability.py
index 4512014b5cf..66cc6b47f00 100644
--- a/studio/backend/tests/test_video_capability.py
+++ b/studio/backend/tests/test_video_capability.py
@@ -45,8 +45,10 @@ def _patch(
system = None,
mps = None,
torch_import_error = None,
+ rosetta = False,
):
monkeypatch.setattr(hw, "_has_torch", lambda: torch)
+ monkeypatch.setattr(hw, "_running_under_rosetta", lambda: rosetta)
monkeypatch.setattr(hw, "get_device", lambda: device)
monkeypatch.setattr(hw, "is_apple_silicon", lambda: apple)
monkeypatch.setattr(hw, "CHAT_ONLY_REASON", chat_only_reason)
@@ -302,6 +304,24 @@ def test_intel_mac_is_macos_unsupported_not_a_missing_gpu(monkeypatch):
assert "GPU" not in cap["video_unsupported_message"]
+def test_rosetta_is_told_to_reinstall_native_not_that_it_is_an_intel_mac(monkeypatch):
+ _patch(
+ monkeypatch,
+ torch = True,
+ device = hw.DeviceType.CPU,
+ apple = False,
+ system = "Darwin",
+ mps = False,
+ chat_only_reason = "rosetta",
+ rosetta = True,
+ )
+ cap = hw.video_capability()
+ assert cap["video_supported"] is False
+ assert cap["video_unsupported_reason"] == "rosetta"
+ assert "arm64" in cap["video_unsupported_message"]
+ assert "Intel Mac" not in cap["video_unsupported_message"]
+
+
def test_a_broken_probe_still_beats_the_macos_branch(monkeypatch):
# detection_failed is checked first on purpose: a Mac whose probe fell over should be
# told detection failed, not that video is coming soon, because the verdict is unknown.
diff --git a/studio/backend/utils/hardware/hardware.py b/studio/backend/utils/hardware/hardware.py
index 94af813a4c4..3153c1e87d5 100644
--- a/studio/backend/utils/hardware/hardware.py
+++ b/studio/backend/utils/hardware/hardware.py
@@ -48,7 +48,7 @@ class DeviceType(str, Enum):
DEVICE: Optional[DeviceType] = None
CHAT_ONLY: bool = True # No CUDA GPU -> GGUF chat only (Mac, CPU-only, etc.)
-# Why CHAT_ONLY is True; None when training is enabled. "mlx_unavailable": Apple Silicon with a missing, too old or broken MLX stack, published at once when no mlx is on disk while a present but unusable one waits for the post-warm probe, so a stack that only lost the warm's import race is still overturned; "no_torch": Apple Silicon installed --no-torch, GGUF-only by request, which `unsloth studio update` cannot change; "intel_mac"; "no_gpu": CPU-only non-Mac; "torch_cpu_build" / "torch_cuda_unavailable" (see classify_torch_build()): the host HAS GPUs this PyTorch cannot use, which must not read as "no_gpu", since the fix is repairing the install, not buying a GPU.
+# Why CHAT_ONLY is True; None when training is enabled. "mlx_unavailable": Apple Silicon with a missing, too old or broken MLX stack, published at once when no mlx is on disk while a present but unusable one waits for the post-warm probe, so a stack that only lost the warm's import race is still overturned; "no_torch": Apple Silicon installed --no-torch, GGUF-only by request, which `unsloth studio update` cannot change; "rosetta": an x86_64 Python on Apple Silicon; "intel_mac"; "no_gpu": CPU-only non-Mac; "torch_cpu_build" / "torch_cuda_unavailable" (see classify_torch_build()): the host HAS GPUs this PyTorch cannot use, which must not read as "no_gpu", since the fix is repairing the install, not buying a GPU.
CHAT_ONLY_REASON: Optional[str] = None
# What blocked the reason above, when there is something specific to say. Only "mlx_unavailable" sets it: the gate is all-or-nothing across mlx, mlx-lm and mlx-vlm, so naming the offending package is the difference between a dead end and a fix. Never shown on its own.
CHAT_ONLY_DETAIL: Optional[str] = None
@@ -152,6 +152,29 @@ def is_apple_silicon() -> bool:
return platform.system() == "Darwin" and platform.machine() == "arm64"
+_ROSETTA: Optional[bool] = None
+
+
+def _running_under_rosetta() -> bool:
+ """True for an x86_64 Python on an Apple Silicon Mac (``hw.optional.arm64``, as install.sh). Cached; never raises."""
+ global _ROSETTA
+ if _ROSETTA is None:
+ answer = False
+ if platform.system() == "Darwin" and platform.machine() == "x86_64":
+ try:
+ out = subprocess.run(
+ ["sysctl", "-n", "hw.optional.arm64"],
+ capture_output = True,
+ text = True,
+ timeout = 2,
+ )
+ answer = out.returncode == 0 and out.stdout.strip() == "1"
+ except Exception:
+ answer = False
+ _ROSETTA = answer
+ return _ROSETTA
+
+
# Set by _has_torch() when torch is installed but its import blew up (unresolved CUDA libs); the CPU fallback reports that as a detection failure, not as "no GPU".
TORCH_IMPORT_ERROR: Optional[str] = None
@@ -1661,6 +1684,9 @@ def _detect_hardware_locked() -> DeviceType:
_build_reason, _build_detail = _mismatch_verdict_for_this_host(_disk_reason)
if _build_reason is not None:
CHAT_ONLY_REASON, CHAT_ONLY_DETAIL = _build_reason, _build_detail
+ elif platform.system() == "Darwin" and _running_under_rosetta():
+ # MLX needs a native arm64 Python; "Intel Mac" would be wrong.
+ CHAT_ONLY_REASON = "rosetta"
elif platform.system() == "Darwin":
CHAT_ONLY_REASON = "intel_mac" # Intel Mac: no PyTorch/MLX -> GGUF-only by design.
else:
@@ -1947,6 +1973,12 @@ def export_capability() -> dict:
"Export on Apple Silicon requires the MLX stack, which is unavailable or too old. Run "
"`unsloth studio update` to restore MLX and enable export."
)
+ elif platform.system() == "Darwin" and _running_under_rosetta():
+ reason = "rosetta"
+ message = (
+ "Studio is running under Rosetta (x86_64 Python), so export is disabled. Re-run the installer from a "
+ "native arm64 terminal to enable export."
+ )
elif _gpu_present_but_unusable_message("export", verdict) is not None:
# BEFORE _has_torch(), which reports an unimportable wheel as absent while re-running the seconds-long import that already failed.
reason = verdict[0]
@@ -2042,6 +2074,12 @@ def _video_capability_verdict() -> dict:
"This PyTorch build exposes no Metal (MPS) device, so the video pipelines have "
"nowhere to run. Reinstall PyTorch with MPS support to enable video generation."
)
+ elif platform.system() == "Darwin" and _running_under_rosetta():
+ reason = "rosetta"
+ message = (
+ "Studio is running under Rosetta (x86_64 Python), which has no Metal (MPS) device for the "
+ "video pipelines. Re-run the installer from a native arm64 terminal to enable video generation."
+ )
elif platform.system() == "Darwin":
# Ahead of the torch/GPU branches below: neither installing torch nor adding a GPU enables video on an Intel Mac, so it must not be told to try either.
reason = "macos_unsupported"
diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsx
index 0763128a447..6e2e0c1a620 100644
--- a/studio/frontend/src/components/app-sidebar.tsx
+++ b/studio/frontend/src/components/app-sidebar.tsx
@@ -1338,6 +1338,8 @@ export function AppSidebar() {
canRepair
? "Training was left out of this install (Chat only). Use Repair installation in Settings to add it."
: "Training was left out of this install (--no-torch). Reinstall without --no-torch to enable Train."
+ : chatOnlyReason === "rosetta"
+ ? "Studio is running under Rosetta (x86_64 Python). Re-run the installer from a native arm64 terminal to enable training."
: chatOnlyReason === "intel_mac"
? "Training needs Apple Silicon or a GPU. Intel Macs are chat-only."
: chatOnlyReason === "torch_cpu_build" ||
diff --git a/studio/frontend/src/config/hardware-verdict.ts b/studio/frontend/src/config/hardware-verdict.ts
index 936820096a0..437bb220edb 100644
--- a/studio/frontend/src/config/hardware-verdict.ts
+++ b/studio/frontend/src/config/hardware-verdict.ts
@@ -57,6 +57,8 @@ export function videoNavHint(
// that reads as a fix that would not work. Mirrors the backend's message for this host.
if (chatOnlyReason === "intel_mac")
return "Video generation requires Apple Silicon. This Intel Mac has no Metal device to run it.";
+ if (chatOnlyReason === "rosetta")
+ return "Studio is running under Rosetta (x86_64 Python). Re-run the installer from a native arm64 terminal to enable video generation.";
// The GPU is there; PyTorch is what cannot reach it (a Windows update that resolved torch
// from PyPI leaves a +cpu wheel beside two working cards), so "get a GPU" is a lie.
if (
diff --git a/studio/frontend/src/features/model-picker/model-config/per-model-config.ts b/studio/frontend/src/features/model-picker/model-config/per-model-config.ts
index eddf39094c1..6e6c0a5658c 100644
--- a/studio/frontend/src/features/model-picker/model-config/per-model-config.ts
+++ b/studio/frontend/src/features/model-picker/model-config/per-model-config.ts
@@ -171,6 +171,7 @@ const NO_MLX_REASONS = new Set([
"mlx_unavailable",
"no_torch",
"intel_mac",
+ "rosetta",
"detection_failed",
]);
diff --git a/studio/frontend/tests/mlx-context-helpers.test.ts b/studio/frontend/tests/mlx-context-helpers.test.ts
index 5473190e15e..3554b8a1857 100644
--- a/studio/frontend/tests/mlx-context-helpers.test.ts
+++ b/studio/frontend/tests/mlx-context-helpers.test.ts
@@ -157,6 +157,7 @@ test("MLX is a Mac non-GGUF load, and the reasons that rule it out", () => {
"mlx_unavailable",
"no_torch",
"intel_mac",
+ "rosetta",
"detection_failed",
]) {
assert.equal(isServedByMlx(false, "mac", reason), false, reason);
diff --git a/studio/frontend/tests/provisional-hardware-verdict.test.ts b/studio/frontend/tests/provisional-hardware-verdict.test.ts
index c354f4ca5f1..418fa56779a 100644
--- a/studio/frontend/tests/provisional-hardware-verdict.test.ts
+++ b/studio/frontend/tests/provisional-hardware-verdict.test.ts
@@ -419,6 +419,8 @@ test("the Video hint names the reason the host has no video device", () => {
!/gpu|graphics|coming soon/i.test(videoNavHint(true, "intel_mac") ?? ""),
"an Intel Mac is pointed at graphics hardware that cannot run video",
);
+ // Rosetta has Apple Silicon underneath: the fix is a native arm64 install, not new hardware.
+ assert.match(videoNavHint(true, "rosetta") ?? "", /arm64/, "a Rosetta host is not told the fix");
});
// A broken MLX stack makes the host chat-only, but video runs on Metal and does not use MLX,
diff --git a/studio/install_audio_cpp_prebuilt.py b/studio/install_audio_cpp_prebuilt.py
index deb7a890448..e6615890242 100644
--- a/studio/install_audio_cpp_prebuilt.py
+++ b/studio/install_audio_cpp_prebuilt.py
@@ -269,6 +269,32 @@ def nvidia_driver_cuda_version() -> Optional[tuple[int, int]]:
return (int(match.group(1)), int(match.group(2))) if match else None
+def _nvidia_has_prebuilt_arch() -> Optional[bool]:
+ """Any NVIDIA card sm_75+ (audio.cpp CUDA*_ARCHS in unsloth-prebuilt-build.yml start at 75); None if unreadable."""
+ exe = shutil.which("nvidia-smi")
+ if not exe:
+ return None
+ try:
+ out = subprocess.run(
+ [exe, "--query-gpu=compute_cap", "--format=csv,noheader"],
+ capture_output = True,
+ text = True,
+ timeout = 15,
+ )
+ except (OSError, subprocess.SubprocessError):
+ return None
+ caps = []
+ for line in (out.stdout or "").splitlines() if out.returncode == 0 else ():
+ if not line.strip():
+ continue
+ match = re.fullmatch(r"\s*(\d+)\.(\d+)\s*", line)
+ if not match:
+ # Old driver ("[N/A]"): unknown, keep the CUDA answer.
+ return None
+ caps.append((int(match.group(1)), int(match.group(2))))
+ return any(cap >= (7, 5) for cap in caps) if caps else None
+
+
def _nvidia_gpu_present() -> bool:
"""An NVIDIA card, also one whose driver reports no CUDA version (wedged, partial)."""
if shutil.which("nvidia-smi"):
@@ -305,7 +331,10 @@ def detect_accelerator() -> str:
system = platform.system().lower()
if system == "darwin":
return "metal"
- if nvidia_driver_cuda_version() is not None:
+ # Pascal / Volta-only hosts: the fork's bundles have no kernels for them. Other publishers set their own archs.
+ if nvidia_driver_cuda_version() is not None and (
+ _repo().casefold() != DEFAULT_REPO.casefold() or _nvidia_has_prebuilt_arch() is not False
+ ):
return "cuda"
# No HIP bundle is published (#13042); never beside NVIDIA, which Vulkan could enumerate first.
if _amd_gpu_present() and not _nvidia_gpu_present():
diff --git a/tests/studio/install/test_install_audio_cpp_prebuilt_logic.py b/tests/studio/install/test_install_audio_cpp_prebuilt_logic.py
index 32c4ed0a4ef..3b2a330c1aa 100644
--- a/tests/studio/install/test_install_audio_cpp_prebuilt_logic.py
+++ b/tests/studio/install/test_install_audio_cpp_prebuilt_logic.py
@@ -127,6 +127,79 @@ def test_driver_cuda_version_reads_both_spellings(monkeypatch, smi, expected):
assert M.nvidia_driver_cuda_version() == expected
+def _fake_nvidia_smi(
+ monkeypatch,
+ caps,
+ returncode = 0,
+ amd = False,
+):
+ def run(cmd, *a, **k):
+ if any("compute_cap" in part for part in cmd):
+ if isinstance(caps, Exception):
+ raise caps
+ return type("R", (), {"stdout": caps, "returncode": returncode})()
+ return type("R", (), {"stdout": "CUDA Version: 12.6", "returncode": 0})()
+
+ monkeypatch.setattr(M.platform, "system", lambda: "Linux")
+ monkeypatch.setattr(M.shutil, "which", lambda name: "nvidia-smi")
+ monkeypatch.setattr(M.subprocess, "run", run)
+ monkeypatch.setattr(M, "_amd_gpu_present", lambda: amd)
+ monkeypatch.delenv("UNSLOTH_AUDIO_CPP_REPO", raising = False)
+
+
+ "caps,expected",
+ [
+ ("6.1\n", "cpu"), # GTX 10xx / P40: no kernels in the sm_75+ bundles
+ ("7.0\n7.0\n", "cpu"), # V100 x2
+ ("6.0\n", "cpu"), # P100
+ ],
+)
+def test_pre_turing_nvidia_does_not_get_the_cuda_bundle(monkeypatch, caps, expected):
+ _fake_nvidia_smi(monkeypatch, caps)
+ assert M.detect_accelerator() == expected
+
+
+def test_pre_turing_nvidia_beside_amd_still_skips_vulkan(monkeypatch):
+ _fake_nvidia_smi(monkeypatch, "6.1\n", amd = True)
+ assert M.detect_accelerator() == "cpu"
+
+
+ "caps",
+ [
+ "7.5\n", # T4
+ "8.6\n",
+ "12.0\n",
+ "6.1\n8.9\n", # mixed: one card has kernels
+ "", # no rows
+ "[N/A]\n", # old driver
+ "6.1\n[N/A]\n", # one unreadable card: unknown
+ 'Field "compute_cap" is not a valid field to query.\n',
+ ],
+)
+def test_sm75_or_unreadable_compute_cap_keeps_cuda(monkeypatch, caps):
+ _fake_nvidia_smi(monkeypatch, caps)
+ assert M.detect_accelerator() == "cuda"
+
+
[email protected]("repo", ["0xShug0/audio.cpp", "someone/audio.cpp-fork"])
+def test_custom_audio_repo_keeps_cuda_on_pre_turing(monkeypatch, repo):
+ """The sm_75 floor is the default fork's; a custom publisher may ship Pascal / Volta kernels."""
+ _fake_nvidia_smi(monkeypatch, "6.1\n")
+ monkeypatch.setenv("UNSLOTH_AUDIO_CPP_REPO", repo)
+ assert M.detect_accelerator() == "cuda"
+ monkeypatch.setenv("UNSLOTH_AUDIO_CPP_REPO", "UnslothAI/Audio.cpp")
+ assert M.detect_accelerator() == "cpu"
+
+
+def test_a_failing_compute_cap_query_keeps_cuda(monkeypatch):
+ _fake_nvidia_smi(monkeypatch, "6.1\n", returncode = 6)
+ assert M.detect_accelerator() == "cuda"
+ _fake_nvidia_smi(monkeypatch, M.subprocess.TimeoutExpired("nvidia-smi", 15))
+ assert M.detect_accelerator() == "cuda"
+
+
# Install flow. Archives are real zips in tmp_path; the download copies them, the staged-server check
# is stubbed (its own tests below), and every release carries its own sha256 index, as the fork's do.
@@ -1857,6 +1930,7 @@ def _fake_host(
)
monkeypatch.setattr(M.shutil, "which", lambda name: "/usr/bin/nvidia-smi" if smi else None)
monkeypatch.setattr(M, "nvidia_driver_cuda_version", lambda: cuda)
+ monkeypatch.setattr(M, "_nvidia_has_prebuilt_arch", lambda: None)
real_listdir = M.os.listdir
monkeypatch.setattr(
M.os,
diff --git a/unsloth_cli/commands/doctor.py b/unsloth_cli/commands/doctor.py
index a5a4711410a..1622523133a 100644
--- a/unsloth_cli/commands/doctor.py
+++ b/unsloth_cli/commands/doctor.py
@@ -85,8 +85,12 @@ def collect_gpus(torch) -> dict:
"hip": hip,
"nccl": None,
"gpus": [],
+ "accelerator": None,
}
if not torch.cuda.is_available():
+ # A CUDA build that sees no device stays a failure.
+ if not info["cuda"] and not hip:
+ info["accelerator"] = _non_cuda_accelerator(torch)
return info
try:
nccl = torch.cuda.nccl.version()
@@ -117,6 +121,22 @@ def collect_gpus(torch) -> dict:
return info
+def _non_cuda_accelerator(torch) -> Optional[str]:
+ for name, probe in (
+ (
+ "mps",
+ getattr(getattr(getattr(torch, "backends", None), "mps", None), "is_available", None),
+ ),
+ ("xpu", getattr(getattr(torch, "xpu", None), "is_available", None)),
+ ):
+ try:
+ if callable(probe) and probe():
+ return name
+ except Exception:
+ pass
+ return None
+
+
def driver_version(pynvml = None) -> Optional[str]:
if pynvml is not None:
try:
@@ -403,6 +423,9 @@ def verdict(
"""(healthy, hints). Pure, so every branch is testable without GPUs."""
hints = []
gpus = info["gpus"]
+ if not gpus and info.get("accelerator"):
+ name = "Metal (MPS)" if info["accelerator"] == "mps" else "Intel XPU"
+ return True, [f"{name} detected: multi-GPU CUDA checks skipped."]
if not gpus:
return False, [
"No GPU is visible to torch. Check `nvidia-smi`, CUDA_VISIBLE_DEVICES, and "
diff --git a/unsloth_cli/tests/test_doctor_gpus.py b/unsloth_cli/tests/test_doctor_gpus.py
index f360532b8dc..f788a86b316 100644
--- a/unsloth_cli/tests/test_doctor_gpus.py
+++ b/unsloth_cli/tests/test_doctor_gpus.py
@@ -482,3 +482,55 @@ def test_doctor_reports_a_gpu_enumeration_failure(monkeypatch):
assert result.exit_code == 1
assert result.exception is None or isinstance(result.exception, SystemExit)
assert "GPU enumeration failed" in result.output and "PROBLEMS FOUND" in result.output
+
+
+def _non_cuda_torch(
+ mps = False,
+ xpu = False,
+ cuda = None,
+ hip = None,
+):
+ torch = _fake_torch(0)
+ torch.__version__ = "2.x"
+ torch.version = SimpleNamespace(cuda = cuda, hip = hip)
+ torch.backends = SimpleNamespace(mps = SimpleNamespace(is_available = lambda: mps))
+ torch.xpu = SimpleNamespace(is_available = lambda: xpu)
+ return torch
+
+
+ "mps, xpu, name",
+ [(True, False, "Metal (MPS)"), (False, True, "Intel XPU")],
+)
+def test_doctor_on_mps_or_xpu_is_healthy(monkeypatch, mps, xpu, name):
+ result, calls = _run_doctor(monkeypatch, _non_cuda_torch(mps = mps, xpu = xpu), [])
+ assert result.exit_code == 0, result.output
+ assert calls == []
+ assert "Verdict: OK" in result.output
+ assert f"{name} detected: multi-GPU CUDA checks skipped." in result.output
+
+
+ "cuda, hip",
+ [("12.4", None), (None, "6.2")],
+)
+def test_cuda_or_rocm_build_without_a_device_still_fails_beside_xpu_or_mps(monkeypatch, cuda, hip):
+ torch = _non_cuda_torch(mps = True, xpu = True, cuda = cuda, hip = hip)
+ result, calls = _run_doctor(monkeypatch, torch, [])
+ assert result.exit_code == 1 and calls == []
+ assert "No GPU" in result.output
+
+
+def test_cpu_build_without_mps_or_xpu_still_fails(monkeypatch):
+ result, _ = _run_doctor(monkeypatch, _non_cuda_torch(), [])
+ assert result.exit_code == 1 and "No GPU" in result.output
+
+
+def test_a_raising_accelerator_probe_is_no_accelerator():
+ torch = _non_cuda_torch()
+
+ def boom():
+ raise RuntimeError("level zero")
+
+ torch.xpu = SimpleNamespace(is_available = boom)
+ assert doctor_mod.collect_gpus(torch)["accelerator"] is None