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.

Unsloth Studio / Desktop: show the GPU llama.cpp runs on when it is CUDA and differs from training (#12251)

Leo Borcherdinga521448fde1e
diff --git a/studio/backend/main.py b/studio/backend/main.py
index 581dae8f438..549ca96c15a 100644
--- a/studio/backend/main.py
+++ b/studio/backend/main.py
@@ -2176,6 +2176,7 @@ def _get_cached_system_gpu_info(
import time
from utils.hardware import (
get_backend_visible_gpu_info,
+ get_cross_vendor_inference_gpu_info,
get_visible_gpu_utilization,
get_vulkan_inference_gpu_info,
)
@@ -2298,15 +2299,20 @@ def _get_cached_system_gpu_info(
inference_gpu_info = gpu_info
else:
vulkan_info = get_vulkan_inference_gpu_info()
- inference_gpu_info = (
- {
+ cross_vendor_info = (
+ get_cross_vendor_inference_gpu_info() if vulkan_info is None else None
+ )
+ if vulkan_info is not None:
+ inference_gpu_info = {
**vulkan_info,
# Pinnable only once the probe enumerated devices: without ordinals there is nothing to offer.
"gguf_gpu_ids_supported": bool(vulkan_info.get("devices")),
}
- if vulkan_info is not None
- else gpu_info
- )
+ elif cross_vendor_info is not None:
+ # SMI row numbers, not the ordinals a pin is applied in.
+ inference_gpu_info = {**cross_vendor_info, "gguf_gpu_ids_supported": False}
+ else:
+ inference_gpu_info = gpu_info
combined_info = (gpu_info, inference_gpu_info)
_system_gpu_cache = (time.monotonic(), combined_info)
diff --git a/studio/backend/tests/test_system_vulkan_gpu_info.py b/studio/backend/tests/test_system_vulkan_gpu_info.py
index 4f81c4d61b2..7e04bee56f4 100644
--- a/studio/backend/tests/test_system_vulkan_gpu_info.py
+++ b/studio/backend/tests/test_system_vulkan_gpu_info.py
@@ -398,3 +398,247 @@ def test_system_gpu_info_still_derives_free_when_the_probe_reports_none(monkeypa
)
assert gpu["devices"][0]["vram_free_gb"] == 18.0
+
+
+def _refuse(*args, **kwargs):
+ raise AssertionError("this vendor's reader must not run")
+
+
+def _mixed_host(monkeypatch, *, torch_rocm, llama_backend):
+ """Stubs a host whose torch and llama.cpp are pinned by the test, never read off the runner."""
+ import utils.hardware as hardware
+ import utils.hardware.hardware as hw
+ from core.inference.llama_cpp import LlamaCppBackend
+
+ torch_backend = "rocm" if torch_rocm else "cuda"
+ torch_card = "AMD Radeon AI PRO R9700" if torch_rocm else "NVIDIA GeForce RTX 3080"
+ monkeypatch.setattr(
+ hardware,
+ "get_backend_visible_gpu_info",
+ lambda: {
+ "available": True,
+ "backend": torch_backend,
+ "index_kind": "physical",
+ "devices": [
+ {"index": 0, "index_kind": "physical", "name": torch_card, "memory_total_gb": 32.0}
+ ],
+ },
+ )
+ monkeypatch.setattr(
+ hardware,
+ "get_visible_gpu_utilization",
+ lambda: {"available": True, "backend": torch_backend, "devices": []},
+ )
+ monkeypatch.setattr(hardware, "get_vulkan_inference_gpu_info", lambda: None)
+ monkeypatch.setattr(hw, "get_device", lambda: hw.DeviceType.CUDA)
+ monkeypatch.setattr(hw, "IS_ROCM", torch_rocm)
+ monkeypatch.setattr(hw, "_installed_llama_backend", lambda: llama_backend)
+ monkeypatch.setattr(LlamaCppBackend, "_is_vulkan_backend", staticmethod(lambda: False))
+ monkeypatch.setattr(
+ LlamaCppBackend, "_backend_lacks_gpu_lib", staticmethod(lambda binary = None: False)
+ )
+ monkeypatch.setattr(main, "_system_gpu_cache", None)
+ for name in (
+ "CUDA_VISIBLE_DEVICES",
+ "HIP_VISIBLE_DEVICES",
+ "ROCR_VISIBLE_DEVICES",
+ "GPU_DEVICE_ORDINAL",
+ ):
+ monkeypatch.delenv(name, raising = False)
+
+
+def test_rocm_torch_with_a_cuda_llama_cpp_reports_the_nvidia_card(monkeypatch):
+ """RTX 3080 beside an R9700, ROCm torch, CUDA llama.cpp: only the AMD card was listed."""
+ import utils.hardware.amd as amd
+ import utils.hardware.nvidia as nvidia
+
+ _mixed_host(monkeypatch, torch_rocm = True, llama_backend = "cuda")
+ monkeypatch.setattr(
+ nvidia,
+ "get_physical_gpu_inventory",
+ lambda: {
+ "available": True,
+ "devices": [
+ {
+ "vendor": "nvidia",
+ "index": 0,
+ "name": "NVIDIA GeForce RTX 3080",
+ "memory_total_gb": 10.0,
+ }
+ ],
+ },
+ )
+ asked = []
+
+ def _usage(parent_visible_ids, parent_cuda_visible_devices = None):
+ asked.append(parent_visible_ids)
+ return {"devices": [{"index": 0, "vram_used_gb": 7.88, "vram_total_gb": 10.0}]}
+
+ monkeypatch.setattr(nvidia, "get_visible_gpu_utilization", _usage)
+ monkeypatch.setattr(amd, "get_gpu_vram_report", _refuse)
+
+ gpu, inference_gpu = main._get_cached_system_gpu_info(SimpleNamespace(debug = lambda *args: None))
+
+ assert gpu["backend"] == "rocm"
+ assert inference_gpu is not gpu
+ assert inference_gpu["backend"] == "cuda"
+ assert inference_gpu["available"] is True
+ assert inference_gpu["index_kind"] == "physical"
+ # nvidia-smi row numbers are not the ordinals a pin is applied in.
+ assert inference_gpu["gguf_gpu_ids_supported"] is False
+ assert asked == [[0]]
+ (card,) = inference_gpu["devices"]
+ assert card["name"] == "NVIDIA GeForce RTX 3080"
+ assert card["index"] == 0
+ assert card["memory_total_gb"] == 10.0
+ assert card["vram_used_gb"] == 7.88
+ assert card["vram_free_gb"] == 2.12
+ assert card["vram_utilization_pct"] == 78.8
+
+
+def test_rocm_torch_with_a_rocm_llama_cpp_keeps_the_training_inventory(monkeypatch):
+ import utils.hardware.amd as amd
+ import utils.hardware.nvidia as nvidia
+
+ _mixed_host(monkeypatch, torch_rocm = True, llama_backend = "rocm")
+ monkeypatch.setattr(nvidia, "get_physical_gpu_inventory", _refuse)
+ monkeypatch.setattr(nvidia, "get_visible_gpu_utilization", _refuse)
+ monkeypatch.setattr(amd, "get_gpu_vram_report", _refuse)
+
+ gpu, inference_gpu = main._get_cached_system_gpu_info(SimpleNamespace(debug = lambda *args: None))
+
+ assert inference_gpu is gpu
+ assert inference_gpu["backend"] == "rocm"
+
+
+def test_cuda_torch_with_a_rocm_llama_cpp_keeps_the_training_inventory(monkeypatch):
+ """amd-smi cannot prove HIP's memory scope (an APU reports only its carve-out)."""
+ import utils.hardware.amd as amd
+ import utils.hardware.nvidia as nvidia
+
+ _mixed_host(monkeypatch, torch_rocm = False, llama_backend = "rocm")
+ monkeypatch.setattr(nvidia, "get_physical_gpu_inventory", _refuse)
+ monkeypatch.setattr(amd, "get_gpu_vram_report", _refuse)
+
+ gpu, inference_gpu = main._get_cached_system_gpu_info(SimpleNamespace(debug = lambda *args: None))
+
+ assert inference_gpu is gpu
+
+
+def test_a_silent_nvidia_smi_falls_back_to_the_training_inventory(monkeypatch):
+ """An empty cross-vendor list would read as "this host has no GPU" to the load estimate."""
+ import utils.hardware.nvidia as nvidia
+
+ _mixed_host(monkeypatch, torch_rocm = True, llama_backend = "cuda")
+ monkeypatch.setattr(
+ nvidia, "get_physical_gpu_inventory", lambda: {"available": False, "devices": []}
+ )
+ monkeypatch.setattr(nvidia, "get_visible_gpu_utilization", _refuse)
+
+ gpu, inference_gpu = main._get_cached_system_gpu_info(SimpleNamespace(debug = lambda *args: None))
+
+ assert inference_gpu is gpu
+
+
+def test_a_vulkan_llama_cpp_never_asks_the_cross_vendor_probe(monkeypatch):
+ """CUDA torch with a Vulkan llama.cpp keeps the Vulkan inventory exactly as before."""
+ import utils.hardware as hardware
+
+ vulkan_info = {
+ "available": True,
+ "backend": "vulkan",
+ "devices": [
+ {"index": 0, "index_kind": "vulkan", "name": "Vulkan0", "memory_total_gb": 8.0}
+ ],
+ "index_kind": "vulkan",
+ }
+ _mixed_host(monkeypatch, torch_rocm = False, llama_backend = "vulkan")
+ monkeypatch.setattr(hardware, "get_vulkan_inference_gpu_info", lambda: vulkan_info)
+ monkeypatch.setattr(hardware, "get_cross_vendor_inference_gpu_info", _refuse)
+
+ gpu, inference_gpu = main._get_cached_system_gpu_info(SimpleNamespace(debug = lambda *args: None))
+
+ assert gpu["backend"] == "cuda"
+ assert inference_gpu["backend"] == "vulkan"
+ assert inference_gpu["devices"] == vulkan_info["devices"]
+ assert inference_gpu["gguf_gpu_ids_supported"] is True
+
+
+def _two_nvidia_cards(monkeypatch, names_and_totals):
+ import utils.hardware.amd as amd
+ import utils.hardware.nvidia as nvidia
+
+ monkeypatch.setattr(
+ nvidia,
+ "get_physical_gpu_inventory",
+ lambda: {
+ "available": True,
+ "devices": [
+ {"vendor": "nvidia", "index": i, "name": name, "memory_total_gb": total}
+ for i, (name, total) in enumerate(names_and_totals)
+ ],
+ },
+ )
+ asked = []
+
+ def _usage(parent_visible_ids, parent_cuda_visible_devices = None):
+ asked.append(parent_visible_ids)
+ return {"devices": [{"index": i, "vram_used_gb": 1.0} for i in parent_visible_ids]}
+
+ monkeypatch.setattr(nvidia, "get_visible_gpu_utilization", _usage)
+ monkeypatch.setattr(amd, "get_gpu_vram_report", _refuse)
+ return asked
+
+
+def test_cross_vendor_nvidia_cards_follow_cuda_visible_devices(monkeypatch):
+ _mixed_host(monkeypatch, torch_rocm = True, llama_backend = "cuda")
+ asked = _two_nvidia_cards(monkeypatch, [("RTX 3080", 10.0), ("RTX 4090", 24.0)])
+ monkeypatch.setenv("CUDA_VISIBLE_DEVICES", "1")
+
+ _, inference_gpu = main._get_cached_system_gpu_info(SimpleNamespace(debug = lambda *args: None))
+
+ assert [d["name"] for d in inference_gpu["devices"]] == ["RTX 4090"]
+ assert asked == [[1]]
+
+
+def test_capacity_less_nvidia_rows_fall_back_to_the_training_inventory(monkeypatch):
+ """procfs placeholder rows (nvidia-smi failed, driver loaded) carry no capacity."""
+ _mixed_host(monkeypatch, torch_rocm = True, llama_backend = "cuda")
+ _two_nvidia_cards(monkeypatch, [(None, None), (None, None)])
+
+ gpu, inference_gpu = main._get_cached_system_gpu_info(SimpleNamespace(debug = lambda *args: None))
+
+ assert inference_gpu is gpu
+
+
+def test_an_unresolvable_cuda_mask_declines_the_nvidia_inventory(monkeypatch):
+ _mixed_host(monkeypatch, torch_rocm = True, llama_backend = "cuda")
+ _two_nvidia_cards(monkeypatch, [("RTX 3080", 10.0), ("RTX 4090", 24.0)])
+ monkeypatch.setenv("CUDA_VISIBLE_DEVICES", "GPU-8a1b2c3d")
+
+ gpu, inference_gpu = main._get_cached_system_gpu_info(SimpleNamespace(debug = lambda *args: None))
+
+ assert inference_gpu is gpu
+
+
+def test_visible_ordinals_follow_the_mask_order(monkeypatch):
+ _mixed_host(monkeypatch, torch_rocm = True, llama_backend = "cuda")
+ _two_nvidia_cards(monkeypatch, [("RTX 3080", 10.0), ("RTX 4090", 24.0)])
+ monkeypatch.setenv("CUDA_VISIBLE_DEVICES", "1,0")
+
+ _, inference_gpu = main._get_cached_system_gpu_info(SimpleNamespace(debug = lambda *args: None))
+
+ assert [(d["name"], d["visible_ordinal"]) for d in inference_gpu["devices"]] == [
+ ("RTX 4090", 0),
+ ("RTX 3080", 1),
+ ]
+
+
+def test_a_non_pci_cuda_order_declines_multi_nvidia(monkeypatch):
+ _mixed_host(monkeypatch, torch_rocm = True, llama_backend = "cuda")
+ _two_nvidia_cards(monkeypatch, [("RTX 3080", 10.0), ("RTX 4090", 24.0)])
+ monkeypatch.setenv("CUDA_DEVICE_ORDER", "FASTEST_FIRST")
+
+ gpu, inference_gpu = main._get_cached_system_gpu_info(SimpleNamespace(debug = lambda *args: None))
+
+ assert inference_gpu is gpu
diff --git a/studio/backend/utils/hardware/__init__.py b/studio/backend/utils/hardware/__init__.py
index eb7eaea868d..b45c12fa0a2 100644
--- a/studio/backend/utils/hardware/__init__.py
+++ b/studio/backend/utils/hardware/__init__.py
@@ -25,6 +25,7 @@ from .hardware import (
trusted_mem_get_info,
get_backend_visible_gpu_info,
get_vulkan_inference_gpu_info,
+ get_cross_vendor_inference_gpu_info,
get_physical_gpu_count,
get_visible_gpu_count,
get_parent_visible_gpu_ids,
@@ -106,6 +107,7 @@ __all__ = [
"trusted_mem_get_info",
"get_backend_visible_gpu_info",
"get_vulkan_inference_gpu_info",
+ "get_cross_vendor_inference_gpu_info",
"get_physical_gpu_count",
"get_visible_gpu_count",
"get_parent_visible_gpu_ids",
diff --git a/studio/backend/utils/hardware/hardware.py b/studio/backend/utils/hardware/hardware.py
index 88875185069..e6d0f066462 100644
--- a/studio/backend/utils/hardware/hardware.py
+++ b/studio/backend/utils/hardware/hardware.py
@@ -5947,6 +5947,112 @@ def get_vulkan_inference_gpu_info() -> Optional[Dict[str, Any]]:
return result
+def _installed_llama_backend() -> Optional[str]:
+ """The backend the installed llama.cpp prebuilt records, as Settings shows it."""
+ from core.inference.llama_cpp import LlamaCppBackend
+ from utils.llama_cpp_freshness import read_install_marker
+ from utils.prebuilt.llama_backend import marker_backend
+
+ return marker_backend(read_install_marker(LlamaCppBackend._find_llama_server_binary()))
+
+
+def _smi_inference_device(
+ index: int,
+ ordinal: int,
+ name: Optional[str],
+ total_gb: Optional[float],
+ used_gb: Optional[float],
+) -> Dict[str, Any]:
+ known = total_gb is not None and used_gb is not None
+ return {
+ "index": index,
+ "index_kind": "physical",
+ "visible_ordinal": ordinal,
+ "name": name,
+ "memory_total_gb": total_gb,
+ "vram_used_gb": used_gb,
+ "vram_free_gb": round(max(0.0, total_gb - used_gb), 2) if known else None,
+ "vram_utilization_pct": round((used_gb / total_gb) * 100, 1)
+ if known and total_gb > 0
+ else None,
+ "shared_memory": False,
+ }
+
+
+def _nvidia_inference_devices() -> list[Dict[str, Any]]:
+ from core.inference.llama_cpp import LlamaCppBackend
+
+ from . import nvidia
+
+ # The mask llama.cpp's own nvidia-smi probe applies: hidden cards are not llama-server's.
+ allowed = LlamaCppBackend._visible_devices_mask("CUDA_VISIBLE_DEVICES")
+ if allowed is None and os.environ.get("CUDA_VISIBLE_DEVICES") is not None:
+ return [] # a UUID / MIG mask names cards nvidia-smi rows cannot be matched to
+ physical = [
+ row
+ for row in (nvidia.get_physical_gpu_inventory().get("devices") or [])
+ if isinstance(row.get("index"), int)
+ ]
+ # nvidia-smi rows are PCI order; CUDA ordinals (and numeric masks) only match them under PCI_BUS_ID.
+ if os.environ.get("CUDA_DEVICE_ORDER") != "PCI_BUS_ID" and (
+ allowed is not None or len(physical) > 1
+ ):
+ return []
+ rows = [row for row in physical if allowed is None or row["index"] in allowed]
+ if not rows:
+ return []
+ if allowed is not None:
+ # visible_ordinal is the child's numbering, which follows the mask's order.
+ order = [int(x) for x in os.environ["CUDA_VISIBLE_DEVICES"].split(",") if x.strip()]
+ rows.sort(key = lambda row: order.index(row["index"]))
+ usage = nvidia.get_visible_gpu_utilization([row["index"] for row in rows])
+ usage_by_index = {d.get("index"): d for d in usage.get("devices") or []}
+ devices = []
+ for ordinal, row in enumerate(rows):
+ util = usage_by_index.get(row["index"], {})
+ devices.append(
+ _smi_inference_device(
+ row["index"],
+ ordinal,
+ row.get("name"),
+ row.get("memory_total_gb") or util.get("vram_total_gb"),
+ util.get("vram_used_gb"),
+ )
+ )
+ return devices
+
+
+def get_cross_vendor_inference_gpu_info() -> Optional[Dict[str, Any]]:
+ """The NVIDIA cards a CUDA llama.cpp runs on when torch is another backend, else None.
+
+ nvidia-smi only: a CUDA context here would pin VRAM. No ROCm counterpart: amd-smi cannot
+ prove the memory scope HIP sees (an APU reports only its carve-out).
+ """
+ try:
+ llama_backend = _installed_llama_backend()
+ except Exception as e:
+ logger.debug("Could not read the installed llama.cpp backend: %s", e)
+ return None
+ if llama_backend != "cuda" or _backend_label(get_device()) == "cuda":
+ return None
+ try:
+ devices = _nvidia_inference_devices()
+ except Exception as e:
+ logger.debug("CUDA inference GPU query failed: %s", e)
+ return None
+ # Not []: the load estimate reads that as "no GPU". Capacity-less procfs rows read as 0 GB.
+ if not devices or not all((d["memory_total_gb"] or 0) > 0 for d in devices):
+ return None
+ return {
+ "available": True,
+ "backend": llama_backend,
+ "backend_cuda_visible_devices": None,
+ "parent_visible_gpu_ids": [],
+ "devices": devices,
+ "index_kind": "physical",
+ }
+
+
def _repair_smi_visible_devices(
devices: list[Dict[str, Any]], parent_visible_ids: Optional[list[int]]
) -> bool:
diff --git a/studio/frontend/src/features/settings/tabs/resources-tab.tsx b/studio/frontend/src/features/settings/tabs/resources-tab.tsx
index 238d1f96f28..ddceff93894 100644
--- a/studio/frontend/src/features/settings/tabs/resources-tab.tsx
+++ b/studio/frontend/src/features/settings/tabs/resources-tab.tsx
@@ -668,6 +668,24 @@ export function ResourcesTab() {
) : (
` · ${t("settings.resources.gpu.unavailable")}`
)}
+ {separateInferenceGpu.available &&
+ inferenceDisplay.usageDevices.map((device, index) => (
+ <span
+ key={`${device.index ?? index}-${device.name ?? "gpu"}`}
+ className="block normal-case"
+ >
+ {`${
+ device.name ??
+ t("settings.resources.gpu.deviceWithIndex", {
+ index: deviceOrdinal(device) ?? index,
+ })
+ } · ${t("settings.resources.gpu.used", {
+ value: isFiniteNumber(device.vram_used_gb)
+ ? formatGiB(device.vram_used_gb)
+ : unknownLabel,
+ })}`}
+ </span>
+ ))}
{separateInferenceGpu.available &&
inferenceDisplay.sharedDevices.length > 0 && (
<span className="block normal-case">