Skip to content

AMD: Multi-GPU RX 9070 XT w/ RX 480 - GGUF OOM Labels & GPU Memory Controls - #7356

Closed
LeoBorcherding wants to merge 26 commits into
unslothai:mainfrom
LeoBorcherding:fix-oom-labels-vulkan-6414
Closed

LeoBorcherding wants to merge 26 commits into
unslothai:mainfrom
LeoBorcherding:fix-oom-labels-vulkan-6414

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Problem

On a Vulkan llama.cpp build, llama-server can drive GPUs the torch backend cannot see. A user report (dual AMD on Windows: RX 9070 XT on ROCm + RX 480, which is too old for ROCm, via the Vulkan prebuilt) shows llama-server using both cards for inference while Studio behaves as if only one exists:

Root cause: /api/system builds its device list from torch/ROCm (get_backend_visible_gpu_info), and every fit label sums VRAM over that list. The report suggested pulling from llama-server --list-devices; this PR does the equivalent through the ggml Vulkan probe Studio already ships, so no extra server spawn is needed.

Backend

  • _vulkan_probe.py prints a 5th column: ggml's device description (ggml_backend_dev_description), sanitized for the tab protocol.
  • LlamaCppBackend gains _run_vulkan_probe (shared parse, tolerant of 4- or 5-column output), vulkan_device_inventory (names + real totals for the UI), and validate_vulkan_gpu_ids.
  • /api/system reports gguf_devices on Vulkan builds: the llama-server inventory in ggml Vulkan ordinal space, alongside the unchanged torch view in devices. The inventory rides its own 60s cache so /api/system pollers don't respawn the probe subprocess every 10s GPU-cache expiry; model loads keep their own fresh probe.
  • gpu_ids picks on Vulkan builds are now supported instead of hard-400ing: the probe, the picker, and the existing --device Vulkan<i> pin all share one index space, so /load and /validate validate picks against the probed ordinals. XPU behavior is unchanged.

Frontend

  • GpuInfo gains ggufMemoryTotalGb: the sum of llama-server-visible discrete VRAM (iGPUs excluded, their memory is the system RAM already budgeted separately), falling back to the torch total on non-Vulkan builds. All GGUF fit surfaces (hub fit labels, GGUF variant expanders, fits-on-device filters) budget against it.
  • Training and safetensors estimates deliberately stay on the torch total: ROCm training genuinely cannot use a pre-ROCm card, so a 24GB training budget would be wrong.
  • The GPU picker in the model config sheet lists the llama-server devices (both cards, names, per-card VRAM) and allows picks on Vulkan builds.

Tensor parallelism is intentionally untouched; whether row-split TP is worthwhile on a mixed-generation pair is a separate question from device visibility.

Tests

  • Probe: 5-column parse, legacy 4-column compatibility, inventory names/totals/iGPU flag, ordinal validation (in-range, out-of-range, duplicate, unverifiable-empty-probe).
  • /api/system merge: torch view preserved, inventory surfaced, support flag semantics, and no re-probe across GPU-cache refreshes.
  • Existing GPU selection / GPU memory mode / vulkan probe suites pass (178 tests across the five related files).

Verified live on a ROCm host: devices unchanged, gguf_devices empty, picks still supported. The mixed-GPU Vulkan path is covered by the synthetic-probe tests; I don't have a pre-ROCm card to reproduce the reporter's exact hardware.

…r-visible devices

On a Vulkan llama.cpp build, llama-server can drive cards the torch backend
cannot see (e.g. a pre-ROCm RX 480 next to a ROCm-only RX 9070 XT on Windows).
Studio previously built its GPU list only from torch/ROCm, so such cards were
invisible: TIGHT/OOM labels budgeted against half the real VRAM and the unslothai#6414
GPU Memory controls could not offer the second card.

Backend:
- _vulkan_probe.py prints a 5th column with ggml's device description.
- LlamaCppBackend gains _run_vulkan_probe (shared parse, 4/5-column tolerant),
  vulkan_device_inventory (names + real totals for the UI), and
  validate_vulkan_gpu_ids (picks validated in ggml Vulkan ordinal space).
- /api/system reports gguf_devices (the llama-server inventory, Vulkan builds)
  alongside the torch view, and gguf_gpu_ids_supported becomes true when the
  inventory is available: probe, picker, and --device Vulkan<i> pin all share
  one index space, so the old unconditional 400 on Vulkan picks is replaced
  with ordinal validation in /load and /validate.
- The inventory rides its own 60s cache: /api/system pollers (floating
  monitor, Resources tab) keep expiring the 10s GPU cache, and the probe
  spawns a subprocess. Model loads keep their own fresh probe.

Frontend:
- GpuInfo gains ggufMemoryTotalGb (sum of llama-server-visible discrete VRAM,
  falling back to the torch total). GGUF fit surfaces (hub fit labels, variant
  expanders, fits-on-device filters) budget against it; training and
  safetensors estimates stay on the torch total, which training truly has.
- The GPU picker lists gguf_devices (both cards, names, per-card VRAM) and
  allows picks on Vulkan builds.

Tests: probe 5-column parse, inventory, ordinal validation, and the
/api/system merge (torch view preserved, inventory surfaced and cached across
GPU-cache refreshes, support flag).
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

@codex 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: 48dfa33e58

ℹ️ 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".

Comment thread studio/backend/routes/inference.py Resolved
- recommended-fit: only GGUF rows budget against the llama-server total;
  safetensors/MLX rows load through torch, which can't use Vulkan-only cards.
- use-gpu-info: a reported llama-server inventory is authoritative even at
  zero discrete VRAM (all-iGPU case counts as system RAM, not torch dGPU
  VRAM); only a missing inventory falls back to the torch total.
- Training guard: a Vulkan build's gpu_ids (ggml ordinals) are dropped before
  the physical-index free-VRAM sizing, so the load is guarded as unpinned
  instead of resolving the wrong card or skipping protection.
- Persisted picks: remember the pick index space (physical vs vulkan) in
  localStorage; reconcilePersistedGpuIds clears saved picks after a backend
  swap flips the space, where a bare-number membership check would let a
  pick land on a different physical card.
- _vulkan_probe: the name lookup binds in its own best-effort block so a
  ggml-base without ggml_backend_dev_description can't disable iGPU
  detection, and stdout is reconfigured to UTF-8 (reader decodes to match)
  so non-ASCII device names can't kill the probe on cp1252 consoles.

Tests: guard drops/keeps gpu_ids by backend kind (test_chat_load_during_training).

@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: 40c1464d41

ℹ️ 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".

Comment thread studio/backend/routes/inference.py Resolved
Comment thread studio/backend/routes/inference.py Resolved
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

@codex 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: 79eace774d

ℹ️ 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".

Comment thread studio/backend/routes/inference.py Resolved
Comment thread studio/backend/routes/inference.py Resolved
…keep fresh live picks

Codex round-3 follow-ups on the Vulkan llama.cpp GPU-selection path:

- can_load_chat_during_training: add worst_case_gpu_count so a Vulkan pick
  (ggml ordinals with no physical mapping) is sized against the N most-
  constrained visible cards instead of falling back to the whole-pool check,
  which could OK a load that lands on a busy selected card and OOMs training.

- /load and /validate: reject gpu_ids for diffusion GGUFs on a Vulkan build
  with a 400 -- the diffusion runner cannot map ggml Vulkan ordinals.

- reconcilePersistedGpuIds: gate the index-space-change clear behind a new
  fromPersisted flag so a freshly picked live Vulkan selection is not nulled
  for the whole first post-swap session. Persisted PerModelConfig restores
  pass fromPersisted:true; live store reads (send path, unload-restore) do not.
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

@codex 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: d65536268f

ℹ️ 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".

Comment thread studio/backend/routes/inference.py Resolved
The pre-download /load and /validate Vulkan gates rejected gpu_ids whenever
_classify_diffusion_gguf was not False, but None is the ordinary first-load
case for an uncached Hub GGUF (no local header to classify yet). That 400'd
first-time remote GGUF loads and made the new Vulkan GPU picker unusable unless
the model was already cached.

Reject only a CONFIRMED diffusion GGUF (is True) at the gates. For the rare
uncached model that turns out to be diffusion after download, add a spawn-time
backstop in load_model: on a Vulkan build, drop the unmappable gpu_ids pin
before _start_diffusion_server (ggml Vulkan ordinals cannot be forwarded as the
runner's CUDA/DG token) so it serves on the default device instead of the wrong
card. Regression tests cover the relaxed gate and the spawn backstop.

@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: a9afb8011c

ℹ️ 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".

applyPerModelConfigToRuntime runs synchronously on model selection, which can
happen before any GPU hook has fetched /api/system. On a cold cache
reconcilePersistedGpuIds can't tell whether the saved ids belong to the current
llama.cpp backend's index space (physical CUDA/ROCm ids vs ggml Vulkan
ordinals), so it passes them through. That value then launders into the store
and the later load path reconciles it as a live pick (fromPersisted false),
which never clears it -- a saved physical [1] gets sent as Vulkan ordinal 1 and
pins the wrong card.

When the pick is applied cold, warm the cache and re-reconcile with
fromPersisted, overwriting only if the user has not replaced the pick since.
test_compare_load_uses_each_models_gpu_config asserted the exact single-arg
call reconcilePersistedGpuIds(ownConfig.selectedGpuIds); the per-model (persisted)
path now passes { fromPersisted: true } to drop a pick saved under the other
llama.cpp backend's GPU index space. Match the new call and assert the flag.

@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: 6d13f25a76

ℹ️ 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".

Codex round on the fromPersisted marker: it was set on call sites that also
carry fresh, current-space picks, and the cold-cache revalidation raced the
load path.

- applyPerModelConfigToRuntime now takes { fromPersisted } (default false =
  live). Only a config actually restored from storage passes true.
- chat-page load-on-selection passes fromPersisted only for the
  rememberedConfigFor fallback, not an explicit selection.config (fresh Run
  settings / picker edit). Prevents a freshly selected Vulkan ordinal from being
  cleared and loaded on all GPUs.
- shared-composer compare pane gates fromPersisted on (!config && ownRemembered),
  so an explicit sel.config pane pick stays live.
- Cold-cache race: instead of leaking the raw persisted ids into the store
  (where the load path snapshots and sends them before the async revalidation
  runs), park the pick at null (all GPUs, safe) and fill in the validated pick
  once the cache warms. The load snapshot can no longer send a wrong-space pin.

Contract test updated + a regression guard for the storage-only invalidation.

@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: c85e763029

ℹ️ 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".

LeoBorcherding and others added 2 commits July 23, 2026 23:00
The fromPersisted-by-call-site marker kept getting misapplied because those
sites carry both storage restores and fresh live edits, and the cold-cache
park/revalidate raced the load path. Replace it with per-value provenance: each
GPU pick carries the index space it was made under, and reconcile drops it only
when that stamp no longer matches the backend.

- use-gpu-info: currentGpuIndexKind() (from /api/system gguf_devices); drop the
  session-global gpuIndexSpaceChanged marker machinery.
- PerModelConfig gains selectedGpuIdsIndexKind (persisted); the runtime store
  gains selectedGpuIdsKind, stamped wherever a pick is set (live picker = current
  kind, load echo = current kind, config apply = the config's stamp).
- reconcilePersistedGpuIds(ids, savedKind): drop when savedKind != current kind
  (both known); unstamped picks default to physical (pre-Vulkan).
- Run settings stamps the current kind when the user edits the GPU picker, so an
  edited pick is never treated as a stale cross-space restore; an unedited
  stored pick keeps its saved kind.
- No more park-null / async revalidate / fromPersisted: a same-backend refresh
  keeps the saved subset (kinds match), a cross-space pin is dropped, and the
  load snapshot carries the stamp so it can't send a wrong-space pin.

Fixes the three Codex findings (cold-cache saved-pick loss, model-generation
race, unedited run-settings treated as live). Contract tests updated; typecheck
+ build + tests/studio contracts green.

@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: 9bdee5c7f8

ℹ️ 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".

Comment thread studio/backend/routes/inference.py Resolved
Comment thread studio/backend/main.py Resolved
@LeoBorcherding LeoBorcherding changed the title [Bug] AMD: GGUF OOM Labels Multi GPU AMD with RX 480 AMD: GGUF OOM Labels Multi GPU AMD with RX 480 Jul 24, 2026

@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: 715b20561f

ℹ️ 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".

@LeoBorcherding LeoBorcherding changed the title AMD: GGUF OOM Labels Multi GPU AMD with RX 480 AMD: Multi-GPU RX 9070 XT w/ RX 480 - GGUF OOM Labels & GPU Memory Controls Jul 24, 2026
LeoBorcherding and others added 2 commits July 24, 2026 00:59
… budget

- gpuFieldsSignature now folds selectedGpuIdsIndexKind into the pick, so when
  the reactive fallback stamps a cold-hydrated active pick after the GPU cache
  warms, an open Run-settings panel remounts and re-snapshots with the new
  stamp instead of reloading/saving it as a legacy physical pick.
- /api/system reports gguf_backend_is_vulkan so the frontend can tell an empty
  gguf_devices on a Vulkan build (probe failed/masked, budget unknown) from a
  non-Vulkan build. Empty Vulkan inventory now budgets GGUF at 0 instead of the
  torch VRAM total, which on a mixed host would let fit checks pass against VRAM
  /load cannot place.
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

@codex 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: a5d1646989

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member

Pushed a small fix to the diffusion path.

The graceful "drop the unmappable Vulkan pin and serve on the default device" backstop in load_model was unreachable: the hard raise just above it keys on the same is_vulkan_backend and gpu_ids predicate and nothing between them changes either operand, so an uncached Hub GGUF that only classifies as diffusion after download hard-errored instead of falling back. That contradicts the relaxed /load and /validate gate that was added precisely to allow those uncached picks.

Removed the dead raise so the drop is reached, and tightened test_diffusion_vulkan_load_drops_unmappable_gpu_pin to assert no earlier raise can preempt it. A Vulkan ordinal still never reaches the CUDA diffusion runner, since the route already rejects a confirmed diffusion pick up front.

Verified: full backend suite plus the frontend tsc -b && vite build stay green, and non-Vulkan builds are unchanged (empty gguf_devices, torch devices and fit budgets untouched).

… pin stamp

Addresses two Codex P2s on the Vulkan GPU-pin machinery:

- use-gpu-info caches /api/system forever, so after an in-session llama.cpp
  backend swap (update/rebuild) currentGpuIndexKind() kept reporting the pre-swap
  index space until a full reload, stranding physical pins on a now-Vulkan
  backend (or dropping Vulkan pins after a swap back). Add invalidateGpuInfoCache()
  and call it on llama.cpp update success, beside the existing refreshHardwareInfo().

- A /status hydration (or eager picker edit) that beats the first /api/system
  fetch stamped a live pick's index kind null; currentRuntimePerModelConfig then
  serialized it as an unstamped (legacy physical) pick, dropping a real Vulkan
  selection on the next reconcile. Add warmSelectedGpuIdsKind() to warm the cache
  and backfill the kind at the two cold-capable stamp sites (setSelectedGpuIds,
  the /status hydration).
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Pushed follow-ups addressing the two remaining P2s from the last review (commit 81333e1), plus a merge of latest main (4e7c0c2) which clears the Repo tests (CPU) failure (it was text-[11px] in chat-settings-sheet.tsx, fixed on main; this branch was just out of date).

  • Refresh GPU kind after backend swaps: added invalidateGpuInfoCache() in use-gpu-info.ts, called on llama.cpp update success beside the existing refreshHardwareInfo(), so currentGpuIndexKind() and the next reconcile re-probe the new index space instead of stranding pins stamped under the old backend.
  • Unstamped active Vulkan pick: added warmSelectedGpuIdsKind() which warms the /api/system cache and backfills the kind at the two cold-capable stamp sites (setSelectedGpuIds and the /status hydration), so an imperative rollback snapshot no longer serializes a live Vulkan pick as a legacy-physical one.

The diffusion dead-raise P2 was already handled by d95abea. tsc -b and vite build are green.

@codex 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: 81333e166d

ℹ️ 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".

// flips the gpu_ids index space. Drop the separate /api/system GPU
// cache too so currentGpuIndexKind()/the next reconcile re-probe the
// new space instead of stranding pins stamped under the old one.
invalidateGpuInfoCache();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Invalidate the cache on every completed llama update

When another tab misses the running window, it observes the persisted success through surfaceIfAvailable, which only calls notifyReloadIfNeeded; likewise, a chained update whose llama phase lands but whose later whisper phase fails reaches the error branch with reload_required. Neither path executes this invalidation, so a backend swap leaves that tab's physical/Vulkan index kind cached and subsequent loads can retain a pin in the wrong index space. Centralize the refresh/invalidation for terminal jobs whose llama phase required a reload rather than limiting it to the polling success branch.

Useful? React with 👍 / 👎.

Comment on lines +88 to +90
export function invalidateGpuInfoCache(): void {
cachedSystem = null;
systemPromise = null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Clear the server-side GPU caches after a backend swap

If the next load occurs shortly after an update, clearing only this module cache is insufficient: /api/system can still return main.py's pre-swap _system_gpu_cache for 10 seconds (and its Vulkan inventory for 60 seconds). fetchSystemOnce then caches that stale response indefinitely, so reconciliation still sees the old index kind and can send a physical pin as an existing Vulkan ordinal, selecting the wrong card. The update completion path needs to invalidate the backend caches or request an uncached system snapshot.

Useful? React with 👍 / 👎.

Comment on lines +88 to +90
export function invalidateGpuInfoCache(): void {
cachedSystem = null;
systemPromise = null;

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 Notify mounted GPU hooks when invalidating the cache

On an in-session backend swap, this function only clears module variables; already-mounted useGpuInfo, useGpuDevices, and useCurrentGpuIndexKind instances retain their state because their effects run only once and there is no listener or generation subscription. Even if a later load-boundary call refetches /api/system, an open Hub or GPU settings surface continues showing the old VRAM budget/device list and index kind until it unmounts or the page reloads. Invalidation should trigger a refetch and publish the result to mounted consumers.

Useful? React with 👍 / 👎.

Comment on lines +44 to +47
const savedKind: GpuIndexKind | null =
config.selectedGpuIds == null
? null
: (config.selectedGpuIdsIndexKind ?? "physical");

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 the GPU index stamp when applying presets

On a Vulkan host with an explicit GPU selection, applying a chat preset calls applyPresetLoadConfig, which copies store.selectedGpuIds into a PerModelConfig but omits selectedGpuIdsIndexKind. This fallback consequently labels the live Vulkan ordinals as physical; once /api/system is warm, reconcilePersistedGpuIds sees a cross-space mismatch and clears the selection, so the next load unexpectedly uses all GPUs. The preset path must carry store.selectedGpuIdsKind alongside the retained IDs.

Useful? React with 👍 / 👎.

Comment on lines +66 to +70
function systemGpuIndexKind(
data: SystemInfoResponse | null,
): GpuIndexKind | null {
if (!data) return null;
return (data.gpu?.gguf_devices ?? []).length ? "vulkan" : "physical";

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 Derive the index kind from the Vulkan backend flag

When a Vulkan build's device probe transiently fails, /api/system deliberately returns gguf_backend_is_vulkan: true with an empty gguf_devices list, but this function classifies that response as physical. A running Vulkan model hydrated from /status can then have its live ordinal selection backfilled and persisted with the physical stamp, causing it to be discarded or misinterpreted when the probe later recovers. Use the authoritative backend flag for the index space; inventory emptiness only means the ordinal set is currently unverifiable.

Useful? React with 👍 / 👎.

The iGPU exclusion in ggufMemoryTotalGb is right when llama-server is
masked to an iGPU beside a dGPU torch can see, but it also catches the
plain APU case: a Strix Halo or 890M box on a Vulkan build enumerates one
integrated device and nothing else, so the budget collapses to 0 and the
Hub renders "0 GiB" on a machine llama-server reports 91 GiB for. Fit
still resolves via system RAM, so this is a labelling and fit-surface
defect rather than a wrong load, but it reads as OOM on every GGUF row.

Fall back to the torch total when the inventory is all-iGPU and torch sees
no device beyond the ones probed. The device-count check is what keeps the
masked-beside-a-dGPU host on 0, which is the case the exclusion exists for.

Tests: the shape was uncovered (the existing cases are all is_igpu False).
Added a backend test that an iGPU-only inventory is surfaced with its real
total and keeps picks supported, and a source contract guard on the
frontend rule, matching how the other frontend fixes here are pinned.

Verified: frontend typecheck clean (same 5 pre-existing missing-module
errors as main, none new), 211 passed across the vulkan probe, gguf
devices, gpu memory mode, chat-load and model-picker contract suites.
@danielhanchen

Copy link
Copy Markdown
Member

Went through this on a Strix Halo box (Radeon 8060S). That machine runs the ROCm llama.cpp prebuilt, so gguf_devices comes back empty and everything falls through to the torch total, which matches the ROCm-host state you described. The mixed Vulkan path itself I could not exercise, no pre-ROCm card here either.

What I could check held up:

  • All four ggml symbols the probe binds (ggml_backend_dev_description, ggml_backend_dev_type, ggml_backend_reg_dev_count, ggml_backend_reg_dev_get) are exported from the shipped ggml-base.dll, and the description API is in the bundled headers, so the 5th column has something real behind it.
  • _gguf_devices_cache sits inside the existing _system_gpu_cache_lock, and /api/system is a sync def, so it is threadpooled and the probe subprocess cannot block the event loop. The 60s TTL split from the 10s GPU cache is the right call.
  • Frontend typecheck clean, no new errors. 211 passed across the vulkan probe, gguf devices, gpu memory mode, chat-load and model-picker contract suites.

The iGPU-only case renders 0 GiB

Pushed a fix. The iGPU exclusion in ggufMemoryTotalGb is correct for the case you wrote it for, llama-server masked to an iGPU while torch still sees a dGPU it will not use. But it also catches a plain APU box: a Strix Halo or 890M machine on a Vulkan build enumerates one integrated device and nothing else, so ggufDevices.length is truthy, ggufDeviceTotalGb is 0, and the Hub label becomes 0 GiB. On this machine llama-server reports the pool as 91.6 GiB:

$ llama-server --list-devices
Available devices:
  ROCm0: AMD Radeon(TM) 8060S Graphics (91612 MiB, 91452 MiB free)

fitsDevice still resolves through systemRamAvailableGb, so nothing loads wrong, but every GGUF fit surface reads as OOM and the GPU tile says 0 GiB. On main that label shows the torch total, so it is a regression for that hardware shape specifically.

The fix falls back to the torch total when the inventory is all-iGPU and torch sees no device beyond the ones probed. That second condition is what keeps the masked-beside-a-dGPU host on the conservative 0, so the case the exclusion exists for is unchanged.

Worth noting AMD's lemonade takes the opposite approach here and never zeroes: it reports iGPU vram_gb and virtual_mem_gb with an integrated: true flag, then prefers discrete and falls back to integrated at selection time. Not suggesting you rework the budgeting, just that treating an iGPU as 0 VRAM is the part that needed the guard.

Tests

The new test_system_gguf_devices.py cases are all is_igpu: False, so this shape was uncovered. Added a backend test that an all-iGPU inventory is surfaced with its real total and keeps picks supported, plus a source contract guard on the frontend rule in test_model_picker_contracts.py, matching how the other frontend fixes in this PR are pinned.

Rest of the PR looks good to me.

@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: 71619891e0

ℹ️ 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 +90
export function invalidateGpuInfoCache(): void {
cachedSystem = null;
systemPromise = null;

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 Prevent invalidated fetches from restoring stale GPU data

If /api/system is already in flight when a llama.cpp backend swap calls this function, clearing systemPromise does not cancel or invalidate that request. A post-swap read can start a fresh request, but the older request may resolve afterward and unconditionally overwrite cachedSystem at line 100 with the pre-swap physical/Vulkan inventory; because successful snapshots are cached indefinitely, subsequent GPU reconciliation can then use the wrong index space until another update or page reload. Track a cache generation or otherwise ignore completions from promises invalidated here.

Useful? React with 👍 / 👎.

Comment on lines +160 to +162
ggufMemoryTotalGb: ggufDevices.length
? ggufIgpuOnly && devices.length <= ggufDevices.length
? memoryTotalGb

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 Avoid identifying an APU by device counts alone

When Vulkan is masked to a single iGPU while torch sees a different single dGPU, both arrays have length 1, so this condition incorrectly substitutes the torch dGPU's total for the Vulkan GGUF budget. This is exactly the mixed masked topology the preceding comments intend to keep at zero: llama-server cannot use that dGPU, yet Hub fit filters and GGUF variant labels will count its VRAM and can advertise models as fitting. Matching list lengths does not establish that the inventories describe the same device, so the torch fallback needs a stronger identity/topology check.

Useful? React with 👍 / 👎.

LeoBorcherding and others added 3 commits July 25, 2026 04:51
…an-6414

# Conflicts:
#	studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts
Addresses the Codex review on 81333e1/7161989:

- P1 centralize invalidation: move refreshHardwareInfo + invalidateGpuInfoCache
  into notifyReloadIfNeeded so every reload-required terminal path (poll,
  surfaceIfAvailable, apply stale-click, chained-update error) re-probes, not
  just polling success.
- P1 stale backend cache: /api/system gains ?refresh=1 (force_refresh) to bypass
  the 10s GPU and 60s Vulkan-inventory caches; invalidateGpuInfoCache refetches
  with it so a post-swap read can't re-cache the pre-swap inventory.
- P2 stale in-flight write: cache generation counter; a fetch that started before
  an invalidation drops its now-stale snapshot instead of overwriting the cache.
- P2 notify mounted hooks: useGpuInfo/useGpuDevices/useCurrentGpuIndexKind share
  a subscription so an invalidation repaints open Hub / GPU settings surfaces.
- P2 index kind from flag: systemGpuIndexKind uses gguf_backend_is_vulkan, so an
  empty inventory on a Vulkan build is vulkan (not misread as physical).
- P2 preset stamp: applyPresetLoadConfig carries selectedGpuIdsIndexKind so a
  Vulkan pick isn't cleared as a cross-space physical pick.
- P2 APU identity: replace the device-count guard with a normalized-name identity
  check so a masked-iGPU-beside-a-dGPU host stays on the conservative 0.

Merged latest main (resolved use-chat-model-runtime: kept the kind-aware
reconcile alongside main's pendingLoadConfig branching).
@Bebiv24

Bebiv24 commented Jul 25, 2026

Copy link
Copy Markdown

Hey Leo, tested this on my setup. RX 9070 XT (16GB) + RX 480 (8GB) on Windows.

What I did:

  • Fresh installed Studio via irm https://unsloth.ai/install.ps1 | iex
  • Cloned this branch: git clone -b fix-oom-labels-vulkan-6414 https://github.com/LeoBorcherding/unsloth.git
  • Ran install.ps1 --local
  • Copied Vulkan DLLs from the official llama.cpp Vulkan release (llama-bin-win-vulkan-x64) into .unsloth\llama.cpp\build\bin\Release\
  • Deleted ggml-hip.dll from that folder

Results: Studio now shows both GPUs (GPU 0: AMD Radeon RX 9070 XT, GPU 1: Radeon RX 480). Tensor Parallelism toggle is available and enabled. Fit labels are budgeting against more than 16GB now. Before this fix, Studio only showed the 9070 XT and everything was budgeted against 16GB.

The key step was removing ggml-hip.dll — without that, Studio still assumed ROCm and only detected one card even with the Vulkan DLLs in place. Once it was gone, the Vulkan probe picked up both GPUs correctly.

Nice work, this is a big quality of life improvement for mixed AMD GPU setups.
preview2
preview

@danielhanchen

Copy link
Copy Markdown
Member

Re-reviewed after the Codex follow-up commit. Everything still passes here: 217 passed across the vulkan probe, gguf devices, gpu memory mode, chat-load and model-picker contract suites, and frontend typecheck is clean (same five pre-existing missing-module errors as main, none new).

Replacing my device-count guard with the normalized-name identity check is a straight improvement, and it closed a hole I had left. My devices.length <= ggufDevices.length false-positives on exactly the case it was supposed to protect: a masked host with one torch dGPU and one probed iGPU satisfies 1 <= 1, so it would have used the torch total anyway. Matching on device identity fixes that properly. Thanks for updating the contract test to match rather than deleting it.

The rest of the follow-up looks right to me. force_refresh is threaded through both caches, /api/system stays auth-gated and stays a sync def so the probe subprocess is still threadpooled off the event loop, and the generation counter closes the in-flight-write race.

One thing to check on the identity join

normalizedDeviceName joins the torch view and the Vulkan inventory on the device name, and that string is driver-dependent. ggml takes it straight from VkPhysicalDeviceProperties.deviceName:

// ggml-vulkan.cpp
snprintf(description, description_size, "%s", props.deviceName.data());

On this Strix Halo box under the AMD proprietary driver the two sides agree exactly, so the guard fires as intended:

$ vulkaninfo --summary
GPU0:
        deviceType   = PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
        deviceName   = AMD Radeon(TM) 8060S Graphics
        driverName   = AMD proprietary driver

torch: AMD Radeon(TM) 8060S Graphics

Both normalize to 8060s, and the INTEGRATED_GPU type confirms ggml will flag is_igpu here, so this is the real scenario.

Linux is the open question. Mesa RADV does not report the same string as the ROCm name for the same GPU, and llama.cpp's own device dedup exists specifically because of it:

// Check if there are two physical devices corresponding to the same GPU
// This handles the case where the same GPU appears with different drivers
// (e.g., RADV + AMDVLK on Linux)

If the RADV string does not normalize to the ROCm one, torchDevicesAreAllProbed stays false on Linux and a Strix Halo box there keeps the 0 GiB label the fix is meant to remove. I could not verify the RADV string on this machine, the installed llama.cpp here is the ROCm build so there is no ggml-vulkan to probe.

Worth either loosening the comparison to containment in either direction, or falling back to the count check when no torch device name matches any probed name. Not a blocker for the Windows path, but it would be good to confirm on a Linux APU before this lands, otherwise the fix silently does nothing on half the affected hosts.

@danielhanchen

Copy link
Copy Markdown
Member

@Bebiv24 thanks for testing this on the actual hardware, that is the validation this needed. Both cards showing with real names and the fit labels budgeting past 16GB is exactly the outcome the PR was aiming at. The ggml-hip.dll detail is a good catch too: _is_vulkan_backend() keys off the shipped backend DLLs, so a directory holding both HIP and Vulkan libraries classifies as ROCm and the Vulkan probe never runs.

I tried to merge main in and stopped, because this is no longer a conflict resolution. #7476 ("report Vulkan GPUs in system UI") landed on main and independently implements an overlapping feature, end to end:

  • get_vulkan_inference_gpu_info() in utils/hardware/hardware.py
  • _get_cached_system_gpu_info now returns a (training, inference) tuple rather than one dict
  • a top-level inference_gpu on /api/system
  • frontend consumption already in use-system.ts, use-gpu-info.ts, hub-page.tsx, pickers.tsx, resources-tab.tsx and floating-monitor.tsx

Four of those six files are ones this PR also rewrites, and the two designs disagree on the data model rather than on formatting. Merging mechanically would ship two parallel Vulkan device concepts with different index semantics, which is the exact class of bug the pin-space commits here spent several rounds fixing.

Which design wins

This PR is the stronger one on capability, and I would not want to lose it:

#7476 (on main) this PR
device name Vulkan0, Vulkan1 real ggml description, e.g. AMD Radeon RX 9070 XT
index_kind relative, so unpinnable vulkan, pins via --device Vulkan<i>
gpu_ids picks not offered validated in /load and /validate
iGPU inferred from total_mib == 0 explicit is_igpu from the ggml device type

@Bebiv24's screenshots show the difference concretely: real card names and a working Tensor Parallelism toggle, neither of which #7476 gives you.

One place main is ahead: aggregateGpuMemoryTotalGb sums dedicated VRAM and counts a shared pool once via shared_memory. That is a better answer than the iGPU handling in 7161989, which I had patched to fall back to the torch total on an all-iGPU host. Main's version supersedes that, so drop my change when you rebase.

Suggested path

Rebase this onto #7476's inference_gpu shape rather than reintroducing gguf_devices: keep main's transport and enrich it with the real device description, the explicit is_igpu flag, and index_kind: "vulkan" so picks stay pinnable. The probe work, validate_vulkan_gpu_ids and the pick index-space stamping all carry over largely unchanged. That keeps this PR's capabilities without a second device model.

I did not push a merge since that is a design call rather than a resolution, and it is your PR. Happy to do the rebase if you would rather I took it. The Python 3.10-3.13 CI failures resolve on their own with the rebase, they are the test_load_marker_precedes_hub_guard_and_unload anchor that #7443 already fixed on main.

@danielhanchen

Copy link
Copy Markdown
Member

Opened #7498 with the rebase onto #7476's inference_gpu transport, as discussed above. It supersedes this PR.

What carried over: the probe's 5th column for ggml's real device description, vulkan_device_inventory with the explicit is_igpu flag, index_kind: "vulkan" so picks are selectable, the pick support gate, and the removal of the late diffusion raise so the graceful drop stays reachable.

What did not, and why:

  • validate_vulkan_gpu_ids is redundant on current main. resolve_requested_gpu_ids already rejects duplicates and _resolve_gguf_gpu_ids_for_request already probes for ordinal existence, so it would have been dead code.
  • gguf_devices is replaced by inference_gpu.
  • The iGPU budget fallback I pushed in 7161989 is dropped. Main's aggregateGpuMemoryTotalGb counts a shared pool once, which is a better fix than falling back to the torch total.

One thing worth flagging that I got wrong first time: I initially took the memory numbers from vulkan_device_inventory and test_vulkan_igpu_info_uses_capped_free_budget failed. _get_gpu_memory applies _apply_igpu_host_reserve_mib and zeroes a shared total; the raw inventory does not. Budgeting an APU off the raw shared total would hand out the whole machine's RAM with no OS headroom, 91 GiB on my Strix Halo box. #7498 joins identity onto the fit-correct memory path by ordinal instead.

The per-model pick stamping, chat runtime store and preset-config work here is not in #7498. It is follow-on and easier to land once the index space is settled in one place, so it is worth keeping this branch around for that rather than discarding it.

Separately, before anything from here gets reused: 0c4968b15 committed 708 files under studio/frontend/~/CLAUDE_CODE_TMPDIR/ (a literal ~ directory holding a Node compile cache) plus temp/. None of those paths are gitignored, so they will keep coming back. Worth adding them to .gitignore and stripping them from the branch.

@Bebiv24 your test is what made the case for keeping the richer design rather than settling for #7476's Vulkan0 / Vulkan1 labels, thanks again for running it.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@danielhanchen

Copy link
Copy Markdown
Member

Force-pushed this branch to strip the committed junk. Heads up that the last two commit SHAs changed, so re-pull before doing anything further on it:

git fetch origin && git reset --hard origin/fix-oom-labels-vulkan-6414

What was removed: 708 files under studio/frontend/~/CLAUDE_CODE_TMPDIR/ (a Node compile cache plus cwd markers) and temp/chat_preset_builtin_invariants/, all added in 0c4968b15. The PR went from 733 changed files to 25.

Nothing of yours was touched. I rewrote only the two commits that carried the junk in their trees, 0c4968b15 and b6ea3ac7e; their parent was already clean. Both commit messages are preserved, and a diff of the new tip against the old one excluding those two paths is empty, so every line of real source is byte-identical. File count went 2941 to 2233, exactly the 708 removed.

Old tip was b6ea3ac7e if you need to recover anything from it; it is still reachable via the reflog on any clone that had it fetched.

The root cause is fixed separately in #7499: .gitignore had a /~/ rule, but root-anchored, so it only caught a stray ~ directory created at the repo root. Tools run from a subdirectory create it there instead, which is how studio/frontend/~/ slipped through. That PR unanchors it and adds /temp/, so this cannot recur.

danielhanchen added a commit that referenced this pull request Jul 27, 2026
… onto #7476) (#7498)

* Vulkan GPUs: real device names and selectable ordinals

Rebases the durable half of #7356 onto the inference_gpu transport #7476
landed on main. Those two PRs solve an overlapping problem and disagree on
the data model, so merging #7356 as-is would ship two parallel Vulkan
device concepts with different index semantics. This keeps main's transport
and adds what #7356 had that #7476 does not.

- _vulkan_probe.py emits a 5th column, ggml's device description, sanitized
  for the tab protocol and UTF-8 safe. Reader tolerates 4- or 5-column
  output so an older probe still parses.
- llama_cpp gains _run_vulkan_probe (shared parse) and
  vulkan_device_inventory (names + is_igpu + real totals).
- get_vulkan_inference_gpu_info reports the real name and an explicit
  is_igpu instead of "Vulkan<i>" and a total == 0 guess.
- index_kind becomes "vulkan", not "relative", and gpu_ids picks are
  supported on Vulkan builds once the probe enumerated ordinals. The XPU ban
  no longer applies to them: a Vulkan pick is a ggml ordinal, not a torch-xpu
  index, so it works on an Intel host too.
- Frontend picker reads the Vulkan inventory as the pickable set.

Memory deliberately still comes from _get_gpu_memory, not the inventory.
That path applies _apply_igpu_host_reserve_mib and zeroes a shared total;
budgeting an APU off its raw shared total would hand out the whole machine's
RAM with no OS headroom. Identity is joined onto it by ordinal, so a probe
failure degrades to Vulkan<i> names with the memory readings intact.

Dropped from #7356 as superseded: validate_vulkan_gpu_ids (main's
resolve_requested_gpu_ids already rejects duplicates and
_resolve_gguf_gpu_ids_for_request already probes for existence), the
gguf_devices transport, and the iGPU budget fallback in 7161989, which
main's aggregateGpuMemoryTotalGb handles better by counting a shared pool
once.

Also keeps #7356's removal of the late diffusion raise, so the graceful
gpu_ids drop stays reachable for a GGUF only classified as diffusion after
download. #7415's real guard, _reject_vulkan_diffusion_gpu_ids_before_
teardown, is untouched.

Verified on Windows + Strix Halo: backend Vulkan/GPU-selection suites at the
same 4 pre-existing failures as main, tests/studio 1671 passed with no new
failures, frontend typecheck clean. Hardware confirmation of the underlying
behavior is on #7356 from @Bebiv24 (RX 9070 XT + RX 480).

Co-authored-by: LeoBorcherding <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: LeoBorcherding <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants