Repository navigation
fix(studio): keep iGPU carve-out VRAM on hybrid ROCm hosts - #9198
kagura-chen wants to merge 5 commits into
Conversation
On a host where an integrated Radeon and a discrete Radeon are both visible (e.g. a Ryzen iGPU beside a dGPU), the inventory routine replaced the integrated part's carve-out total with the mem_get_info GTT/shared pool, reporting system RAM as the iGPU's VRAM capacity (unslothai#8942). Detect hybrid ROCm sets once up front (unified + non-unified members present), and skip the GTT substitution for the integrated member only. APU-only hosts and all-discrete sets keep today's behaviour, pinned by new tests.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 886847c7c3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| unified_flags = [ | ||
| props is not None and bool(_rocm_classify_unified_memory(props)[1]) | ||
| for _, _, props in props_list | ||
| ] | ||
| hybrid_rocm = any(unified_flags) and not all(unified_flags) |
There was a problem hiding this comment.
Exclude failed probes from hybrid detection
When an APU is successfully classified but another requested ordinal fails get_device_properties, this comprehension assigns the failed probe False, producing flags such as [True, False] and incorrectly declaring the host hybrid. The surviving APU then skips mem_get_info and is reported using only its carve-out rather than the intended GTT total, regressing the existing best-effort behavior during a device-loss or enumeration failure. Hybrid detection should consider only successfully retrieved properties and require both classifications among those successful probes.
Useful? React with 👍 / 👎.
|
Confirmed this hits studio/backend/utils/hardware/hardware.py where the carve-out to GTT correction is applied to the integrated device even when a discrete card is present, so the iGPU capacity comes back inflated. Will get this reviewed. |
There was a problem hiding this comment.
studio/backend/utils/hardware/hardware.py:1244 - /api/system emits a device row that contradicts itself: used above total, free 47x total
_torch_get_device_inventory supplies memory_total_gb. vram_used_gb, vram_free_gb and vram_utilization_pct come from _torch_get_per_device_info (line 1272) through _apply_unified_memory_correction (line 2274), which still adopts torch's GTT total over amd-smi's carve-out. main.py:1833-1847 merges the two without reconciling them: enriched_dev = dict(dev) carries the inventory total through untouched while total_vram on line 1833 is the utilization side's.
Replaying main.py:1815-1848 against the real hardware functions, on a dGPU gfx1201 16 GiB + iGPU gfx1150 0.5 GiB carve-out / 24 GiB GTT host with amd-smi present:
merge base idx=1 memory_total_gb=24.0 vram_used_gb=0.6 vram_free_gb=23.4 pct=2.5
this PR idx=1 memory_total_gb=0.5 vram_used_gb=0.6 vram_free_gb=23.4 pct=2.5
host tile merge base total=40.0 free=38.4
this PR total=16.5 free=38.4
resources-tab.tsx:482-503 renders total, used and free on one row from exactly those three fields, so Settings -> Resources reads "0.6 GiB used / 0.5 GiB total, 23.4 GiB free" with the meter at 2.5%. With a 6 GiB model resident it reads 6.6 / 0.5 GiB. The host tile takes its total from aggregateGpuMemoryTotalGb (hooks/gpu-vram.ts:30) and its free from the summed vram_free_gb (resources-tab.tsx:253-263), so free comes out 2.3x total. Both were self-consistent at merge base.
_apply_unified_memory_correction's docstring states the invariant this breaks: "so the two endpoints stay in sync on AMD iGPUs with unified memory". test_inventory_totals_match_the_occupancy_path (tests/test_system_poll_no_cuda_context.py:195) asserts that parity but only parametrizes non-ROCm totals, so it still passes. The hybrid gate has to sit where both totals are decided, not in the inventory helper alone.
studio/backend/utils/hardware/hardware.py:1251 - a Strix Halo loses its GTT pool as soon as any discrete card is visible, and the new tests pin that outcome
hybrid_rocm and integrated is true for every unified device in a mixed set, including the ones whose dedicated carve-out genuinely is not their VRAM. [gfx1151 8 GiB carve-out / 128 GiB GTT, gfx1100 24 GiB], hip 6.2:
merge base [128.0, 24.0]
this PR [ 8.0, 24.0]
That is the outcome _rocm_props_total_is_carve_out's docstring names on line 1161 as the thing to avoid: "Reporting the carve-out would undo that correction and budget a 128 GiB Strix Halo as ~8 GiB", and on line 1172: "a total that is too small hides models".
The two new hybrid tests encode the same mistake. tests/test_system_poll_no_cuda_context.py:285 and :297 give the integrated member gcnArchName = "gfx1150", which is Strix Point, one of the three arches _rocm_classify_unified_memory names as a genuine shared GPU/system-RAM pool (core/training/worker.py:1704, :1737), and then assert it must report 0.5 GB. The fixture also pairs that arch with the name "AMD Radeon Graphics", a desktop iGPU. A desktop Ryzen iGPU is gfx1036 or gfx1103 and reaches is_unified only through the driver flag, never through the arch set.
The gate asks whether a device is the integrated member of a mixed set. The question that decides the answer is whether the device's dedicated total is its real VRAM, and the classifier already separates those two populations. The skip needs to exclude the hardcoded arch set, not every unified member.
studio/backend/utils/hardware/hardware.py:1231 - a failed props probe turns a single-APU host into a hybrid one
props is not None and bool(...) contributes False for an ordinal whose get_device_properties raised, so one failed probe beside one APU gives [True, False], hybrid_rocm goes true, and the only real device on the host loses the substitution. len(props_list) >= 2 on line 1227 counts requested ordinals, not probed devices, so it does not stop this.
Strix Halo at ordinal 0, ordinal 1 raising:
merge base [128.0]
this PR [ 8.0]
device_indices comes from get_parent_visible_gpu_ids(), which parses HIP_VISIBLE_DEVICES / CUDA_VISIBLE_DEVICES with no clamp against torch's device count, and otherwise from get_physical_gpu_count(), which on ROCm counts amd-smi's devices rather than HIP agents. test_inventory_skips_a_device_that_fails_to_enumerate (tests/test_system_poll_no_cuda_context.py:226) already pins that this path is live; none of the four new tests exercise it.
Build the flags from the probes that succeeded:
_probed = [p for _, _, p in props_list if p is not None]
if IS_ROCM and len(_probed) >= 2:
unified_flags = [bool(_rocm_classify_unified_memory(p)[1]) for p in _probed]Same block, second failure mode: the whole comprehension sits under one try on line 1228, so a single props object that raises on attribute access collapses the decision for the entire set. [dGPU, iGPU, bad props] returns [16.0, 24.0, 4.0] with a ROCm hybrid-set classification failed debug line, meaning the fix silently does not apply. Classifying per device contains it.
studio/backend/utils/hardware/hardware.py:2448 - get_visible_gpu_utilization now answers 0.5 or 24.0 for the same device depending on whether amd-smi is on PATH
The amd-smi branch runs first and reaches _reconcile_rocm_unified_memory; only when it returns None does the Linux sysfs branch on line 2525 run, and that is the branch the PR changes. Same Linux host, same function, 6 GiB resident on the iGPU:
this PR, amd-smi absent [(0, 16.0, 1.0), (1, 0.5, 0.11)]
this PR, amd-smi present [(0, 16.0, 1.0), (1, 24.0, 6.0 )]
merge base, either [(0, 16.0, 1.0), (1, 24.0, 6.0 )]
48x apart on total, 55x on used, decided by tool availability. Both feed /api/train/hardware/visible, auto_select_gpu_ids (line 3293) and routes/training_vram.py:27-35, so this is not display only.
The sysfs branch is reached because the inventory total changed. _rocm_system_wide_vram_by_index's tolerance check on line 2403 exists, by its own comment on lines 2397-2402, to catch "a unified-memory APU (sysfs sees only the dedicated slice, torch the GTT pool)". With the inventory now reporting the dedicated slice, 0.5 matches 0.5, the check stops firing for the case it was written for, and mem_info_vram_used (VRAM heap only, no GTT) becomes the reported usage.
studio/backend/utils/hardware/hardware.py:1229 - the fix only lands when the runtime fills is_integrated, and nothing establishes that it does on the reported host
_rocm_props_total_is_carve_out reaches the substitution three ways: the classifier says unified, or the classifier says discrete but the runtime is not trusted to have filled the flag (hip < 6.2, or the attribute absent), or the classifier raised. The new gate cancels only the first, because unified_flags needs a positive classification.
The reported device is "AMD Radeon(TM) Graphics", which is not in the name table at core/training/worker.py:1743-1749, and a desktop Ryzen iGPU's arch is not in {gfx1150, gfx1151, gfx1152}, so props.is_integrated is the only thing that can trip the branch. Reporter's hip 7.13, dGPU gfx1201 16 GiB, iGPU 0.5 GiB carve-out / 36 GiB GTT:
props.is_integrated merge base this PR
1 [16.0, 36.0] [16.0, 0.5]
0 [16.0, 0.5] [16.0, 0.5]
absent [16.0, 36.0] [16.0, 36.0]
Only the first row is a fix. The third is the case _rocm_props_total_is_carve_out's docstring calls out by name on line 1168 ("a gfx1103 Phoenix iGPU on a runtime that leaves the flag at 0 reads as discrete"). Nothing in the repository establishes that a Radeon wheel populates hipDeviceProp_t.integrated; what it does record is that this wheel family leaves version.hip unset (line 1146) and may not populate the arch attributes (core/training/worker.py:1712-1713).
Separately, the "Root cause" section describes code the reported build never ran. _torch_get_device_inventory and _rocm_props_total_is_carve_out were added on 2026-08-13 by 44a05f349 (#8677); the reporter was on v0.1.51-beta, tagged 2026-07-29, where get_backend_visible_gpu_info went through _torch_get_per_device_info and called mem_get_info for every device unconditionally. The 36 GiB in the screenshot therefore fixes the value of hipMemGetInfo's total and says nothing about props.total_memory or props.is_integrated. A log line or a props dump from a real hybrid ROCm host would settle which row above applies.
studio/backend/utils/hardware/hardware.py:1201 - the function's docstring now states the opposite of what it does
Lines 1201-1204 still read "props.total_memory is the same number mem_get_info returns as its total half everywhere except a ROCm APU ... so totals are unchanged." The hybrid iGPU is now precisely a device where the inventory total is deliberately not the mem_get_info total, and line 2527 feeds that total into a comparator that assumes it describes the device's allocatable scope.
studio/backend/utils/hardware/hardware.py:1247 - the classifier runs five times for two devices
_rocm_props_total_is_carve_out on line 1244 already classifies props, the comprehension on line 1230 classified it, and line 1248 classifies it a third time. Counted on a two-device host: 5 calls. unified_flags is already indexed the way the loop iterates, so zip it with the probes and drop the re-import and the except Exception: pass.
studio/backend/tests/test_system_poll_no_cuda_context.py:315 - test_inventory_discrete_rocm_set_untouched cannot fail for the reason its comment gives
The comment says "nothing unified, no correction, driver totals stand", but _rocm_inventory_mod is fed gtt_total == total_memory for both discrete entries (16/16, 24/24), so [16.0, 24.0] holds whether or not the correction fires. Forcing _rocm_props_total_is_carve_out to return IS_ROCM for every device leaves this test green; only the pre-existing test_rocm_discrete_inventory_stays_context_free (line 426) fails. That test already has the honest form on line 429: mod.mem_get_info = lambda o: pytest.fail(...).
mem_get_info is also never reached in the two hybrid tests, because hip 6.2 plus a present is_integrated makes _rocm_props_total_is_carve_out False for the discrete member. The gtt_total column is inert for every discrete row in all four new cases.
Two terms of the new gate are unpinned as a result. if not (hybrid_rocm and integrated) on hardware.py:1251 passes the whole suite when reduced to if not hybrid_rocm, and when integrated is hardcoded to True. Reaching that branch needs a device the classifier calls discrete while _rocm_props_total_is_carve_out still says carve-out: hip 6.1 with [gfx1201 dGPU, gfx1150 iGPU, gfx1103 Phoenix iGPU] gives [16.0, 0.5, 24.0] today and [16.0, 0.5, 0.5] under either mutant.
|
Thanks @danielhanchen for confirming the bug, and @mahiatlinux for the detailed review — all three points are valid and I will address them:
Will push a revised version addressing these. |
Reply to mahiatlinux's review of unslothai#9198 (8 points): 1. Row self-contradiction: the occupancy path (_reconcile_rocm_unified_memory) now keeps the carve-out for the hybrid integrated member too, so /api/system rows no longer show used/free beyond total and the answer no longer flips with amd-smi availability. 2. Strix Halo GTT loss: the skip now excludes the genuine shared-pool arches (gfx1150/51/52 + Radeon 8xxM/80xxS names); only a flag-classified desktop iGPU keeps its carve-out in a hybrid set. 3. Failed probe -> false hybrid: hybrid detection now builds flags from probed devices only, and classifies each device in its own try so one bad props object cannot collapse the whole set. 4. get_visible_gpu_utilization inconsistency: same carve-out gate applied on the amd-smi branch, matching the sysfs branch (both report the carve-out). 5. is_integrated reach: per-device debug log records name/arch/is_integrated/ classification so a real hybrid host can confirm which path applies. 6. Docstring no longer claims totals are unchanged everywhere. 7. Classifier now runs once per device (was up to 3x per device). 8. Tests: hybrid fixtures use gfx1103 (desktop iGPU) instead of gfx1150 (Strix Point), discrete test uses gtt != total so it can actually fail, and new tests pin the hybrid_rocm / integrated / genuine-arch gate terms (APU-only flag-classified, hip 6.1 positive-classification, Strix+dGPU). 36 passed / 3 skipped in test_system_poll_no_cuda_context.py.
|
Thanks @mahiatlinux — this is a thorough review, and you're right that my earlier summary understated it. Pushed 1. Device row self-contradiction — the hybrid gate now also sits on the occupancy path: 2. Strix Halo GTT loss — the skip now excludes the genuine shared-pool arches (gfx1150/51/52 and the Radeon 8xxM/80xxS name table). A Strix Halo beside a dGPU keeps its 128 GiB GTT pool; only a driver-flag-classified desktop iGPU keeps the carve-out. 3. Failed probe → false hybrid — hybrid detection builds flags from successfully probed devices only ( 4. amd-smi availability flip — with the occupancy path fixed (point 1), 5. is_integrated reach — you're right that nothing establishes the wheel populates the flag. Added a per-device debug log (name / arch / is_integrated / classification result) so a real hybrid ROCm host can confirm which row of your table applies; I can't verify hardware behavior from a checkout. I also fixed the PR's root-cause section, which described code the reported build (v0.1.51-beta) never ran. 6. Docstring — 7. Redundant classification — the classifier now runs once per device ( 8. Tests — fixtures fixed: the hybrid tests now use gfx1103 (a desktop iGPU) instead of gfx1150 (Strix Point, a genuine shared-pool arch), 36 passed / 3 skipped in |
|
Confirmed this hits studio/backend/utils/hardware/hardware.py where the carve-out to GTT substitution still fires for the integrated device with a discrete card present, and the occupancy path now agrees with the inventory path. The direction is right, but _rocm_hybrid_keeps_carve_out re-lists the gfx1150/51/52 and Radeon 8xxM name table that _rocm_classify_unified_memory already owns in core/training/worker.py; could you have the classifier return that answer instead of keeping a second copy here? |
|
Thanks @danielhanchen — agreed. I'll remove the second name table copy in |
|
Checked the revision and the both-endpoints gate in _reconcile_rocm_unified_memory now matches the inventory path, with the shared-pool arches exempted so a Strix Halo beside a discrete card keeps its GTT total. Could you update the Scope section of the description, which still says _apply_unified_memory_correction is not touched? |
Reply to danielhanchen's review of unslothai#9198: _rocm_hybrid_keeps_carve_out re-listed the gfx1150/51/52 arches and the Radeon 8xxM/80xxS name table that _rocm_classify_unified_memory already owns in core/training/worker.py. The classifier now returns a third answer, is_shared_pool (genuine shared-pool arch: GTT is the real VRAM), computed before the is_integrated early return so a Strix Halo reports it even with the driver's integrated flag set. _rocm_hybrid_keeps_carve_out consumes classification[2] and no longer carries a second copy of the table; all callers were updated to the 3-tuple, and TestSharedPoolFlag pins the flag-only-APU (unified but not shared-pool) vs genuine arch distinction. Tests: test_rocm_oom_guard.py 160 passed, test_system_poll_no_cuda_context.py 36 passed / 3 skipped.
|
Hi @danielhanchen — both points addressed:
Validation: |
|
Confirmed the hybrid gate now sits on both paths, with the shared-pool arches exempted via the classifier's new is_shared_pool answer in core/training/worker.py, so the second name table is gone and the Scope section matches the code. Will get this reviewed. |
|
Thanks for this, and for working through both review rounds so thoroughly. Closing it, because main moved in two ways since August that a rebase can't get past.
What's still open on #8942 after #11366 and #11871 (the iGPU row labelling the shared pool) is tracked there. |
Fixes #8942
Problem
On hosts where an integrated Radeon and a discrete Radeon are both visible to ROCm (e.g. a Ryzen iGPU beside a desktop dGPU),
_torch_get_device_inventoryreplaced the integrated part's carve-out total with themem_get_infoGTT/shared pool, so Studio's About page / hardware specs reported system RAM (e.g. 24 GB) as the iGPU's VRAM capacity.Root cause
The carve-out→GTT correction exists so unified-only APU hosts (Strix Halo etc.) budget their whole usable pool. It was applied unconditionally to every carve-out device, including the integrated member of a hybrid set, where the GTT pool is not the card's real VRAM.
Fix
IS_ROCM+ ≥2 devices + mixed unified/discrete classification via the existing_rocm_classify_unified_memory).test_system_poll_no_cuda_context.py.Scope
Both memory-reporting endpoints now apply the same hybrid gate, so
/api/systemdevice rows stay self-consistent (used/free never exceed total):_torch_get_device_inventory(via_rocm_props_total_is_carve_out+_rocm_hybrid_keeps_carve_out)_apply_unified_memory_correction→_reconcile_rocm_unified_memorynow skips the GTT adoption for the hybrid integrated member, so the two endpoints agree on the same carve-out totalThe shared-pool arches (Strix Point gfx1150/51/52, Radeon 8xxM/80xxS) are exempted from the carve-out skip, so a Strix Halo beside a discrete card keeps its GTT pool.
Not touched:
amd-smipolling, llama.cpp backend, telemetry (_torch_get_per_device_info) — those keep GTT semantics on real APU machines.