stable-diffusion.cpp/docs
Claude 6a01873d73
feat: keep sd-server serving when a request runs out of memory
A request that ran the machine out of memory ended in a 500 and left the
server on the configuration that had just failed, so every later request
of that size failed the same way. The context now belongs to a
ContextKeeper (examples/server/recovery.*) and every generation of the
OpenAI, sdapi and sdcpp endpoints goes through ContextKeeper::run().

On out_of_memory or backend (the codes of sd_get_last_error()) it frees
the model, loads it again with the next lighter profile of
max > balanced > lite > lite-disk > lite-cpu and runs the same request
again. Steps that would load the same configuration are skipped, a
device failure jumps to lite-cpu, and from lite on the VAE is decoded in
tiles whatever the request asked. --profile sets the top of the ladder.

After --degradation-cooldown seconds (300; 0 = never) the server climbs
back one profile at the start of the next request. A climb that fails
on its first use is undone and doubles the wait, up to an hour. If the
model cannot be loaded again, requests get 503 "unavailable" and the
load is retried no more than every 15 seconds. --disable-degradation
keeps the old behavior of answering with the error.

Failures are answered with 503 and Retry-After (out of memory, no
context), 400 (invalid_argument) or 500, with a body of
{"error", "code", "retry_after_seconds"}. Async jobs report the same
code in error.code, 429 carries Retry-After, and std::bad_alloc in a
handler becomes a 503. New endpoints: GET /sdcpp/v1/health (status,
profile, counters, last error, queue; it never waits for a running
generation) and GET /sdcpp/v1/resources (system memory and devices).

sd-server now exits with code 1 and a message when it cannot listen or
create its HTTP threads; the second used to end in std::terminate and
the first in a silent exit 0. The lite-disk profile clears --eager-load,
which read every weight into memory and so saved nothing.

test/server_recovery_test.cpp checks the ladder, the step downs, the
climb back, the reload after a failure, the HTTP answers and use from
several threads with a scripted library and clock (114 checks, also
under ASan/UBSan and TSan). Checked with a synthetic SD 1.5 model on
the CPU under address-space limits: a 384x384 request at 2400 MiB steps
down to lite-disk and succeeds, below 2200 MiB it answers 503 and the
server stays up, the climb back and a failed climb behave as described,
and nine parallel requests of the three kinds are all served. The server
and the whole engine built with ASan/UBSan went through the ladder, the
CPU memory-guard scenarios and injected read errors without a report.
Not checked: Windows, GPUs, real models.

Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
2026-10-11 10:40:29 +02:00
..
adetailer.md feat: add ADetailer support (#1785) 2026-07-14 23:59:11 +08:00
anima.md docs: unify model path 2026-07-05 18:31:59 +08:00
animatediff.md refactor: unify runner lifecycles and weight residency (#1940) 2026-09-06 22:30:45 +08:00
backend.md feat: run CPU graphs in segments when weights stream from disk 2026-10-11 06:39:34 +02:00
boogu_image.md docs: unify model path 2026-07-05 18:31:59 +08:00
build.md ci: build portable packages with GPU backends (Windows CUDA 12 and Vulkan, Linux Vulkan) 2026-10-11 05:40:43 +02:00
caching.md feat: add configurable conditioning cache for all models (#2034) 2026-09-23 22:25:42 +08:00
chroma.md refactor: move model-specific args into model parsers (#1757) 2026-07-06 23:13:18 +08:00
chroma_radiance.md docs: unify model path 2026-07-05 18:31:59 +08:00
distilled_sd.md feat: SDXS-09 support and update doc (#1356) 2026-04-17 01:11:44 +08:00
docker.md chore: move Dockerfiles into docker directory (#1745) 2026-07-05 18:39:09 +08:00
edit.md feat: add configurable image input preprocessing (#2028) 2026-09-23 02:12:49 +08:00
ernie_image.md docs: unify model path 2026-07-05 18:31:59 +08:00
esrgan.md fix: preserve alpha when upscaling RGBA images with ESRGAN (#2029) 2026-09-23 02:23:10 +08:00
flux.md docs: unify model path 2026-07-05 18:31:59 +08:00
flux2.md docs: unify model path 2026-07-05 18:31:59 +08:00
hidream_o1_image.md docs: unify model path 2026-07-05 18:31:59 +08:00
hipBLAS_on_Windows.md ci: update ROCm Windows builds (#1282) 2026-05-16 20:25:38 +08:00
hunyuan_video.md feat: add hunyuan video 1.5 support (#1795) 2026-07-18 22:30:10 +08:00
ideogram4.md feat: restore legacy fp8 handling when building with upstream ggml (#2001) 2026-09-21 00:48:30 +08:00
image_preprocessing.md feat: add configurable image input preprocessing (#2028) 2026-09-23 02:12:49 +08:00
imatrix.md feat: add imatrix support (#633) 2026-07-01 23:26:37 +08:00
int8_convrot.md feat: enable hip INT8 tensorwise matmul and convrot (#2071) 2026-09-27 23:24:07 +08:00
integrazione_progetti.md feat: keep sd-server serving when a request runs out of memory 2026-10-11 10:40:29 +02:00
ip_adapter.md feat: add IP-Adapter Plus (Resampler image projection) support (#1839) 2026-08-02 16:15:28 +08:00
iris.md feat: add Iris-3B text-to-image support (#2117) 2026-10-10 01:39:49 +08:00
kontext.md docs: unify model path 2026-07-05 18:31:59 +08:00
krea2.md docs: unify model path 2026-07-05 18:31:59 +08:00
lcm.md feat: simple openai image generation api compatiple server (#1037) 2025-12-13 13:53:21 +08:00
lens.md refactor: require external Gemma 2 and GPT-OSS tokenizers (#1974) 2026-09-15 01:25:13 +08:00
lingbot_video.md feat: add lingbot video support (#1770) 2026-07-11 17:50:59 +08:00
llada_image.md feat: add LLaDA-Image support (#1968) 2026-09-21 01:14:20 +08:00
longcat_image.md docs: unify model path 2026-07-05 18:31:59 +08:00
lora.md feat: simple openai image generation api compatiple server (#1037) 2025-12-13 13:53:21 +08:00
ltx2.md feat: add LTX-2.5 support (#1893) 2026-08-30 19:13:06 +08:00
mage_flow.md docs: update hugging face links for MageFlow diffusion and VAE models (#2065) 2026-09-27 17:22:03 +08:00
ming_image.md feat: add Ming-Image Design support (#2063) 2026-09-27 17:24:13 +08:00
minimax_h3.md feat: add minimax-h3 support (#1854) 2026-08-04 23:14:18 +08:00
minit2i.md feat: add MiniT2I support (#1683) 2026-07-02 00:46:51 +08:00
model_config.md feat: add verbose logging and log-level selection (#1941) 2026-09-06 23:14:03 +08:00
ovis_image.md docs: unify model path 2026-07-05 18:31:59 +08:00
performance.md feat: keep sd-server serving when a request runs out of memory 2026-10-11 10:40:29 +02:00
photo_maker.md feat: simple openai image generation api compatiple server (#1037) 2025-12-13 13:53:21 +08:00
pid.md refactor: require external Gemma 2 and GPT-OSS tokenizers (#1974) 2026-09-15 01:25:13 +08:00
pixart.md feat: add PixArt model family support (#2047) 2026-09-25 18:18:55 +08:00
pulid.md chore: move utility scripts under scripts (#1746) 2026-07-05 18:48:18 +08:00
quantization_and_gguf.md feat: simple openai image generation api compatiple server (#1037) 2025-12-13 13:53:21 +08:00
qwen_image.md docs: unify model path 2026-07-05 18:31:59 +08:00
qwen_image_2.1.md feat: add TAEQI2.1 support for Qwen Image 2.1 (#2123) 2026-10-11 00:01:18 +08:00
qwen_image_edit.md refactor: move model-specific args into model parsers (#1757) 2026-07-06 23:13:18 +08:00
rpc.md docs: reflect GGML_MAX_NAME value change in rpc docs (and in ggml_extend assert) (#1950) 2026-09-10 23:55:02 +08:00
sage_attention.md feat: add native CUDA SageAttention support (#2005) 2026-09-21 01:16:59 +08:00
sd.md refactor: unify runner lifecycles and weight residency (#1940) 2026-09-06 22:30:45 +08:00
sd3.md feat: simple openai image generation api compatiple server (#1037) 2025-12-13 13:53:21 +08:00
sefi_image.md refactor: unify runner lifecycles and weight residency (#1940) 2026-09-06 22:30:45 +08:00
sensenova_u1.md feat: add SenseNova U1.5 support (#1935) 2026-09-12 00:39:59 +08:00
taesd.md feat: add TAEQI2.1 support for Qwen Image 2.1 (#2123) 2026-10-11 00:01:18 +08:00
tokenizers.md refactor: require external Gemma 2 and GPT-OSS tokenizers (#1974) 2026-09-15 01:25:13 +08:00
troubleshooting.md fix: reject video models in image generation (#2017) 2026-09-21 21:48:42 +08:00
wan.md fix: improve GGUF metadata parsing and reader selection (#2062) 2026-09-27 16:24:07 +08:00
z_image.md docs: unify model path 2026-07-05 18:31:59 +08:00
z_image_l2p.md feat: add Z-Image L2P support (#2075) 2026-10-06 17:23:21 +08:00