Repository navigation
Description
Problem
With the new idle weight TTL support, model-component unloading runs successfully, but sd-server retains roughly 4.2 GiB of VRAM afterward. Immediately after restarting the same container, before generating, it uses only approximately 128 MiB.
Is this retained memory expected (for example, a CUDA backend pool or other runtime allocations), or is there something the residency TTL should also release?
Environment
- Official Docker image:
ghcr.io/leejet/stable-diffusion.cpp:master-cuda - Server log:
stable-diffusion.cpp version unknown, commit ce7ef90 - GPU: NVIDIA GeForce RTX 5060 Ti, 16 GB
- Host driver: 595.112.07 (
nvidia-smireports CUDA 13.2 driver support) - The published image uses CUDA runtime 12.6.3.
- GPU selected using
CUDA_VISIBLE_DEVICES=1, exposed inside the container ascuda0. - Qwen Image 2.1 Turbo Q8 GGUF, Qwen3-VL 8B Q4 text encoder, vision projector and Qwen-compatible VAE; auto-fit and flash attention enabled.
--weight-residency-ttl 120; also tested with--weight-staging-ttlenabled, with the same remaining VRAM.
Reproduction
- Start
sd-serverwith a model configured through command-line arguments and--weight-residency-ttl 120. - Check
nvidia-smibefore generating: approximately 128 MiB attributed to sd-server after a fresh restart. - Generate an image and let generation finish.
- Leave the server idle for more than 120 seconds. The verbose log confirms cached model components unload.
- Check
nvidia-smi: the server still retains about 4.2 GiB. Restarting returns its usage to approximately 128 MiB.
Observed process memory
| State | VRAM attributed to /sd.cpp/bin/sd-server |
|---|---|
| Fresh restart, before generation | ~128 MiB |
| During generation | 11,628 MiB |
| After idle unloading | 4,294 MiB |
The idle screenshot showed 4,475 MiB total on the GPU, including a separate ignis-server process using 158 MiB; the 4,294 MiB figure above is specifically sd-server's process usage.
Relevant verbose log excerpts
2026-11-24T18:31:38.223Z [V] version: stable-diffusion.cpp version unknown, commit ce7ef90
2026-11-24T18:32:52.508Z [V] free compute buffer: 5.57 MB(VRAM) on CUDA0
2026-11-24T18:33:06.622Z [V] free compute buffer: 775.11 MB(VRAM) on CUDA0
2026-11-24T18:33:12.835Z [V] free compute buffer: 289.13 MB(VRAM) on CUDA0
2026-11-24T18:33:12.839Z [I] computing vae decode graph completed, taking 6.21s
2026-11-24T18:35:13.178Z [V] DGL unloaded 3 cached model components
These excerpts confirm the timeout runs approximately 120 seconds after generation. They do not establish which allocations account for the remaining VRAM, so I am not assuming it is a leak.
Expected behavior / feature request if intentional
My use case is sharing this GPU with another inference service while image generation is idle. Ideally, idle unloading would bring sd-server close to its fresh-start memory footprint while keeping its HTTP server and model configuration available for the next request.
If retaining the backend allocations is intentional for --weight-residency-ttl, could an additional opt-in argument such as --context-idle-ttl <seconds> be provided? It could destroy the model/execution context and release its backend resources after the timeout, preserve the selected configuration, then recreate the context on the next generation request. Exact naming and implementation are suggestions; the goal is to release the additional ~4 GiB while accepting a cold reload on the next request. Small unavoidable process/driver overhead is fine.
The earlier fork's full-context unload worked well for this shared-GPU use case. This report follows up on #2406 and #2239 after #2385 was closed as superseded; it highlights the difference between component residency release and returning near the fresh-start VRAM footprint.
Activity
nitedani commentedon Nov 25, 2026
With
--weight-residency-ttl 15, our unpatchedsd-serverstill used about 4.5 GiB of VRAM 35 seconds after the job. For us an idle sd-server has kept VRAM since master-1117, as #2401 reports. ggml intentionally keeps eligible freed CUDA buffers for reuse, up to 4 GiB per device (ggml-cuda.cu#L958-L979). That cache could account for some of the VRAM left after the residency timeout.On master-1127 with Z-Image Turbo on a 12 GB RTX 3080 Ti,
--offload-to-cpuand--weight-staging-ttl 0, this patch took idle VRAM from 4162–4780 MiB to 814 MiB. It empties ggml's reusable cache on the CUDA devices it finds in the staging list, previously cached buffers included (clear):It doesn't reach your path, because residency expiry calls the model unload instead (async_jobs.cpp#L731-L744). With
--weight-residency-ttl 15alone, the server held 4596 MiB unpatched and 4412 MiB with it, 5 and 35 seconds after the job, and the next job returned HTTP 200 on both builds.We haven't tried the same clear after the residency unload, so I can't say how close to the fresh-start 128 MiB it gets, or whether
--context-idle-ttlwould still be needed.