Skip to content

Unsloth Studio (AMD): pick a discrete GPU that fits over a larger APU in automatic GPU selection - #13196

Merged
danielhanchen merged 3 commits into
mainfrom
gd4/apu-discrete-first
Oct 10, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
gd4/apu-discrete-first

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

The problem

On a ROCm host with an APU next to a discrete card (for example a Strix Halo or Strix Point APU plus a Radeon dGPU), automatic GPU selection for training and Transformers loads can put the model on the APU even when the discrete card has room for it.

auto_select_gpu_ids ranks candidates by free memory only. For a ROCm APU, _reconcile_rocm_unified_memory widens the row to the shared GTT pool, so with 96 GB of shared memory the APU reports far more free memory than a 24 GB discrete card and is picked first. The unified-memory flag already exists on the torch inventory rows (_rocm_known_unified), but selection never read it.

The change

Before the existing ranked loop, on ROCm only and only when more than one GPU is a candidate: if the top-ranked device is a unified-memory APU and a discrete card alone has enough free memory for the estimate, that discrete card goes first. Everything else is unchanged:

  • no discrete card fits alone: today's ranking, so a large model still lands on the APU or is sharded exactly as before
  • no APU among the candidates, a single GPU, CUDA, XPU: the inventory is not read and the ranking is identical

Tests

studio/backend/tests/test_rocm_apu_discrete_first.py, with the selection inputs stubbed:

case main this branch
APU (88 GB free) + dGPU (23 GB free), 16 GB needed APU dGPU
same host, 40 GB needed (dGPU too small) APU APU
two discrete cards larger card larger card
same APU host off ROCm APU, no inventory read APU, no inventory read
APU only APU APU

The first case fails on main and passes here; the four controls pass on both. The related Studio backend suites (test_gpu_selection_sandbox, test_training_gpu_arch_gate, test_training_vram_coexistence, test_rocm_multi_gpu_vram_system_wide, test_rocm_live_telemetry_hip_ids) give the same results on main and on this branch, as do test_gpu_selection.py and test_chat_load_during_training.py (245 passed on main plus the new test; the only difference in failing test IDs is the new case).

No host with an AMD APU and a discrete card was available, so this is shown with stubbed device rows.

The desktop Ryzen iGPU case from #8847

The same ranking hits a desktop Ryzen 7000 / 9000 with its integrated graphics enabled beside a Radeon card on Windows ROCm. The AMD multi-arch Windows wheel has kernels for the gfx1036 iGPU, so the arch gate from #8791 keeps it as a candidate, and its free reading is the WDDM shared pool, half of system RAM. On a 32 GB machine that is about 16 GB, level with an RX 7800 XT.

Selection inputs stubbed to that host (iGPU HIP 0 with a shared pool of RAM / 2, RX 7800 XT HIP 1 with 15.4 GB free), every RAM size in {24, 32, 48, 64, 96} GB x model estimate in {6, 10, 14, 20} GB, 20 cells:

RAM 6 / 10 / 14 GB model, main this branch 20 GB model, main this branch
24 GB dGPU dGPU dGPU + iGPU dGPU + iGPU
32 GB iGPU dGPU iGPU + dGPU iGPU + dGPU
48 / 64 / 96 GB iGPU dGPU iGPU iGPU

12 cells move, all to the discrete card and all where it fits alone; the 8 others are identical.

Related: #8847

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 10, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 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-10-10T10:35:10.907356Z abe0f60 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 6ca29b4ba6

ℹ️ 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: abe0f60119

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

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.

1 participant