GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — auto-fit: plan for integrated GPUs when no discrete GPU is present by danielhanchen · Pull Request #51 · unslothai/stable-diffusion.cpp Conversation
|
| arm | devices planned | picked | SD1.5 F16, 20 steps | Z-Image-Turbo Q4_K_M, 8 steps | pixels vs master |
|---|---|---|---|---|---|
| master ba6ac30 | ROCm0 + Vulkan0 (same pool counted twice) | Vulkan0 | 5.64 s [5.58, 5.64, 5.69] | 8.15 s [8.42, 8.13, 8.15] | |
| previous head 192306d | ROCm0 | ROCm0 | 6.53 s [6.43, 6.55, 6.53] | 9.11 s | PSNR 34.4 / 36.2 (ROCm render) |
| this head ab36235 | Vulkan0 | Vulkan0 | 5.61 s [5.58, 5.61, 5.66] | 8.14 s [8.14, 8.14, 8.13] | identical |
ab36235, --backend ...=Vulkan0 |
ROCm0 + Vulkan0 | Vulkan0 | 5.64 s | 8.10 s | identical |
ab36235, --backend ...=ROCm0 |
ROCm0 + Vulkan0 | ROCm0 | 6.53 s | 9.05 s | same pixels as the ROCm render |
Hosted runners (all nine prebuilt runner types, master vs ab36235): every leg builds, SD1.5 on CPU renders pixel-identical, and Metal on macos-15 renders pixel-identical (62.5 vs 61.8 s); the llvmpipe Vulkan legs stop on master already at a pre-allocated-tensor error with the stock SD1.5 checkpoint, so the RADV numbers above are the Vulkan evidence.
Vulkan-only builds (what the prebuilt Vulkan bundle is) have a single iGPU backend, so the guard drops nothing there: measured on the previous head, same device line and budget as master and identical pixels for SD1.5 F16 / Q8_0 and Z-Image. All 30 renders exited 0 and each arm's repeats were pixel-identical. Not exercised: the spill case (--max-vram small enough to place params elsewhere), the 0 / 0 and free > total branches (both backends reported sane memory), discrete GPUs.
On iGPU-only machines (AMD Strix Halo / Radeon 8060S, gfx1151, with ROCm or Vulkan) auto-fit printed auto-fit: no GPU devices; using the default backend and skipped planning, because enumerate_gpu_devices in src/core/backend_fit.cpp only accepted GGML_BACKEND_DEVICE_TYPE_GPU. Rendering still ran on the iGPU through the default backend, but no plan was made, so no budget was set and nothing was decided about where weights live, what gets offloaded, or VAE tiling.
This change lets auto-fit plan for GGML_BACKEND_DEVICE_TYPE_IGPU, using the same rule as llama.cpp's default device list:
src/llama.cpp (case GGML_BACKEND_DEVICE_TYPE_IGPU and "add integrated GPUs only if no discrete GPUs were found", lines 260 and 281 at ggml-org/llama.cpp@45b6604b).--fit uses (common/fit.cpp, no special case for IGPU). When everything fits, params stay on the iGPU and nothing is copied to a separate host copy. The RAM fallback only applies when the iGPU budget is too small (for example a small BIOS carve-out or --max-vram), which is the same order as for discrete cards.common/fit.cpp line 136).model_manager.cpp already treats it.Discrete GPUs and CPU-only builds take exactly the same path as before: the new branch only runs when the device is an iGPU, no --backend was given, and no discrete GPU exists. Explicit --backend handling is unchanged.
Base = master aba3a1c5, head = master + this commit. Base and head were built with the same recipe and run in the same job on the same machine, alternating per rep. SD1.5 fp16 512x512 20 steps seed 42 (3 reps), Z-Image Turbo Q4_K_M + Qwen3-4B Q4_K_M + FLUX ae 1024x1024 8 steps (2 reps). Times are median (min to max) in seconds.
| Platform | base | head |
|---|---|---|
| gfx1151 Linux, ROCm 7.14 (gfx1151 build) | no GPU devices; using the default backend |
ROCm0 free 102395 MiB, budget 101883 MiB -> --backend "diffusion=ROCm0,te=ROCm0,vae=ROCm0" |
| gfx1151 Linux, Vulkan (RADV) | no GPU devices; using the default backend |
Vulkan0 free 102685 MiB, budget 102173 MiB -> --backend "diffusion=Vulkan0,te=Vulkan0,vae=Vulkan0" |
| gfx1151 Windows 11, Vulkan (AMD driver) | no GPU devices; using the default backend |
Vulkan0 free 99437 MiB, budget 98925 MiB -> --backend "diffusion=Vulkan0,te=Vulkan0,vae=Vulkan0" |
On all three, every component fits, so all params stay on the iGPU, which is the backend the default path already picked. Apart from the plan lines the base and head logs are the same (same backend, same compute buffers, one graph-cut segment).
| Platform | Model | base generate | head generate | peak GPU mem delta (MiB) base / head | peak RSS (MiB) base / head | pixels |
|---|---|---|---|---|---|---|
| Linux ROCm | SD1.5 | 7.34 (7.20-7.34) | 7.32 (7.31-7.34) | 3176 / 3176 | 1324 / 1331 | identical |
| Linux ROCm | Z-Image | 42.02 (41.99-42.04) | 42.11 (42.05-42.17) | 10246 / 10246 | 1714 / 1702 | identical |
| Linux RADV | SD1.5 | 6.50 (6.43-6.51) | 6.42 (6.41-6.54) | 2713 / 2713 | 749 / 775 | identical |
| Linux RADV | Z-Image | 41.61 (41.22-41.99) | 42.61 (41.53-43.69) | 9000 / 9000 | 1219 / 1107 | identical |
| Windows Vulkan | SD1.5 | 6.03 (5.73-6.31) | 6.03 (5.97-6.05) | not measured | not measured | identical |
| Windows Vulkan | Z-Image | 57.83 (56.64-59.01) | 52.46 (45.64-59.28) | not measured | not measured | see note |
GPU memory is the peak of amdgpu mem_info_vram_used + mem_info_gtt_used during the run minus the idle reading. RSS is the child's ru_maxrss.
Notes:
conv2d direct auto: Vulkan0 -> on (probe 0.173 vs 0.162 ms) where every other run picked off (probe tie, 0.159 vs 0.159 ms). That rep's VAE ran fully on the GPU (3.5 s instead of 14.5 s) and its image differs slightly (max abs diff 4, PSNR 55.5 dB). This comes from the existing conv-direct auto probe, not from placement. The head rep that picked off like base produced identical pixels.| Check | Result |
|---|---|
| NVIDIA L4 (CUDA, sm89), SD1.5 512px 20 steps, 3 reps per arm | identical md5 for every rep, generate 3.40-3.42 s on both arms, the auto-fit plan and --backend line are the same on both arms |
NVIDIA L4 with --max-vram 1.5 (plan offloads params) |
same plan on both arms (--params-backend "diffusion=cpu,te=cpu,vae=cpu"), identical md5, 8.60 vs 8.61 s |
| CPU-only build (Linux x86_64), SD1.5 256px 2 steps | both arms log no GPU devices; using the default backend, identical pixels |
--max-vram) was not run on the AMD boxes. On those boxes the reported iGPU memory (about 100 GB) is far above what these models need.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
enumerate_gpu_devices only took GGML_BACKEND_DEVICE_TYPE_GPU, so on iGPU-only hosts (AMD Strix Halo with ROCm or Vulkan) auto-fit logged "no GPU devices" and skipped planning. Mirror llama.cpp's default device list: use iGPUs only when no discrete GPU exists, from the first backend that reports one, with the device's reported free memory. Skip an iGPU that reports 0/0 (keep the default backend instead of forcing CPU) and clamp a wrapped Vulkan free reading to the total, as the model manager already does. Discrete GPU and CPU-only hosts take the exact same path as before.
There was an error while loading. Please reload this page.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here are some automated review suggestions for this pull request.
Reviewed commit: 54a3759fdf
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (auto_igpu) { | ||
| // An iGPU reports its share of the unified pool. Without a reading it cannot be planned for, | ||
| // so keep the default backend instead of falling back to CPU. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Account for shared RAM when planning iGPU parameter offloads
On UMA machines where GPU allocations consume available system RAM, admitting the iGPU to the existing planner treats GPU memory and RAM as independent pools: GPU placements reduce remaining, but never reduce ram_budget_bytes. For example, with 12 GiB free in the shared pool and 8/2/1 GiB diffusion/TE/VAE weights, compute_plan places diffusion on the GPU and TE/VAE in RAM. ModelManager::stage_tensors_to_compute_backend then allocates additional GPU copies of those offloaded weights while retaining their RAM backing, increasing physical memory consumption compared with the previous single-copy default placement. Near capacity this can force unnecessary segmentation, swapping, or allocation failures. Preserve shared-memory information in the device plan and account for GPU residency and staging against the same physical RAM budget before choosing CPU offloads.
Useful? React with 👍 / 👎.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
# Conflicts: # src/core/backend_fit.cpp
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here are some automated review suggestions for this pull request.
Reviewed commit: 192306d914
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (type == GGML_BACKEND_DEVICE_TYPE_IGPU && igpu_reg != nullptr && | ||
| ggml_backend_dev_backend_reg(dev) != igpu_reg) { | ||
| continue; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Preserve explicitly selected iGPUs from other backends
When an APU is exposed through both ROCm and Vulkan, this filter also removes the second backend's iGPU when the user explicitly selects it with --backend. resolve_runtimes() still resolves that backend name successfully, but cannot find it in devices, leaving its runtime device list empty. Consequently, compute_plan() cannot place weights on the selected GPU and instead chooses CPU RAM or disk even when the model fits, introducing unnecessary staging or disk reads. Apply this backend deduplication only to automatic device selection, or retain explicitly requested devices for planning.
Useful? React with 👍 / 👎.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…t registered With two backends on one APU (a HIP + Vulkan build on Strix Halo), taking the first backend's iGPU moved auto-fit from Vulkan0, master's pick, to ROCm0, about 12% slower in sampling there. Rank by budget instead, which is the device select_main_device picks, so the main device stays master's while the shared pool is still counted once. A user-named assignment keeps every device.
|
@codex review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Closing: the main integrated-GPU fix came in with #52 (upstream leejet#2228 / leejet#2259). The three remaining guards change no plan, pixel or timing in any measured config, and the double-counted second iGPU only comes into play after host RAM is already exhausted. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.