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
Unsloth Studio (AMD/Windows): report an iGPU's used VRAM when a discrete card sits beside it (#11871)
Leo Borcherding79856a64be75
diff --git a/studio/backend/tests/test_rocm_windows_vram_7072.py b/studio/backend/tests/test_rocm_windows_vram_7072.pyindex 98d7828de14..a4f301325ef 100644--- a/studio/backend/tests/test_rocm_windows_vram_7072.py+++ b/studio/backend/tests/test_rocm_windows_vram_7072.py@@ -2425,3 +2425,92 @@ def test_the_luid_is_internal_and_never_reaches_a_payload(win_rocm, monkeypatch)for payload in (hw.get_gpu_utilization(), hw.get_visible_gpu_utilization()):assert not carries_luid(payload)assert 0x15369 not in [v for v in payload.values() if isinstance(v, int)]+++# A unified iGPU beside a discrete card (#8942).+RX6800_IGPU = [+ ("AMD Radeon RX 6800", 16 * GB, "gfx1030"),+ ("AMD Radeon(TM) Graphics", int(76.8 * GB), "gfx1036"),+]+DGPU_LUID, IGPU_LUID = 0xD1E2, 0x1532A+++def _igpu_beside_dgpu(monkeypatch, *, shared = "default"):+ monkeypatch.setitem(sys.modules, "torch", _fake_torch(RX6800_IGPU, free_equals_total = True))+ monkeypatch.setattr(+ hw, "_rocm_props_are_positively_unified", lambda props: props.gcnArchName == "gfx1036"+ )+ dedicated = [+ (f"luid_0x00000000_0x{DGPU_LUID:08x}_phys_0", 4.28 * GB),+ (f"luid_0x00000000_0x{IGPU_LUID:08x}_phys_0", 0.3 * GB),+ ("luid_0x00000000_0x00017034_phys_0", 0.0),+ ]+ if shared == "default":+ shared = [+ (f"luid_0x00000000_0x{DGPU_LUID:08x}_phys_0", 0.1 * GB),+ (f"luid_0x00000000_0x{IGPU_LUID:08x}_phys_0", 1.2 * GB),+ ]+ counters = {"Dedicated Usage": dedicated, "Shared Usage": shared}+ monkeypatch.setattr(+ hw,+ "_rocm_windows_perf_counter_vram_by_adapter",+ lambda counter = "Dedicated Usage": counters[counter],+ )+ monkeypatch.setattr(+ hw, "_rocm_windows_hip_adapter_ids", _hip_ids((DGPU_LUID, 0), (IGPU_LUID, 0))+ )+++def test_an_igpu_beside_a_discrete_card_reports_its_own_used(win_rocm, monkeypatch):+ _igpu_beside_dgpu(monkeypatch)++ devices, aggregate = hw._rocm_windows_per_device_vram([0, 1])+ assert devices[0]["used_gb"] == pytest.approx(4.28, abs = 0.01) # Dedicated only+ assert devices[1]["used_gb"] == pytest.approx(1.5, abs = 0.01) # 0.3 + 1.2+ assert devices[1]["total_gb"] == 76.8+ assert aggregate == pytest.approx(5.78, abs = 0.01)+++def test_a_failed_shared_query_leaves_the_igpu_unknown(win_rocm, monkeypatch):+ """A failed Shared query is not zero: past the carve-out the overflow lives there."""+ _igpu_beside_dgpu(monkeypatch, shared = None)++ devices, aggregate = hw._rocm_windows_per_device_vram([0, 1])+ assert devices[0]["used_gb"] == pytest.approx(4.28, abs = 0.01)+ assert devices[1]["used_gb"] is None+ assert aggregate is None+++def test_without_hip_luids_the_igpu_stays_unknown(win_rocm, monkeypatch):+ """Without a LUID the lone busy adapter is the discrete card, so no sum."""+ _igpu_beside_dgpu(monkeypatch)+ monkeypatch.setattr(hw, "_rocm_windows_hip_adapter_ids", lambda ordinals, names: None)++ devices, aggregate = hw._rocm_windows_per_device_vram([0, 1])+ assert devices[1]["used_gb"] is None+ assert aggregate is None+++def test_the_system_tab_gets_both_rows_and_the_total(win_rocm, monkeypatch):+ _igpu_beside_dgpu(monkeypatch)++ devices = hw.get_visible_gpu_utilization()["devices"]+ assert [(d["index"], d["vram_used_gb"], d["vram_total_gb"]) for d in devices] == [+ (0, pytest.approx(4.28, abs = 0.01), 16.0),+ (1, pytest.approx(1.5, abs = 0.01), 76.8),+ ]+++def test_an_igpu_enumerated_first_is_still_paired_by_luid(win_rocm, monkeypatch):+ _igpu_beside_dgpu(monkeypatch)+ monkeypatch.setitem(+ sys.modules, "torch", _fake_torch(list(reversed(RX6800_IGPU)), free_equals_total = True)+ )+ monkeypatch.setattr(+ hw, "_rocm_windows_hip_adapter_ids", _hip_ids((IGPU_LUID, 0), (DGPU_LUID, 0))+ )++ devices, aggregate = hw._rocm_windows_per_device_vram([0, 1])+ assert devices[0]["used_gb"] == pytest.approx(1.5, abs = 0.01)+ assert devices[1]["used_gb"] == pytest.approx(4.28, abs = 0.01)+ assert aggregate == pytest.approx(5.78, abs = 0.01)diff --git a/studio/backend/utils/hardware/hardware.py b/studio/backend/utils/hardware/hardware.pyindex 2c8f081dca0..073538a31be 100644--- a/studio/backend/utils/hardware/hardware.py+++ b/studio/backend/utils/hardware/hardware.py@@ -3471,6 +3471,22 @@ def _rocm_windows_unified_used_bytes(return dedicated_used + shared_used+def _rocm_windows_unified_used_bytes_for_luid(+ luid: int, dedicated: list[tuple[str, float]], total_bytes: float+) -> Optional[float]:+ """Dedicated + Shared for the adapter with this LUID, clamped to ``total_bytes``; None if the Shared query fails (see _rocm_windows_unified_used_bytes)."""+ shared = _rocm_windows_perf_counter_vram_by_adapter("Shared Usage")+ if shared is None:+ return None+ used = 0.0+ for instance, value in (*dedicated, *shared):+ if _parse_adapter_luid(instance) == luid:+ if value < 0.0:+ return None+ used += value+ return max(0.0, min(used, total_bytes))++def _rocm_windows_per_device_vram(device_indices: list[int], adapters: Optional[list[tuple[str, float]]] = None) -> tuple[list[Dict[str, Any]], Optional[float]]:@@ -3581,12 +3597,23 @@ def _rocm_windows_per_device_vram(assigned = [(unified_used if scoped else used) for scoped, used in zip(pool_scoped, assigned)]+ if only is None:+ # Beside another GPU only HIP's LUID says which counters are the iGPU's (#8942).+ for position, luid in enumerate(whole_adapter):+ meta = dev_meta[position]+ if pool_scoped[position] and meta["positively_unified"] and luid is not None:+ assigned[position] = _rocm_windows_unified_used_bytes_for_luid(+ luid, adapters, float(meta["total_bytes"])+ )# The aggregate is the visible set's exact total, so it survives only when every pool-scoped member got a figure.- aggregate_gb = (- round(unified_used / (1024**3), 2)- if unified_used is not None and len(dev_meta) == 1- else None- )+ if only is not None:+ aggregate_gb = round(unified_used / (1024**3), 2) if unified_used is not None else None+ else:+ aggregate_gb = (+ round(sum(assigned) / (1024**3), 2)+ if all(used is not None for used in assigned)+ else None+ )devices: list[Dict[str, Any]] = []for meta, used_bytes, luid in zip(dev_meta, assigned, whole_adapter):