Skip to content

Count a unified-memory APU's window as shared host memory, not dedicated VRAM - #11366

Merged
danielhanchen merged 7 commits into
mainfrom
fix/unified-memory-apu-counted-as-dedicated-vram
Sep 21, 2026
Merged

danielhanchen merged 7 commits into
mainfrom
fix/unified-memory-apu-counted-as-dedicated-vram

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

What this is

gpuMemoryTotalsGb splits the dedicated and shared pools on shared_memory alone. hardware.py sets that flag only on Windows, so on Linux the very same ROCm APU arrives as unified_memory: true, shared_memory: false, and its GTT window is counted as VRAM standing beside system RAM rather than as a view into it.

The sibling helper in the same file already says so:

hardware.py sets shared_memory only on Windows, so on Linux the very same APU arrives as unified_memory: true, shared_memory: false. Reading only sharedMemory there counts the APU's carved window as VRAM standing BESIDE system RAM, when it is a view INTO it.

and use-model-memory.ts records the consequence in as many words:

Known gap: a ROCm APU reports its whole GTT pool and is not flagged as shared.

Measured

On a Strix Halo gfx1151 box (Radeon 8060S). Its ROCm inventory reports memory_total_gb 64.0, shared_memory false, unified_memory true, on a machine with 122.2 GiB of RAM. Settings > System, rendered from that reading:

VRAM tile
before 1% 0.89 GiB / 64 GiB 63.1 GiB free
after 1% 0.89 GiB / 0 GiB VRAM + 64 GiB shared 63.1 GiB free

A discrete card beside such a part was worse. 16 GiB of real VRAM and a 48 GiB window read as one 64 GiB pool, which is the overinflated iGPU VRAM that keeps being reported (#8942, #8847, #7449).

inventory before after
Strix Halo APU alone dedicated 64, shared 0 dedicated 0, shared 64
discrete 16 GiB + APU 48 GiB dedicated 64, shared 0 dedicated 16, shared 48
Windows APU (flag already set) dedicated 24, shared 44 unchanged
discrete B200 dedicated 179.06, shared 0 unchanged

Approach

Fold the two flags inside gpuMemoryTotalsGb rather than at each call site. Every caller that had learned this rule folded on its own way in: use-gpu-info for the system RAM subtraction, memory-fit for the independent total, resolveMemoryCapacityGb for the capacity ceiling. Folding in one place fixes the callers that had not. For a SINGLE device, folding an already-folded flag returns it unchanged, so it is a no-op for the callers that had. It is NOT a no-op for several unified devices, because the fold erases the distinction between one host pool and a pool per socket, so no caller pre-folds any more: they hand in the raw flags and gpuMemoryTotalsGb and budgetedGpuMemoryGb apply the same rule. Reported by @ItsRoy69, whose point was that the earlier version left the capacity path answering 48 GiB for the inventory the totals path called 96.

What does not move

The split changes; the aggregate does not. Every fit verdict is measured against the total, so a change there would be a change to what the app agrees to load.

Swept exhaustively rather than argued: gpuMemoryTotalsGb over 1728 inventories, every combination of memory_total_gb, shared_memory, unified_memory and shared_memory_host_backed_gb including the malformed and absent ones, crossed with three inventory shapes, run on main and on this branch.

cells                                  1728
identical                              1593
changed, split only                     135
cells where the aggregate total moves     0
changed outside unified && !shared        0

Every one of the 135 has unified_memory: true and shared_memory not true. The 1593 that do not move include the 270 with no usable total and the 27 reporting shared_memory_host_backed_gb: 0, which correctly stay dedicated.

resolveMemoryCapacityGb returns the same 122.2 GiB ceiling on both sides, because it already folded unified_memory itself. Vulkan iGPUs, Windows APUs, discrete cards and empty inventories render byte-identically, asserted per case.

The first push of this branch did NOT hold that invariant, and the sweep is how it was caught. Folding unified_memory into the shared bucket also put those devices under the pool collapse, where the largest shared reading is taken as the whole pool. That rule exists for duplicate Vulkan ICD rows describing one physical device. unified_memory alone says only that a device shares memory with its own cpu, which on a multi-socket unified node is a pool per socket, so two 16 GiB devices reported 16 GiB instead of 32 and a four-socket node would have read as a single card. The second commit keeps the collapse for devices carrying shared_memory, and leaves unified_memory devices additive, which is also how they were counted before being classified as shared at all.

What does move, deliberately

On a mixed host the model memory bar now budgets against the discrete card's 16 GiB rather than 64 GiB that includes system RAM. use-model-memory picks dedicatedMemoryTotalGb when it is below the aggregate; previously the two were equal on such a host, so it fell back to the inflated figure. Smaller and truthful is the intended direction here.

Tests

studio/frontend/tests/unified-memory-apu-totals.test.ts, 11 tests built from the measured readings above. They cover the Linux APU, the mixed host, the multi-socket unified host, duplicate shared rows, the Windows shape, the discrete-only host, the flag matrix, the single-device fold-idempotency property, the aggregate-survives property, and the two cross-call-site cases: every surface agrees on a multi-socket unified host, and a genuine single host pool is still counted once. They are not testing their own fixtures: 4 of the first 9 fail on main, and the cross-call-site test fails against this branch's own previous head.

Full frontend suite: 8002 pass 0 fail on main, 8011 pass 0 fail here, same failing set (empty). npm run typecheck, npm run i18n:check:strict, eslint and npm run build all clean. The new tests also pass on node 22.12.0, the version CI pins.

Relationship to the open iGPU work

Independent of #11305 and #11306, which both concern the Vulkan inference inventory and the Unknown VRAM tile. This is the ROCm torch inventory and the dedicated/shared split, and it touches no file either of them touches. The Vulkan path renders identically before and after, checked rather than assumed.

Related in subject to #10283, which fixes the same class of error for integrated NVIDIA parts on the budgeting side.

Not covered

No integrated NVIDIA or Intel part was available to read. The Windows ROCm shape is exercised from its reported values rather than from a Windows box, since the AMD Windows runners carry no ROCm torch.

What it looks like

Two isolated Studio installs, one built from this branch's merge base and one from its head, driven by the same Playwright scene. This box has no unified-memory APU, so both installs were served the gpu block a Strix Halo gfx1151 box (Radeon 8060S) really reported under ROCm on Linux, captured on the self-hosted AMD runner: memory_total_gb 64.0, shared_memory false, unified_memory true, vram_used_gb 1.12. Everything else in the payload is each install's own live reading, and both sides received the identical injection, so the only thing that can differ between the halves is the code under test.

System panel, merge base against head

The VRAM tile, closer:

VRAM tile, merge base against head

merge base 3481bb393 head
VRAM tile 1.12 GiB / 64 GiB 1.12 GiB / 0 GiB VRAM + 64 GiB shared
free reading 62.9 GiB free 62.9 GiB free
GPU devices row Radeon 8060S Graphics, 1.12 GiB used, 62.9 GiB free, 64 GiB total identical

Three things about the pair worth saying plainly. Re-shot after #11305 merged, so the BEFORE half now contains it. That is the interaction check, and it passes: the tile label stays VRAM on both halves rather than becoming GPU MEMORY, because a ROCm APU reports index_kind: physical and so never satisfies #11305's index_kind === "vulkan" && shared_memory === true predicate. The two changes describe different devices and do not overlap on this surface.

The CPU and RAM tiles differ (10% against 0%, 216.4 GiB against 221.7 GiB) because those are wall clock on a shared machine, not anything this change touches. At the settings dialog's fixed width the longer label ellipsises to 0 GiB VRAM + 64 GiB shar... in the tile itself; that is the existing truncation on that tile, which a Windows APU already reached, and the GPU devices row underneath carries the full figures. And the live backend both installs reported before the injection was cuda on both sides, which is what proves each Studio really served the replayed reading rather than photographing this host's own cards.

…ted VRAM

gpuMemoryTotalsGb split the dedicated and shared pools on shared_memory
alone. hardware.py sets that flag only on Windows, so on Linux the very same
ROCm APU arrives as unified_memory: true, shared_memory: false, and its GTT
window was counted as VRAM standing beside system RAM rather than as a view
into it.

Measured on a Strix Halo gfx1151 box (Radeon 8060S), whose ROCm inventory
reports memory_total_gb 64.0, shared_memory false, unified_memory true on a
machine with 122.2 GiB of RAM:

  before   VRAM   1%   0.89 GiB / 64 GiB
  after    VRAM   1%   0.89 GiB / 0 GiB VRAM + 64 GiB shared

A discrete card beside such a part was worse: 16 GiB of real VRAM and a
48 GiB window read as one 64 GiB pool, which is the iGPU with overinflated
VRAM that keeps being reported.

Every caller that had learned this folded the two flags on its own way in:
use-gpu-info for the system RAM subtraction, memory-fit for the independent
total, resolveMemoryCapacityGb for the capacity ceiling. Folding inside
gpuMemoryTotalsGb instead fixes the callers that had not, and is a no-op for
the ones that had, since folding an already-folded flag returns it unchanged.

The split moves and the aggregate does not. Every fit verdict is measured
against the total, and it is unchanged in each case: 64 stays 64 for the
single APU, 16 + 48 stays 64 for the mixed host. resolveMemoryCapacityGb
returns the same 122.2 GiB ceiling before and after, because it already
folded unified_memory itself.

One behaviour does change beyond the label, and it is the point: on a mixed
host the model memory bar now budgets against the discrete card's 16 GiB
rather than 64 GiB that includes system RAM. use-model-memory records the
old state in as many words, "Known gap: a ROCm APU reports its whole GTT
pool and is not flagged as shared".

Windows APUs, discrete cards, Vulkan iGPUs and empty inventories are
untouched, asserted per case.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-20T13:35:23.145642Z 539e69a Manual request
🔒 Security Review ✅ Completed 2026-09-20T07:38:19.419503Z c80d174 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52c38a062a

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

);
const sharedPool = devices
.filter((device) => device.shared_memory)
.filter(sharesHostMemoryDevice)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Aggregate unified-pool telemetry with the same rule

When multiple unified_memory devices expose the same host pool—the case covered by the new “two views” test—this now collapses their capacity to the largest view, but the live-monitor paths still aggregate telemetry additively: resources-tab.tsx:282-291 sums each device's free memory and resolveGpuVramUsedGb in gpu-vram.ts:381-382 sums each device's usage. For two 48 GiB views reporting 40 GiB free each, the UI therefore displays 80 GiB free against the new 48 GiB total, while duplicated usage can also produce an incorrect percentage. The free/used aggregation needs to follow the shared-pool semantics whenever these newly classified devices are present.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct against the commit this was reviewed on, and fixed in 1b92fdd before it came in.

52c38a0 put unified-only devices under the same largest-view collapse that shared_memory devices get, so your two-views case did read 48 GiB total against 80 GiB free. That collapse is wrong for them for a second reason too: unified_memory alone only says a device shares memory with its own CPU, so a multi-socket unified node (MI300A class) has one pool per socket and would have reported as a single card. 1b92fdd keeps the collapse for shared_memory, which does mean "this budget IS the host pool", and leaves unified_memory-only devices additive.

Measured on the same inventory, two 48 GiB unified views reporting 40 GiB free each:

state totals used free
main 3481bb3 dedicated 96, shared 0, total 96 16 80
52c38a0 dedicated 0, shared 48, total 48 16 80
head 1b92fdd dedicated 0, shared 96, total 96 16 80

So the free/used aggregation in resources-tab.tsx and resolveGpuVramUsedGb now sees the same total it saw on main for every inventory this PR reclassifies. A 1728-cell enumeration over the two flags, the host-backed field and the inventory shape confirms it: 135 cells change the dedicated/shared split, 0 change the aggregate.

The one place the mismatch you describe is still live is two devices that already carried shared_memory: true, which reads total 48 against free 80. That is identical on main and on this branch, so it is pre-existing rather than something this PR reaches, and fixing it means changing the telemetry path for the Vulkan duplicate-ICD case that two other open PRs are working in. Leaving it out of this one deliberately.

@danielhanchen

Copy link
Copy Markdown
Member Author

Ran this on the Strix Halo DevLab pool, base against head, so the before column is a real render of the old code rather than an argument about it.

amd-ci-pr11366, Linux gfx1151, states base 3481bb3, head 52c38a0, merge e9237bb.

The device the runner actually reported, read from get_backend_visible_gpu_info() in each state's own checkout:

name=Radeon 8060S Graphics  index_kind=physical
shared_memory=False  unified_memory=True  memory_total_gb=64.0

That is the shape this change is about: unified, not flagged as shared, and a 64 GiB window on a machine with 122.2 GiB of RAM.

Rendering each state's own resources-tab.tsx against that reading:

state VRAM tile capacity
base Unknown / 64 GiB
head Unknown / 0 GiB VRAM + 64 GiB shared

Verdict CONFIRMED: the defect reproduces at the base and is absent at the head. The harness fails VOID rather than passing when the base arm does not show the defect, which is the case that would otherwise make a green head leg meaningless.

Two things worth stating precisely about that table:

  • The Unknown / prefix is the probe, not the app. get_backend_visible_gpu_info() carries no per-device usage figure, since live occupancy comes from the utilization endpoint, and the probe renders the inventory alone. On a running Studio that prefix is the real reading, 0.89 GiB on this box. The capacity label after the slash is what this change moves, and that is what the differential judges.
  • The Vulkan inventory is byte-identical at both states, asserted as a gate rather than assumed. This touches the torch inventory only, so it does not collide with the two open Vulkan iGPU PRs.

What this host cannot answer, carried through from the run rather than written by hand: discrete GPU, multi GPU, NVIDIA, Intel XPU, Apple MLX, Windows, and Windows Docker. The Windows half of the pool is reachable with the Windows selector, but those boxes carry no ROCm torch, so the ROCm inventory this change reads is not available there.

@danielhanchen

Copy link
Copy Markdown
Member Author

Confirmed the split in studio/frontend/src/hooks/gpu-vram.ts still keys on shared_memory alone while the rest of that file already folds unified_memory through sharesHostMemory, so a Linux ROCm APU's window lands in dedicated VRAM. Will get this reviewed.

Folding unified_memory into the shared bucket also put those devices under the
pool collapse, where the largest shared reading is taken as the one pool. That
rule was written for duplicate Vulkan ICD rows describing one physical device.
unified_memory alone says only that a device shares memory with its own cpu,
which on a multi-socket unified node is a pool per socket, so collapsing them
reported a four-socket node as a single card.

An exhaustive sweep of the function over 1728 inventories found 45 cells where
the aggregate moved, all of them two unified devices: 32 GiB became 16. The
aggregate is what every fit verdict is measured against, so that is a change to
what the app agrees to load, and it was not the point of this change.

Devices carrying shared_memory still collapse, since that flag means the budget
IS the host's own pool. Devices classified only by unified_memory stay additive,
which is also how they were counted before they were classified as shared at
all. The same sweep now reports 0 cells where the aggregate moves, and 135
where only the split does, every one of them inside the declared predicate.
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Sep 20, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

Ran the simulation over this branch rather than only over the case it was written for, and it found a defect in my own first push. Fixed in 1b92fdd and re-proved below.

What was wrong

Folding unified_memory into the shared bucket also put those devices under the pool collapse, where the largest shared reading is taken to be the whole pool. That rule exists for duplicate Vulkan ICD rows describing one physical device. unified_memory on its own says only that a device shares memory with its own cpu, which on a multi-socket unified node is a pool per socket. Two 16 GiB unified devices reported a 16 GiB total where main reported 32, and a four-socket node would have read as a single card.

The aggregate is what every fit verdict is measured against, so that was a change to what the app agrees to load, and it was not the point of this change.

How it was caught

gpuMemoryTotalsGb is pure, so it was swept exhaustively on both arms rather than sampled: memory_total_gb in {0, 16, 64, 179.06, absent, NaN, Infinity, -1}, shared_memory in {true, false, absent, null}, unified_memory in {true, false, absent}, shared_memory_host_backed_gb in {absent, null, 0, 24, 100, -1}, crossed with a device alone, beside a discrete card, and twinned. 1728 inventories.

first push 52c38a0 corrected 1b92fdd
cells per arm 1728 1728
identical to main 1593 1593
changed, split only 90 135
cells where the aggregate total moves 45 0
changed outside unified && !shared 0 0

The fix

Devices carrying shared_memory still collapse, since that flag means the budget is the host's own pool. Devices classified only by unified_memory stay additive, which is also how they were counted before they were classified as shared at all. No inventory loses capacity by being read correctly.

Tests grew the multi-socket case, a duplicate-shared-rows case, and an explicit property that the aggregate equals the old dedicated sum for every shape. 9 tests, 4 of which fail on main. Full suite 8011 pass 0 fail, typecheck, eslint and build clean, and the new tests also pass on node 22.12.0.

Re-proved on hardware

amd-ci-pr11366 re-run against the corrected head, states base 3481bb3, head 1b92fdd, merge eb8a56c:

state VRAM tile capacity
base Unknown / 64 GiB
head Unknown / 0 GiB VRAM + 64 GiB shared

CONFIRMED, with the Vulkan inventory byte-identical at both states.

What I could not prove

No multi-socket unified host exists on this pool, so the case above is enumerated and reasoned from the device semantics rather than measured on an MI300A node. No integrated NVIDIA or Intel part was available either; both already carry shared_memory, so the sweep says they do not move, but that is from their reported shape rather than from the hardware.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c80d174480

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +88 to +91
perDevice:
device.shared_memory === true
? totals.perDevice
: totals.perDevice + hostBacked,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve per-socket pools through pre-folded callers

When an inventory contains multiple unified_memory: true, shared_memory: false devices, this branch correctly adds their per-socket pools only while the raw shared_memory value remains false. However, use-gpu-info.ts:143-150 and both mappings in resolveMemoryCapacityGb (gpu-vram.ts:259-267 and 302-310) first fold each device to shared_memory: true and omit unified_memory, so those paths still collapse two 48 GiB pools to 48 GiB. This leaves systemRamAvailableGb overstated and makes a pin covering both devices report only half its GPU capacity; preserve the raw flag distinction through these callers rather than pre-folding it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked both halves of this by measuring, and neither figure moves against main, so there is nothing here this branch introduces. One of the two mechanisms named is also not the one that produces the effect.

resolveMemoryCapacityGb. Removing the pre-fold at both mapping sites and passing the raw flags through leaves gpuCapacityGb at 48 for a pin covering two 48 GiB unified devices. The collapse is not the pre-folding: budgetedGpuMemoryGb does its own sharedPool = Math.max(sharedPool, hostBacked) over anything sharesHostMemory accepts, so the figure is 48 whichever shape it is handed. Main reports 48 for the same inventory.

use-gpu-info.ts. Here the mechanism is right, but the fold is load-bearing rather than redundant, and the value is unchanged:

gpuSharedHostMemoryGb argument main 3481bb3 head c80d174
pre-folded, as the call site does today shared 48, systemRamAvailable 80 shared 48, systemRamAvailable 80
raw, if the fold were removed shared 0, systemRamAvailable 128 shared 96, systemRamAvailable 32

On main the raw row subtracts nothing at all, which is the bug the fold was added for. At head the fold is no longer required for a single APU but still collapses a multi-socket one, and 80 is what both states report.

So the residual is real but predates this PR and sits in budgetedGpuMemoryGb, not in the branch under review. Taking it separately rather than here: it is a fit-verdict path, the only hardware that reaches it is a multi-socket unified node, and I have none to measure it on, so it deserves its own change with its own evidence instead of riding along on a display fix that is proven not to move any budget.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: c80d174480

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 20, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 20, 2026
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Sep 20, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: c80d174480

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 35cd459bc5

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ItsRoy69

Copy link
Copy Markdown
Contributor

Hey @danielhanchen noticed something small, I see it correctly treats pure unified-memory devices as additive (so two 48 GiB sockets stay 96) but on the capacity path we fold both flags into shared_memory first, and that path then collapses them to the max (48). Same inventory, different totals depending on the call site. The new fold test only covers a single device, so this doesn’t show up there. Might be worth aligning those paths or adding a multi-device case to the test I guess

The capacity path folded both flags into shared_memory before calling in, and
budgetedGpuMemoryGb then collapsed those devices to the largest view, so a pin
covering two 48 GiB sockets reported 48 GiB while the totals path reported 96.
Pass the raw flags and give budgetedGpuMemoryGb the same rule gpuMemoryTotalsGb
uses: shared_memory is one host pool and collapses, unified_memory alone is a
pool per socket and stays additive.

Reported by ItsRoy69.
@danielhanchen

Copy link
Copy Markdown
Member Author

Good catch @ItsRoy69, and you are right on both halves of it. Fixed in 539e69a.

The divergence reproduced exactly as you described. Same inventory, two 48 GiB unified sockets, asked three ways at the old head:

call site answer
gpuMemoryTotalsGb, raw flags total 96
gpuMemoryTotalsGb, pre-folded total 48
resolveMemoryCapacityGb gpuCapacityGb 48

Your second point is the one I am more grateful for. The fold test loops over devices but always calls gpuMemoryTotalsGb([preFolded]) with a single element array, so it could only ever prove idempotence for one device, and folding is not idempotent for several. The PR description claimed it always is, which was too broad; that is corrected now.

One thing worth recording, because it caught me out. Removing the pre-fold alone does not fix it. I tried exactly that first and measured no change to gpuCapacityGb, because budgetedGpuMemoryGb does its own Math.max(sharedPool, hostBacked) over anything sharesHostMemory accepts, so it collapsed them again whatever shape it was handed. The fix needs both halves: the call sites pass the raw flags, and budgetedGpuMemoryGb learns the same rule gpuMemoryTotalsGb uses, namely that shared_memory means one host pool and collapses while unified_memory alone is a pool per socket and stays additive.

After the fix, all three read 96, and the RAM tier subtracts 96 rather than 48 on that host.

Two tests were added: one asserting every call site agrees on a multi-socket unified host, which fails without the fix, and one asserting the genuine one-pool case (duplicate Vulkan ICD rows) still collapses to 48, so the widening did not go too far.

Blast radius, measured rather than argued: the 1728 cell enumeration over the two flags, the host-backed field and the inventory shape reports 0 cells where gpuMemoryTotalsGb moves, since the change is confined to the capacity path. Full suite 8081 pass 0 fail, typecheck, lint, i18n and build clean.

One existing test also had to change, and I want to be explicit about it rather than have it look like a quiet edit. on-device-dot-and-header-alignment.test.ts asserted the literal source string shared_memory: sharesHostMemory({ in use-gpu-info to prove the RAM tier accounts for unified memory. That spelling is exactly what the fix removes, while the behaviour it protects is preserved and improved: the tier subtracts 64 GiB for one APU as before, and 96 rather than 48 for two sockets. The assertion now pins the behaviour, that the raw devices reach gpuSharedHostMemoryGb, plus a guard that nothing pre-folds on the way in.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 539e69a161

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 20, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 20, 2026
@ItsRoy69

Copy link
Copy Markdown
Contributor

@danielhanchen thanks for chasing both halves. The fact that removing the pre-fold alone wasn’t enough and that the new multi-device tests now cover it is exactly what was needed.

@danielhanchen
danielhanchen merged commit f10041a into main Sep 21, 2026
58 of 59 checks passed
@danielhanchen
danielhanchen deleted the fix/unified-memory-apu-counted-as-dedicated-vram branch September 21, 2026 02:31
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…ted VRAM (unslothai#11366)

* Count a unified-memory APU's window as shared host memory, not dedicated VRAM

gpuMemoryTotalsGb split the dedicated and shared pools on shared_memory
alone. hardware.py sets that flag only on Windows, so on Linux the very same
ROCm APU arrives as unified_memory: true, shared_memory: false, and its GTT
window was counted as VRAM standing beside system RAM rather than as a view
into it.

Measured on a Strix Halo gfx1151 box (Radeon 8060S), whose ROCm inventory
reports memory_total_gb 64.0, shared_memory false, unified_memory true on a
machine with 122.2 GiB of RAM:

  before   VRAM   1%   0.89 GiB / 64 GiB
  after    VRAM   1%   0.89 GiB / 0 GiB VRAM + 64 GiB shared

A discrete card beside such a part was worse: 16 GiB of real VRAM and a
48 GiB window read as one 64 GiB pool, which is the iGPU with overinflated
VRAM that keeps being reported.

Every caller that had learned this folded the two flags on its own way in:
use-gpu-info for the system RAM subtraction, memory-fit for the independent
total, resolveMemoryCapacityGb for the capacity ceiling. Folding inside
gpuMemoryTotalsGb instead fixes the callers that had not, and is a no-op for
the ones that had, since folding an already-folded flag returns it unchanged.

The split moves and the aggregate does not. Every fit verdict is measured
against the total, and it is unchanged in each case: 64 stays 64 for the
single APU, 16 + 48 stays 64 for the mixed host. resolveMemoryCapacityGb
returns the same 122.2 GiB ceiling before and after, because it already
folded unified_memory itself.

One behaviour does change beyond the label, and it is the point: on a mixed
host the model memory bar now budgets against the discrete card's 16 GiB
rather than 64 GiB that includes system RAM. use-model-memory records the
old state in as many words, "Known gap: a ROCm APU reports its whole GTT
pool and is not flagged as shared".

Windows APUs, discrete cards, Vulkan iGPUs and empty inventories are
untouched, asserted per case.

* Keep a multi-socket unified host's pools additive

Folding unified_memory into the shared bucket also put those devices under the
pool collapse, where the largest shared reading is taken as the one pool. That
rule was written for duplicate Vulkan ICD rows describing one physical device.
unified_memory alone says only that a device shares memory with its own cpu,
which on a multi-socket unified node is a pool per socket, so collapsing them
reported a four-socket node as a single card.

An exhaustive sweep of the function over 1728 inventories found 45 cells where
the aggregate moved, all of them two unified devices: 32 GiB became 16. The
aggregate is what every fit verdict is measured against, so that is a change to
what the app agrees to load, and it was not the point of this change.

Devices carrying shared_memory still collapse, since that flag means the budget
IS the host's own pool. Devices classified only by unified_memory stay additive,
which is also how they were counted before they were classified as shared at
all. The same sweep now reports 0 cells where the aggregate moves, and 135
where only the split does, every one of them inside the declared predicate.

* Tighten the comments added by this change

* Cut the remaining comments to the facts the code does not state

* Make every call site agree on a multi-socket unified host

The capacity path folded both flags into shared_memory before calling in, and
budgetedGpuMemoryGb then collapsed those devices to the largest view, so a pin
covering two 48 GiB sockets reported 48 GiB while the totals path reported 96.
Pass the raw flags and give budgetedGpuMemoryGb the same rule gpuMemoryTotalsGb
uses: shared_memory is one host pool and collapses, unified_memory alone is a
pool per socket and stays additive.

Reported by ItsRoy69.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants