stable-diffusion.cpp/examples/cli
Claude 84cf73f5cd
feat: make the values of device health configurable
The values of device health decided on 25 November (3 levels of strain,
15% of the capacity and 25% of the CPU threads per level, a quiet period
of 300 s, and 10 s under which two engine events count once) can now be
read and changed. Without the new option nothing changes.

- C API, additions only: sd_device_health_settings_t,
  sd_get_device_health_settings() and sd_set_device_health_settings().
- sd-cli and sd-server: --device-health with any of the keys levels,
  step, cpu-step, quiet and spacing, e.g. --device-health quiet=600. It
  applies as soon as the options are read, in the DGL mode of sd-cli too;
  values against the rules stop the program at start and say the rules,
  and the log names the values used.
- The registry refuses waits longer than a day and steps whose product
  with the levels would not fit in an int. When the values change, every
  component keeps its state: before, fewer levels could turn a level of
  strain into an exclusion, and more levels could bring an excluded
  device back under strain. The same values written again no longer
  change the revision, which makes the next generation place its models
  again.
- termico.py --segnala reads the levels of its device from
  /sdcpp/v1/health and from the answers to its reports, and never sends
  more than the last level of strain: with two levels the critical band
  is level 2, not an exclusion.

Docs: a "Device health" section in docs/guides/backend.md,
examples/server/api.md and the server README, the README of
scripts/diagnostica_termica, test/README.md and the fork history.

test: device_health_test covers the new rules and the C API (135
checks), device_health_option_test is new (30), termico_test covers
engines with two levels, one level and none declared (161), and
server_guardian_e2e.py starts its second server with
--device-health levels=2,step=20,quiet=5 and checks the option in sd-cli
(70 checks, three runs in a row with a synthetic SD 1.5 model). Every
program of test/ passes, the server tests under ThreadSanitizer too, and
29 broken versions of the new code (registry and C API 12, option 9,
termico.py 6, the calls in sd-server and sd-cli 2) all make the tests
fail. Not tried: real GPUs, Windows.

Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
2026-11-25 20:26:55 +01:00
..
CMakeLists.txt Merge leejet/stable-diffusion.cpp 3b12781 into fork-pull (sync 4/4, part 2) 2026-11-24 19:44:43 +01:00
dgl.cpp feat: add Diffusion Graph Language support (#2396) 2026-11-22 23:42:26 +08:00
dgl.h feat: add Diffusion Graph Language support (#2396) 2026-11-22 23:42:26 +08:00
main.cpp feat: make the values of device health configurable 2026-11-25 20:26:55 +01:00
media_input.cpp feat: add Diffusion Graph Language support (#2396) 2026-11-22 23:42:26 +08:00
media_input.h feat: add Diffusion Graph Language support (#2396) 2026-11-22 23:42:26 +08:00
README.md feat: add Diffusion Graph Language support (#2396) 2026-11-22 23:42:26 +08:00

Usage

From the build directory, show the full list of command-line arguments:

Windows (PowerShell)

.\bin\Release\sd-cli.exe -h

Linux/macOS

./bin/sd-cli -h

See sampling methods and schedulers for supported names, defaults, and custom sigma schedules.

The CLI defaults to seed 42 for repeatable runs. Pass --seed -1 to request a random seed. Other omitted inference options use the library defaults. Video generation defaults to 6 requested frames before model alignment. The conditioning cache uses the library default. Zero and false are explicit inputs; invalid values are reported rather than treated as omitted.

IP-Adapter, PhotoMaker, PuLID, AnimateDiff, SLG, NitroFusion, ADetailer and video upscaling use explicit DGL workflows. Their former native CLI options and the adetailer / vid_upscale modes have been removed. See the model and component guides for scripts.

--ref-video accepts a frame directory or a video file. Directories retain filename order and 24 fps; files are decoded through DGL video::load at 24 fps. Supported embedded audio is retained unless a matching --ref-video-audio WAV overrides it. --control-video accepts the same inputs; files are sampled at the generation --fps (default 16), without audio, and --video-frames limits decoding after resampling. Existing VACE frame padding is unchanged. File formats are AVI, static/animated WebP, and this project's independent-frame VP8 WebM. VP9 and Opus are unsupported; see DGL media I/O for codec and build requirements.

Logging defaults to info. Use --log-level <level> to select debug, verbose, info, warn, or error (from most to least detailed). Each level includes messages at that level and all less detailed levels. -v and --verbose are equivalent to --log-level verbose. If repeated, the last logging option wins. Native image/video generation and upscaling print the translated DGL program before execution at debug level (--log-level debug).

Run a DGL program with sd-cli -M dgl --script program.dgl. DGL mode accepts the same logging options and sends logs to stderr. Weight loading displays a progress bar with transfer speed; sampling displays its step progress. Context progress callbacks remain active during loading. --run-once on|off controls model release after last use and defaults to on.

--flash-attn on|off|auto defaults to auto, selecting flash attention for each compute backend during context creation. See Backend selection for probing behavior. Use module assignments such as --flash-attn auto,te=off,vae=on to override individual modules.

--conv-direct on|off|auto also defaults to auto, enabling direct convolution on backends with implicit GEMM implementations. Use --conv-direct auto,vae=off for module overrides; supported modules are diffusion, vae, and controlnet. See Direct convolution.

For direct image repair or automatic post-generation YOLOv8 detection followed by cropped inpainting, see ADetailer.

Use repeatable --image-preprocess rules to select resizing, cropping, padding, and resampling separately for each image input. Add canny=true to any input rule for edge detection. See Image preprocessing for input selectors, input defaults, downstream model processing, mask alignment, and examples.

Metadata mode inspects PNG, JPEG, WebP (including animated WebP), AVI, WebM, and Matroska container metadata without loading any model. Use --image for both images and videos:

Windows (PowerShell)

.\bin\Release\sd-cli.exe -M metadata --image .\output.png
.\bin\Release\sd-cli.exe `
  -M metadata `
  --image .\output.jpg `
  --metadata-format json
.\bin\Release\sd-cli.exe -M metadata --image .\output.webm
.\bin\Release\sd-cli.exe `
  -M metadata `
  --image .\output.avi `
  --metadata-format json
.\bin\Release\sd-cli.exe `
  -M metadata `
  --image .\output.png `
  --metadata-raw
.\bin\Release\sd-cli.exe `
  -M metadata `
  --image .\output.png `
  --metadata-all

Linux/macOS

./bin/sd-cli -M metadata --image ./output.png
./bin/sd-cli \
  -M metadata \
  --image ./output.jpg \
  --metadata-format json
./bin/sd-cli -M metadata --image ./output.webm
./bin/sd-cli \
  -M metadata \
  --image ./output.avi \
  --metadata-format json
./bin/sd-cli \
  -M metadata \
  --image ./output.png \
  --metadata-raw
./bin/sd-cli \
  -M metadata \
  --image ./output.png \
  --metadata-all

For completely black or white images or videos, NaNs, and the --linear-scale / --attn-scale workaround, see Troubleshooting.

Generation outputs embed the core generation record. Images retain the native JSON and an additional WebUI-compatible infotext. --disable-image-metadata omits both from files.