Repository navigation
Studio images: render on the NVIDIA card when torch drives no GPU - #16853
Merged
danielhanchen merged 5 commits intoNov 7, 2026
Merged
danielhanchen merged 5 commits into
danielhanchen merged 5 commits into
Conversation
A chat-only install has no torch and a CPU wheel sees no card, so the image engine always installed the CPU stable-diffusion.cpp build, even beside an NVIDIA card that llama.cpp already renders chat on. When torch resolves to CPU, llama.cpp's install marker says it is a CUDA build and the inventory lists an NVIDIA card, the image engine now installs the matching CUDA sd.cpp build and places loads on it with the same auto offload the CPU-torch Vulkan route uses. CUDA gets a CPU rung on that route only: a CUDA build that cannot start is proven unrunnable on the spot and the same load steps down to the CPU build, since nothing else renders without torch. A CUDA torch is unchanged. Fixes unslothai#16803
…election source test, trim comments The in-load retry now only runs where torch drives no GPU, so ROCm / XPU hosts keep today's diffusers fallback for the load. The source test matches the wrapped condition, and the CUDA route tests stub the llama.cpp marker rather than the new helper. [skip ci]
Member
|
@codex review |
1 similar comment
Member
|
@codex review |
Codex Review SummaryThis 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. |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
1 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16803
Problem
On a desktop install without a GPU torch (the "Chat only (GGUF)" option, or a CPU wheel), image generation runs through the native stable-diffusion.cpp engine, and
image_install_accelerator("cpu")always asked for the plain CPU build. So on an NVIDIA box chat ran on the card (llama.cpp ships its own CUDA build) while every image rendered on the CPU with the GPU idle, which is what the screenshots in the issue show. The CPU-torch route already picks the Vulkan build beside AMD/Arc cards, but never anything beside NVIDIA.Fix
diffusion_engine_router._cuda_gpu_for_cpu_torch(): when torch resolves to CPU, the installed llama.cpp is a CUDA build (its install marker'sruntime_line, newsd_cpp_engine.llama_cpp_cuda_major()), the inventory lists an NVIDIA card, the host is Windows x64 / Linux x86_64 andCUDA_VISIBLE_DEVICESdoes not hide every card, the image engine asks for the CUDA sd.cpp build. The CUDA major comes from llama.cpp, whose cudart dir sd.cpp already borrows, so the driver is known to run it.cuda -> cpuis a ladder rung on the CPU-torch route only (_cuda_cpu_rung_applies). A CUDA build that cannot start there is recorded as proven and the same load steps down to the CPU build, instead of ending on diffusers (which has no torch to run on). A CUDA torch is unchanged: no CUDA records, no CPU rung.UNSLOTH_DIFFUSION_SD_CPP_VULKAN_FALLBACK=0(the same knob that gates the Vulkan route and the ladder).Testing
Windows 11, RTX 3050 Laptop 4 GB (driver 566.07), global Python without torch, so the same as a chat-only install. llama.cpp isn't installed on this PC, so only its two lookups were stood in for: its CUDA marker (
cuda12) and its cudart directory (a folder withcudart64_12/cublas64_12/cublasLt64_12).image_install_accelerator('cpu') = auto, installswin-cpu-x64, device listing shows only the CPU.win-cuda12-x64,--list-devicesshowsCUDA0 NVIDIA GeForce RTX 3050 Laptop GPU, enginesd_cpp.select_and_activate_enginecall steps down and ends on thewin-cpu-x64build with enginesd_cpp.SdCppBackend.begin_load+generate:device=cpu, peak VRAM 0 MiB, GPU 0%, 170 s.device=cuda, offload--offload-to-cpu --clip-on-cpu --vae-on-cpu --diffusion-fa --vae-tiling, peak VRAM 2487 MiB, GPU 100%, 71 s.tests/test_sd_cpp_cuda_cpu_torch.py(34 tests: routing gates, CUDA torch unchanged, the CPU rung only on a CPU torch, the loader-refusal ladder, same-load step-down, the pinned release's CUDA assets). Two existing tests now pin the host type they assert about (test_only_rocm_and_vulkan_have_a_rung_below_them,test_the_preflight_never_touches_a_non_rocm_accelerator), and the Vulkan-route fixture stubs the llama.cpp lookup so it never reads the real install.test_sd_cpp_*,test_diffusion_engine_*andtest_diffusion_routessuites: same failures as agit archiveof main on this Windows box (env-only: cudnn 3, engine 6, h3_matrix 36, install 2, moss_image 1, qwen21_edit 1, rocm_vulkan_fallback 2, vram_budget 10, diffusion_routes 25), none new.Not tested: Linux (the gate and assets are covered by unit tests), multi-GPU NVIDIA hosts.