stable-diffusion.cpp/examples/cli
Claude c2f6e845b1
Merge leejet/stable-diffusion.cpp 532d2c1 into fork-pull (sync 3/4)
Third of four steps towards upstream 3b12781: the opaque C API with
options, tensors and results (#2365).

The fork's additions move to the new API:
- multi_gpu, memory_guard and disable_backend_fallback are context
  options (sd::ContextConfig, registered in src/api/options.cpp) that
  sd-cli and sd-server set through SDContextParams::to_context_opt().
- Our classified error code is renamed sd_get_last_error_code(), since
  upstream's sd_get_last_error() now returns the diagnostic text.
  sd_ctx_create, sd_generate_image and sd_generate_video record it again
  (src/api/api.cpp); the device, system-memory and error-code functions
  stay in the public header.
- ContextKeeper creates contexts with sd_ctx_create() from the settings
  of each profile; its create_context hook takes SDContextParams. Every
  attempt builds fresh image or video options and forces VAE tiling with
  the vae_tiling.enabled key; ADetailer follows the keeper's context.
- Settings that became std::optional are read with the library defaults
  (profiles, keeper, conditioning-cache check); the obsolete seed
  workaround in sd-server is gone, since an unset seed is now random.
- test/profile_test, server_recovery_test and api_robustness use the new
  API; the scripted contexts are real sd_ctx_t objects, as sd_ctx_free()
  deletes them.

Verified with a CPU build: the library, sd-cli and sd-server build; all
eight unit-test programs pass, server_recovery_test also eight times in
a row and under ASan and TSan; sd-server answers /sdcpp/v1/health,
/sdcpp/v1/resources and refuses img_gen with model_not_loaded; sd-cli
reports a missing model as model_file. docs/integrazione_progetti.md
still shows the old API in its C examples; the docs follow after the
last step.

Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
2026-11-24 13:01:39 +01:00
..
CMakeLists.txt Merge leejet/stable-diffusion.cpp 532d2c1 into fork-pull (sync 3/4) 2026-11-24 13:01:39 +01:00
image_metadata.cpp feat: return generation metadata with core results (#2206) 2026-10-25 03:18:03 +08:00
image_metadata.h feat(cli): add metadata inspection mode (#1381) 2026-04-01 00:52:03 +08:00
main.cpp Merge leejet/stable-diffusion.cpp 532d2c1 into fork-pull (sync 3/4) 2026-11-24 13:01:39 +01:00
README.md refactor(api): adopt opaque options, tensors, and results (#2365) 2026-11-15 18:33:53 +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.

Omitted inference options use the library defaults. In particular, an omitted seed requests a random seed; use --seed 42 for a repeatable run. Video generation defaults to 6 requested frames before model alignment. SLG layers remain unset unless --skip-layers is supplied, and the conditioning cache uses the library default. Zero and false are explicit inputs; invalid values are reported rather than treated as omitted.

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.

--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.