Commit graph

93 commits

Author SHA1 Message Date
Claude
071a12b378
feat: add --profile to choose a resource footprint
--profile max|balanced|lite|auto sets, in one option, what a small
machine needs: balanced turns the memory guard on at 90; lite also
puts the text encoder on the CPU, tiles the VAE, runs CFG unbatched
and lowers the guard to 85. An option given on the command line always
wins over the profile, including --memory-guard 0. A profile does not
touch --params-backend or --backend, so --auto-fit keeps deciding
where the weights live, and it never changes the size or the steps of
an image.

auto compares the size of the model files plus a working-memory
reserve with the free memory of the discrete GPU with the most, or
with the available RAM without one, and logs the figures it used. It
leaves the defaults alone when the sizes or the memory are unknown.

parse_options() now records which options were given, through
option_was_given(). The levels below lite (weights streamed from disk,
everything on the CPU) cannot be chosen from the command line; they
are the steps a server takes when a request runs out of memory.

The thresholds of auto are heuristics and have not been tuned on a real
model or a GPU. Checked with the synthetic SD 1.5 model on the CPU: the
three profiles give the same image, and with 3.3 GiB held by another
process auto picks balanced.

Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
2026-10-11 07:19:14 +02:00
Claude
51845ffb58
feat: report why a call failed and expose system memory
new_sd_ctx(), generate_image() and generate_video() now record the
reason of a failure, and sd_get_last_error() returns it with a code:
out of memory, model file, backend, invalid argument, busy or
cancelled. An application can tell "try again with less memory" from
"the file is damaged" instead of reading the log. The state belongs to
the calling thread; errors logged by the model loader threads reach the
thread that reports the failure. C++ exceptions, std::bad_alloc
included, no longer cross the C API.

A test with a limited address space showed the process ending with
std::terminate when a loader thread could not be created while others
were already running. The loader now uses fewer threads, or the
calling thread when none could be started, and the loader threads
report exceptions as a failed load.

sd_get_system_memory() returns total, available and process RAM. The
free memory of the CPU device in sd_get_device_info() is the available
RAM, because ggml reports the total on Linux and macOS.

Checked with a synthetic 2.1 GB SD 1.5 model under a limited address
space: the standard configuration fails with out_of_memory, the same
context generates once the limit is lifted, and weights on disk let
the same request succeed. The Windows branch of system_memory.cpp was
only syntax-checked; macOS was not built.

Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
2026-10-11 07:09:28 +02:00
Claude
0d84e104ee
feat: run CPU graphs in segments when weights stream from disk
Without a GPU, auto-fit now compares the available RAM with the size of
each component and leaves the ones that do not fit on disk. When it does,
it turns the memory guard on at 90% unless --memory-guard is set.

On CPU backends the memory guard now counts the weights a graph still has
to read from disk before they are loaded. When that total would pass the
threshold and some weights can be released, the graph runs in segments, as
it already does on a GPU, so the peak stays well below the size of the
model. Splitting is skipped when the guard is off or when every weight is
resident, because it could not lower the peak.

Checked with a synthetic SD 1.5 model (128x128, 3 steps, 2 threads, Linux):
with 3.3 GiB of RAM held by another process and a 60% guard, the UNet runs
in 22 segments with a 732 MiB peak instead of 1722 MiB and the image is
identical pixel for pixel. Resident weights and runs without pressure or
without the guard behave as before. Not tested on Windows or with real
models.

Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
2026-10-11 06:39:34 +02:00
Claude
9b4ff13d52
feat: apply --memory-guard to CPU backends using system RAM
The guard returned an empty sample for CPU backends, so a CPU-only run
could fill system RAM without the guard ever reacting. On the CPU, measure
system RAM instead: total minus the memory available without swapping,
plus the allocation the graph is about to make, against total physical
memory.

Under pressure the guard releases unpinned weights that can be re-read
from the model file (--params-backend disk). It never fails a graph on the
CPU, since system RAM has no managed capacity, and CPU pressure does not
suspend prefetch for GPU backends.

Expose available_ram_bytes() from backend_fit for the probe, and update
the CLI help, the public header comment and the docs.

Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
2026-10-11 04:51:58 +02:00
Claude
86fc897098
Merge upstream leejet/stable-diffusion.cpp master into fix_to_claude
Brings in the nine upstream commits since 228c707, including the VAE
decode tile halving on OOM retry and the demotion of resident params to
disk residency when memory reclamation fails.

The only conflict was in ModelManager::ensure_compute_backend_capacity:
both sides added a block before the final capacity report. Keep both,
and apply the memory guard's "never fail a graph that still fits"
fallback before and after the demotion step.

Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
2026-10-11 04:26:15 +02:00
Daniele
1b0ba10893
feat: run conditional and unconditional CFG in one batched UNet forward (#2085) 2026-10-10 23:35:58 +08:00
Francesco Simeoni
6848c3f33e
Merge branch 'leejet:master' into fork-pull 2026-10-07 19:42:06 +02:00
Filve
bbcbe7459e implemented stable diffusions regular and specific with margin of limits of CPU/GPU 2026-10-07 19:23:28 +02:00
Wagner Bruna
f4b5326da7
feat: support for merging LoRA weights on model conversion (#2079)
Co-authored-by: leejet <leejet714@gmail.com>
2026-10-06 17:50:16 +08:00
leejet
19bbbca1c7
refactor: define VAE tile dimensions in image pixels (#2059) 2026-09-25 18:20:32 +08:00
leejet
740c7ae193
feat: add configurable Qwen cache types and early cache scheduling (#2045) 2026-09-25 01:51:01 +08:00
leejet
2dc7f5408a
feat: add Qwen Image 2.1 prefix KV cache (#2035) 2026-09-23 23:08:21 +08:00
leejet
e6281b6318
feat: add configurable conditioning cache for all models (#2034) 2026-09-23 22:25:42 +08:00
leejet
28b454bda1
feat: add configurable image input preprocessing (#2028) 2026-09-23 02:12:49 +08:00
Weiqi Gao
e112ab5a50
fix: add alpha channel input for Qwen Image 2.1 and relative docs (#2021) 2026-09-22 21:45:06 +08:00
leejet
97d932b8f8
fix: restrict VAE tiling retries to allocation failures (#2019) 2026-09-21 23:40:05 +08:00
Aziz Muminov
78557f88d9
fix: honor reference image resize opt-out in server requests (#2011) 2026-09-21 23:39:24 +08:00
leejet
187b2561ea
feat: add native CUDA SageAttention support (#2005) 2026-09-21 01:16:59 +08:00
fszontagh
15f335daa5
feat: add LLaDA-Image support (#1968)
Co-authored-by: leejet <leejet714@gmail.com>
2026-09-21 01:14:20 +08:00
leejet
3e037a81e4
perf: accelerate VAE direct 3D convolutions (#1996) 2026-09-19 17:50:01 +08:00
Wagner Bruna
07a85c74cb
feat: support Brownian tree noise in all noise injection samplers (#1899) 2026-09-15 02:37:31 +08:00
leejet
f9ddc0f388
refactor: require external Gemma 2 and GPT-OSS tokenizers (#1974) 2026-09-15 01:25:13 +08:00
leejet
4964abdfc5
feat: support external Hugging Face tokenizer JSON files (#1973) 2026-09-15 00:27:39 +08:00
George
0bd72f075a
feat: add Wan2.2 S2V (audio+img-to-video) support (#1925)
Co-authored-by: leejet <leejet714@gmail.com>
2026-09-13 23:33:50 +08:00
leejet
44dd13716d
feat: preserve explicit backend assignments during auto-fit (#1967) 2026-09-13 17:40:38 +08:00
leejet
7f410a3793
feat: add linear and attention scale overrides (#1964) 2026-09-12 01:41:28 +08:00
vmobilis
3191b23d4b
fix: handle invalid option numbers (#1961) 2026-09-11 23:16:39 +08:00
leejet
80bac2d5fc
feat: enable single-GPU auto-fit with tiered parameter placement (#1942) 2026-09-07 00:18:42 +08:00
leejet
dbb611264e
feat: add verbose logging and log-level selection (#1941) 2026-09-06 23:14:03 +08:00
leejet
462d675018
refactor: unify runner lifecycles and weight residency (#1940) 2026-09-06 22:30:45 +08:00
assouan
6c57cc3b38
feat: prefetch streamed layers during compute (#1905)
Co-authored-by: leejet <leejet714@gmail.com>
2026-09-06 16:35:30 +08:00
leejet
6b3edaaf32
feat: generalize temporal tiling across video VAEs (#1926) 2026-08-31 00:11:38 +08:00
leejet
97d2990807 chore: format code 2026-08-19 23:06:07 +08:00
vmobilis
16304cc3fd
fix: guard against missing sampler/scheduler names (#1887) 2026-08-19 22:31:19 +08:00
vmobilis
760717a060
fix: make max_order of lms sampler configurable (#1885) 2026-08-19 22:29:29 +08:00
leejet
ea7f0c87cf
feat: add minimax-h3 support (#1854) 2026-08-04 23:14:18 +08:00
vmobilis
eb7f35ca49
feat: add linear multi-step sampling method (#1843) 2026-08-02 16:19:47 +08:00
Wagner Bruna
af92790ffc
feat: allow customizing the alpha and beta parameters of the beta scheduler (#1834) 2026-07-30 21:24:51 +08:00
fszontagh
5ef4a7557d
feat: expose IP-Adapter in server request schema and capabilities (#1824) 2026-07-27 23:26:34 +08:00
fszontagh
8d377073e3
feat: add IP-Adapter support for SD 1.5 and SDXL (#1803) 2026-07-24 21:19:44 +08:00
leejet
b290693977
feat: add PiD 1.5 support (#1790) 2026-07-17 01:35:18 +08:00
leejet
a8a91b24cd
feat: add ADetailer support (#1785) 2026-07-14 23:59:11 +08:00
fszontagh
c00a9e956d
feat: AnimateDiff SD 1.5 motion modules (v2 + v3) (#1784) 2026-07-14 23:58:03 +08:00
stduhpf
74bce049d0
feat: add configurable reference image processing for edit models (#1780) 2026-07-14 22:58:22 +08:00
leejet
bb84971129
refactor: move model-specific args into model parsers (#1757) 2026-07-06 23:13:18 +08:00
fszontagh
e071aa390b
feat: move circular padding from context to per-generation params (#1748) 2026-07-06 22:04:20 +08:00
fszontagh
e9dee542c4
feat: add DPM++ 2M SDE (Brownian tree) sampler (#1743) 2026-07-05 17:32:43 +08:00
fszontagh
38a51f8105
feat: add DPM++ 2M SDE sampler (#1742) 2026-07-05 16:13:25 +08:00
Piotr Wilkin (ilintar)
b11c95a41c
feat: auto fit tensors across devices to guarantee optimal load (#1736) 2026-07-05 00:48:10 +08:00
Piotr Wilkin (ilintar)
68f3d6df9f
feat: support for cross-device row split (#1735) 2026-07-04 16:31:18 +08:00