From 03552461bb7bc71e784cdfb5f0fdfc5827730b20 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 17 Oct 2026 17:46:39 +0200 Subject: [PATCH] fix(auto-fit): warn about a pinned slower listing of a card and about weights streaming from disk Two things that made a generation take many times longer were visible in the plan only as a device line or a "params disk" label, with nothing saying what they cost. - A GPU that several backends list (an NVIDIA card is both CUDA0 and Vulkan0) is left out of the automatic choice when another backend already provides it, but the user, or a program that starts the engine, can still name it. With --backend vulkan0 the run goes through Vulkan, measured 12 to 22 times slower than CUDA on the same card, and the log did not say so. Each shadowed listing a module runs on now gets one warning that names the listing that the automatic choice uses. The remark about generic graphics APIs is added only when the owner's backend ranks above the shadowed one, so two Vulkan listings of one card are not called slower than each other. - Weights that fit neither the compute device nor the RAM budget stay in the model file and are read again every time their module runs, the diffusion model at every sampling step. One warning names the modules, their size, the free RAM and the budget, and says what helps (closing programs, --type, a quantized file). Nothing is said when the amount of free RAM is unknown, or with --cpu-only plans, which print their own note. The plan itself does not change: both warnings are only log lines after it. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC --- src/core/backend_fit.cpp | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/core/backend_fit.cpp b/src/core/backend_fit.cpp index 35a63da8..efa165e3 100644 --- a/src/core/backend_fit.cpp +++ b/src/core/backend_fit.cpp @@ -481,6 +481,60 @@ namespace sd::backend_fit { } } + // A listing that a preferred backend already provides is left out of the automatic choice, and print_plan marks it + // on its device line. When the user names it anyway (--backend vulkan0 for a card that CUDA lists as CUDA0), the + // run goes through the slower of the two backends and nothing else in the log says so. + static std::vector shadowed_runtime_warnings(const Plan& plan, const std::vector& devices) { + std::vector warnings; + std::vector seen; + for (const Runtime& runtime : plan.runtimes) { + for (size_t di : runtime.devices) { + if (di >= devices.size() || devices[di].shadowed_by.empty() || std::find(seen.begin(), seen.end(), di) != seen.end()) { + continue; + } + seen.push_back(di); + const Device& device = devices[di]; + std::string text = "auto-fit: " + device.name + " is the same GPU as " + device.shadowed_by + "; the automatic choice uses " + device.shadowed_by + " for this card."; + for (const Device& owner : devices) { + if (owner.name == device.shadowed_by && registry_rank(owner.registry) < registry_rank(device.registry)) { + text += " Backends on a generic graphics API (Vulkan, OpenCL) are usually slower than the one the GPU vendor provides: name " + owner.name + + " in --backend, or leave --backend out, unless " + device.name + " is wanted."; + break; + } + } + warnings.push_back(std::move(text)); + } + } + return warnings; + } + + // Weights that fit neither the compute device nor the RAM budget stay in the model file and are read again every + // time their module runs, the diffusion model at every sampling step. print_plan lists "params disk" per module; + // this says what it costs and what helps. Empty when nothing streams, or when the RAM is unknown (print_plan says so). + static std::string disk_streaming_warning(const Plan& plan, const std::vector& components, int64_t free_ram, int64_t ram_budget) { + std::string names; + int64_t bytes = 0; + bool diffusion = false; + for (size_t ci = 0; ci < components.size() && ci < plan.decisions.size(); ++ci) { + if (components[ci].params_bytes <= 0 || plan.decisions[ci].params_location != ParamsLocation::DISK) { + continue; + } + names += (names.empty() ? "" : ", ") + std::string(components[ci].name); + bytes += components[ci].params_bytes; + diffusion = diffusion || components[ci].kind == ComponentKind::DIT; + } + if (bytes == 0 || free_ram < 0) { + return ""; + } + char text[640]; + snprintf(text, sizeof(text), + "auto-fit: the weights of %s (%lld MiB) stay on disk and are read again every time they run%s: free RAM is %lld MiB and the budget for weights %lld MiB. " + "Close other programs to free RAM, or shrink the weights with --type (for example q8_0) or a quantized model file, to keep them in memory.", + names.c_str(), (long long)(bytes / MiB), diffusion ? ", the diffusion model at every sampling step" : "", + (long long)(free_ram / MiB), (long long)(ram_budget / MiB)); + return text; + } + static void append_assignment(std::string& spec, const char* key, const std::string& value) { if (!spec.empty()) { spec += ","; @@ -873,6 +927,15 @@ namespace sd::backend_fit { for (const std::string& note : multi_gpu_notes) { LOG_INFO("auto-fit: %s", note.c_str()); } + for (const std::string& warning : shadowed_runtime_warnings(plan, devices)) { + LOG_WARN("%s", warning.c_str()); + } + if (!cpu_only) { + const std::string streaming = disk_streaming_warning(plan, components, free_ram, ram_budget); + if (!streaming.empty()) { + LOG_WARN("%s", streaming.c_str()); + } + } if (cpu_only) { const bool streams_from_disk = std::any_of(plan.decisions.begin(), plan.decisions.end(), [](const Decision& decision) { return decision.params_location == ParamsLocation::DISK;