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
Report a Linux ROCm APU host-backed pool of zero as measured, not unknown (#11451)
Daniel Hancf0e57790547
diff --git a/studio/backend/tests/test_system_poll_no_cuda_context.py b/studio/backend/tests/test_system_poll_no_cuda_context.pyindex fd3d1aa6676..35eed8614f6 100644--- a/studio/backend/tests/test_system_poll_no_cuda_context.py+++ b/studio/backend/tests/test_system_poll_no_cuda_context.py@@ -1241,8 +1241,14 @@ def test_linux_rocm_apu_uses_sysfs_to_confirm_equal_total_scope(assert result["devices"][0]["memory_total_gb"] == torch_total / (1024**3)assert result["devices"][0]["shared_memory"] is expected_shared+ # When sysfs answered and torch does not exceed it, the host-backed part is a+ # measured ZERO rather than unknown. It used to be omitted, and the tile renders+ # an omitted figure as "all of it is host memory", which printed a 64 GiB+ # carve-out as `0.00 GiB VRAM + 64.00 GiB shared` on a real gfx1151+ # (unsloth#7449 defect 1). `shared_memory` still turns on only for a positive+ # host-backed part, so nothing collapses that did not collapse before.assert result["devices"][0]["shared_memory_host_backed_gb"] == (- round((torch_total - sysfs_total) / (1024**3), 2) if expected_shared else None+ round((torch_total - sysfs_total) / (1024**3), 2) if expected_shared else 0.0)@@ -1743,3 +1749,121 @@ def test_gpu_summary_apu_counters_need_positively_identified_uma(monkeypatch):# Driver total kept, free still hipMemGetInfo's.assert summary == {"gpu_name": "Test GPU", "vram_total_gb": 100.0, "vram_free_gb": 98.0}+++# The measured gfx1151, end to end through the payload Settings > System reads.+# Numbers are verbatim from the AMD CI Strix Halo runner against main:+# torch total_memory 68719476736 (64.00 GiB)+# sysfs mem_info_vram_total 68719476736 (64.00 GiB, a real BIOS carve-out)+# sysfs mem_info_gtt_total 33521315840 (31.22 GiB, host-backed, ON TOP)+# and an 8 GiB torch allocation landed in vram_used, not in gtt_used, so the+# driver's own accounting calls that 64 GiB dedicated.+_MEASURED_STRIX_HALO_TOTAL_BYTES = 68719476736+++def test_the_measured_strix_halo_is_not_reported_as_having_no_vram(monkeypatch):+ """unsloth#7449 defect 1, the Linux arm.++ Settings > System renders an ABSENT `shared_memory_host_backed_gb` as "the whole+ budget is host memory", so omitting the figure printed `0.00 GiB VRAM ++ 64.00 GiB shared` on a machine with a 64 GiB carve-out. The figure here is zero,+ and zero has to be said out loud.+ """+ total = _MEASURED_STRIX_HALO_TOTAL_BYTES+ mod = _apu_mod(gtt_total = total, carve_out = total)+ for var in (+ "HIP_VISIBLE_DEVICES",+ "ROCR_VISIBLE_DEVICES",+ "CUDA_VISIBLE_DEVICES",+ "GPU_DEVICE_ORDINAL",+ ):+ monkeypatch.delenv(var, raising = False)+ monkeypatch.setattr(hw, "IS_ROCM", True)+ monkeypatch.setattr(hw.platform, "system", lambda: "Linux")+ monkeypatch.setattr(hw, "get_device", lambda: hw.DeviceType.CUDA)+ monkeypatch.setattr(hw, "get_parent_visible_gpu_ids", lambda: [0])+ monkeypatch.setattr(hw, "_torch_get_device_module", lambda: (mod, "cuda"))+ monkeypatch.setattr(hw, "_rocm_kfd_gpu_pci_ids", lambda: {0: "0000:03:00.0"})+ monkeypatch.setattr(+ hw,+ "_rocm_linux_sysfs_vram_by_pci_gb",+ lambda: {"0000:03:00.0": (9.06, total / (1024**3))},+ )++ device = hw.get_backend_visible_gpu_info()["devices"][0]++ assert device["memory_total_gb"] == 64.0+ assert (+ device["shared_memory_host_backed_gb"] == 0.0+ ), "a readable sysfs total that torch does not exceed is a measured zero, not an unknown"+ # Still a unified-memory part for every rule that cares; only the SPLIT is known.+ assert device["unified_memory"] is True+ # NOT flipped on: `shared_memory` also means "these rows are one pool", and a+ # zero host-backed part is no reason to start collapsing devices.+ assert device["shared_memory"] is False+++def test_an_unreadable_sysfs_total_still_leaves_the_split_unknown(monkeypatch):+ """The other direction: WSL and anything else with no DRM sysfs must keep+ answering None, because there a zero would be an assertion nobody measured."""+ # _rocm_linux_sysfs_vram_by_index returns {} off Linux before reading anything, so+ # without this the assertion below is answered by the platform gate rather than by+ # the logic under test: red on macOS and Windows where it expects a figure, and+ # green for the wrong reason where it expects {}.+ monkeypatch.setattr(hw.platform, "system", lambda: "Linux")+ devices = [{"index": 0, "total_gb": 100.0, "_rocm_known_unified": True}]+ monkeypatch.setattr(hw, "_rocm_kfd_gpu_pci_ids", lambda: {0: "0000:03:00.0"})+ monkeypatch.setattr(+ hw, "_rocm_linux_sysfs_vram_by_pci_gb", lambda: {"0000:03:00.0": (0.0, 0.0)}+ )+ assert hw._rocm_linux_shared_pool_host_gb_by_index(devices) == {}+++def test_a_real_gtt_backed_excess_is_still_reported_as_host_backed(monkeypatch):+ """The case #9314 and #11366 exist for must not regress: a torch total well+ above the sysfs heap is a genuine host-backed window and keeps its figure."""+ # _rocm_linux_sysfs_vram_by_index returns {} off Linux before reading anything, so+ # without this the assertion below is answered by the platform gate rather than by+ # the logic under test: red on macOS and Windows where it expects a figure, and+ # green for the wrong reason where it expects {}.+ monkeypatch.setattr(hw.platform, "system", lambda: "Linux")+ devices = [{"index": 0, "total_gb": 100.0, "_rocm_known_unified": True}]+ monkeypatch.setattr(hw, "_rocm_kfd_gpu_pci_ids", lambda: {0: "0000:03:00.0"})+ monkeypatch.setattr(+ hw, "_rocm_linux_sysfs_vram_by_pci_gb", lambda: {"0000:03:00.0": (1.0, 8.0)}+ )+ assert hw._rocm_linux_shared_pool_host_gb_by_index(devices) == {0: 92.0}+++def test_a_discrete_rocm_card_is_never_given_a_host_backed_figure(monkeypatch):+ """Gated on `_rocm_known_unified`, so a dGPU keeps its discrete rendering."""+ # _rocm_linux_sysfs_vram_by_index returns {} off Linux before reading anything, so+ # without this the assertion below is answered by the platform gate rather than by+ # the logic under test: red on macOS and Windows where it expects a figure, and+ # green for the wrong reason where it expects {}.+ monkeypatch.setattr(hw.platform, "system", lambda: "Linux")+ devices = [{"index": 0, "total_gb": 24.0}]+ monkeypatch.setattr(hw, "_rocm_kfd_gpu_pci_ids", lambda: {0: "0000:03:00.0"})+ monkeypatch.setattr(+ hw, "_rocm_linux_sysfs_vram_by_pci_gb", lambda: {"0000:03:00.0": (1.0, 24.0)}+ )+ assert hw._rocm_linux_shared_pool_host_gb_by_index(devices) == {}+++def test_a_partitioned_device_keeps_its_split_unknown(monkeypatch):+ """sysfs reporting the whole card while torch reports one partition is a SCOPE+ change, not a measurement of zero host-backed memory.++ Publishing 0.0 there would call the whole partition dedicated and overstate+ independent capacity, in the direction that admits a load.+ `_rocm_system_wide_vram_by_index` already treats a mismatch over the same 10% as a+ different scope in either direction.+ """+ monkeypatch.setattr(hw.platform, "system", lambda: "Linux")+ devices = [{"index": 0, "total_gb": 24.0, "_rocm_known_unified": True}]+ monkeypatch.setattr(hw, "_rocm_kfd_gpu_pci_ids", lambda: {0: "0000:03:00.0"})+ # sysfs reports the whole 192 GiB card, torch reports a 24 GiB partition.+ monkeypatch.setattr(+ hw, "_rocm_linux_sysfs_vram_by_pci_gb", lambda: {"0000:03:00.0": (1.0, 192.0)}+ )+ assert hw._rocm_linux_shared_pool_host_gb_by_index(devices) == {}diff --git a/studio/backend/utils/hardware/hardware.py b/studio/backend/utils/hardware/hardware.pyindex 2c66d6bb15e..7a0e310e648 100644--- a/studio/backend/utils/hardware/hardware.py+++ b/studio/backend/utils/hardware/hardware.py@@ -4180,8 +4180,44 @@ def _rocm_linux_shared_pool_host_gb_by_index(devices: list[Dict[str, Any]]) -> Dcontinue_used, sysfs_total = entrytorch_total = dev.get("total_gb") or 0.0- if sysfs_total > 0 and torch_total - sysfs_total > 0.1 * torch_total:- shared[index] = round(torch_total - sysfs_total, 2)+ if sysfs_total <= 0:+ # sysfs could not be read for this card, so the split is genuinely+ # UNKNOWN and the index stays absent. WSL reaches here.+ continue+ excess = torch_total - sysfs_total+ # A readable sysfs total that torch does not exceed means the whole torch+ # budget IS the driver's dedicated heap, i.e. the host-backed part is a+ # measured ZERO. Omitting the index said "unknown" instead, and the tile+ # renders unknown as "all of it is host memory": on a gfx1151 whose+ # mem_info_vram_total is the full 64 GiB carve-out, Settings > System read+ # `0.00 GiB VRAM + 64.00 GiB shared`. Measured on the AMD CI Strix Halo+ # against main; unsloth#7449 defect 1.+ #+ # The 0.1 band is the threshold for BELIEVING an excess, not for publishing a+ # figure at all. It is NOT a rounding allowance: both totals carry 0.01 GiB, so+ # rounding cannot reach a whole GiB, and a 4 GiB gap on a 64 GiB part is a real+ # disagreement between two sources that count different things.+ #+ # Inside the band the split is genuinely undecided, and all three answers are+ # imperfect. Publishing the excess would call the budget shared (see the caller:+ # host_gb > 0 sets shared_memory, which collapses several rows into one pool) on+ # a difference we do not trust. Omitting the index renders as "all of it is host+ # memory", which IS unsloth#7449 defect 1 and the thing this function exists to+ # stop. Zero attributes the disagreement to the dedicated heap, which is the+ # smallest error of the three: at 64 vs 60 GiB it overstates dedicated memory by+ # 4 GiB, where omitting understates it by all 64.+ #+ # Not settled on hardware: neither AMD CI runner has a small BIOS carve-out, so+ # the in-band case was never measured, only reasoned about.+ # sysfs far ABOVE torch is not a small disagreement, it is a different scope:+ # a partitioned device where sysfs reports the whole card and torch reports one+ # partition. `_rocm_system_wide_vram_by_index` treats a mismatch over the same+ # 10% as a scope change in EITHER direction, and publishing 0.0 here would call+ # the whole partition dedicated, overstating independent capacity in the+ # direction that admits a load. Leave the index absent, which means unknown.+ if -excess > 0.1 * torch_total:+ continue+ shared[index] = round(excess, 2) if excess > 0.1 * torch_total else 0.0return shared@@ -5812,8 +5848,19 @@ def get_backend_visible_gpu_info() -> Dict[str, Any]:shared_host_gb = _rocm_linux_shared_pool_host_gb_by_index(torch_devices)for td in torch_devices:if td["index"] in shared_host_gb:- td["shared_memory"] = True- td["shared_memory_host_backed_gb"] = shared_host_gb[td["index"]]+ host_gb = shared_host_gb[td["index"]]+ # A measured ZERO is an answer, not a miss: it says the whole+ # budget is the driver's dedicated heap. Publish it either way,+ # because the consumer renders an ABSENT figure as "all of it is+ # host memory" and that is how a 64 GiB carve-out came out as+ # `0.00 GiB VRAM + 64.00 GiB shared` (unsloth#7449 defect 1).+ td["shared_memory_host_backed_gb"] = host_gb+ # But only call the budget shared when some of it really is.+ # `shared_memory` additionally means "several rows are views of+ # ONE pool", which collapses them; a two-socket MI300A with no+ # host-backed part must stay additive.+ if host_gb > 0:+ td["shared_memory"] = Trueelif IS_ROCM and platform.system() == "Windows":shared_host_gb = _windows_rocm_shared_pool_host_gb_by_index(torch_devices)for td in torch_devices:diff --git a/studio/frontend/tests/unified-memory-apu-totals.test.ts b/studio/frontend/tests/unified-memory-apu-totals.test.tsindex 7094a73645f..f2bcfc9bd6f 100644--- a/studio/frontend/tests/unified-memory-apu-totals.test.ts+++ b/studio/frontend/tests/unified-memory-apu-totals.test.ts@@ -17,11 +17,37 @@ import {sharesHostMemory,} from "../src/hooks/gpu-vram.ts";-/** Measured on a Strix Halo gfx1151 box (Radeon 8060S) under ROCm on Linux. */+/** Measured on a Strix Halo gfx1151 box (Radeon 8060S) under ROCm on Linux.+ *+ * The host-backed part is a measured ZERO, not an omission. `mem_info_vram_total`+ * on this part is a real 64 GiB BIOS carve-out: the kernel never saw those pages,+ * so the whole torch budget IS the dedicated heap. Confirmed by experiment on the+ * AMD CI gfx1151 runner rather than by arithmetic, because no installed-capacity+ * source is readable there (`dmidecode` is denied and `/sys/devices/system/memory`+ * counts the kernel's own blocks, which a carve-out is excluded from exactly as+ * `MemTotal` is, so both hypotheses predict the same 64 GiB). Taking 8 GiB of VRAM+ * moved `/proc/meminfo` MemAvailable by -0.01 GiB, 0% of the allocation, while the+ * card's `mem_info_vram_used` rose +8.17 GiB and `mem_info_gtt_used` did not move.+ * MemTotal there is 62.44 GiB, disjoint from the 64.+ *+ * This fixture carried no `shared_memory_host_backed_gb` until unsloth#11451, which+ * made the backend publish the zero. Leaving it absent described a payload the+ * backend no longer emits for this box, and asserted the very reading that PR+ * calls the defect. */const linuxApu = {memory_total_gb: 64.0,shared_memory: false,unified_memory: true,+ shared_memory_host_backed_gb: 0.0,+};+/** The same silicon where the split is genuinely UNKNOWN: sysfs unreadable, as on+ * WSL. unsloth#11366's rule still governs here and must keep a test of its own --+ * an absent figure means "assume the whole window is a view into host RAM", which+ * is the safe reading when nobody has measured it. */+const linuxApuUnknownSplit = {+ memory_total_gb: 64.0,+ shared_memory: false,+ unified_memory: true,};/** The same part on Windows, where `hardware.py` does set the flag. */const windowsApu = {@@ -32,12 +58,36 @@ const windowsApu = {};const discrete = { memory_total_gb: 179.06, shared_memory: false };-test("a Linux ROCm APU's window is shared host memory, not dedicated VRAM", () => {+test("a Linux ROCm APU whose carve-out is MEASURED reads as dedicated VRAM", () => {+ // The measured zero says the 64 GiB stands beside system RAM, so it is exactly+ // as dedicated as a discrete card's. Rendering it as host memory is what printed+ // `0 GiB VRAM + 64 GiB shared` on a machine with a full 64 GiB carve-out.const totals = gpuMemoryTotalsGb([linuxApu]);+ assert.equal(totals.dedicated, 64);+ assert.equal(totals.shared, 0);+ assert.equal(totals.total, 64);+ assert.equal(aggregateGpuMemoryTotalGb([linuxApu]), 64);+});++test("a Linux ROCm APU whose split is UNKNOWN is still shared host memory", () => {+ // unsloth#11366's rule, kept: with nothing measured, the whole window has to be+ // assumed a view INTO system RAM, because that is the reading that cannot invent+ // capacity. Only a MEASURED zero may move it to dedicated.+ const totals = gpuMemoryTotalsGb([linuxApuUnknownSplit]);assert.equal(totals.dedicated, 0);assert.equal(totals.shared, 64);assert.equal(totals.total, 64);- assert.equal(aggregateGpuMemoryTotalGb([linuxApu]), 64);+ assert.equal(aggregateGpuMemoryTotalGb([linuxApuUnknownSplit]), 64);+});++test("the aggregate does not move between the measured and unknown splits", () => {+ // The split is a display and budgeting concern; the TOTAL is what every fit+ // verdict is measured against, so it must be identical either way or this change+ // alters what the app agrees to load.+ assert.equal(+ gpuMemoryTotalsGb([linuxApu]).total,+ gpuMemoryTotalsGb([linuxApuUnknownSplit]).total,+ );});test("a discrete card beside an APU keeps its own VRAM separate", () => {