Commit 58d1126 for stable-diffusion.cpp
commit 58d1126febec89040ead4e136d7467a0e6fe6746
Author: leejet <leejet714@gmail.com>
Date: Sat Nov 28 16:59:33 2026 +0800
fix(vulkan): keep CPU-offloaded weights in pageable RAM (#2450)
diff --git a/docs/guides/performance.md b/docs/guides/performance.md
index d57842c..fade7a0 100644
--- a/docs/guides/performance.md
+++ b/docs/guides/performance.md
@@ -148,6 +148,8 @@ See [backend selection](./backend.md) for full syntax.
`--offload-to-cpu` keeps the source parameters in system RAM and creates compute-side GPU replicas on demand. Unpinned replicas remain resident for reuse, but automatic graph-cut execution evicts them from the last segment backward when the next weight or compute allocation needs space. Disk-backed parameters follow the same policy without retaining a RAM source copy.
+On Vulkan, CPU-offloaded weights use pageable system RAM, leaving the driver's host buffer capacity available for transfers.
+
When a graph has cut markers and its missing weights plus incremental compute workspace exceed the available device headroom, it runs its fixed segment list in order. An existing monolithic workspace can be reused without a new allocation. An explicit `--max-vram` budget includes resident managed weights, compute and cache buffers registered by runners sharing the device, and ggml's idle buffer pool. The current segment's weights are pinned during compute, and the next parameter-bearing segment is prefetched when the device supports asynchronous transfer. No opt-in streaming flag is required.
When choosing between monolithic and segmented execution, the runner requires
diff --git a/src/model_manager.cpp b/src/model_manager.cpp
index e719cd9..11dd990 100644
--- a/src/model_manager.cpp
+++ b/src/model_manager.cpp
@@ -1675,8 +1675,10 @@ ggml_backend_buffer_type_t ModelManager::params_buffer_type_for(const TensorStat
ggml_backend_buffer_type_t params_buft = nullptr;
if (state.compute_backend != nullptr && state.params_backend != state.compute_backend &&
sd_backend_is_cpu(state.params_backend)) {
+ // Vulkan host buffers are driver allocations. Keeping offloaded weights in them
+ // can exhaust Vulkan memory even after their device copies have been evicted.
ggml_backend_dev_t compute_dev = ggml_backend_get_device(state.compute_backend);
- if (compute_dev != nullptr) {
+ if (compute_dev != nullptr && !sd_backend_is(state.compute_backend, "Vulkan")) {
params_buft = ggml_backend_dev_host_buffer_type(compute_dev);
}
} else if (state.params_backend == state.compute_backend) {