--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 |
||
|---|---|---|
| .. | ||
| frontend@8e7c115059 | ||
| api.md | ||
| async_jobs.cpp | ||
| async_jobs.h | ||
| CMakeLists.txt | ||
| main.cpp | ||
| README.md | ||
| routes.h | ||
| routes_index.cpp | ||
| routes_openai.cpp | ||
| routes_sdapi.cpp | ||
| routes_sdcpp.cpp | ||
| runtime.cpp | ||
| runtime.h | ||
Example
The following example starts sd-server with a standalone diffusion model, VAE, and LLM text encoder:
.\bin\Release\sd-server.exe --diffusion-model ..\models\diffusion_models\z_image_turbo_bf16.safetensors --vae ..\models\vae\ae.sft --llm ..\models\text_encoders\qwen_3_4b.safetensors --diffusion-fa --offload-to-cpu -v --cfg-scale 1.0
What this example does:
--diffusion-modelselects the standalone diffusion model--vaeselects the VAE decoder--llmselects the text encoder / language model used by this pipeline--diffusion-faenables flash attention in the diffusion model--offload-to-cpureduces VRAM pressure by keeping weights in RAM when possible-venables verbose logging (equivalent to--log-level verbose)--cfg-scale 1.0sets the default CFG scale for generation
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.
After the server starts successfully:
- the web UI is available at
http://127.0.0.1:1234/ - the native async API is available under
/sdcpp/v1/... - the compatibility APIs are available under
/v1/...and/sdapi/v1/...
If you want to use a different host or port, pass:
--listen-ip <ip> --listen-port <port>
Frontend
Build with Frontend
The server can optionally build the web frontend and embed it into the binary as gen_index_html.h.
Requirements
Install the following tools:
-
Node.js ≥ 20 https://nodejs.org/
-
pnpm ≥ 10 Install via npm:
npm install -g pnpm
Verify installation:
node -v
pnpm -v
Install frontend dependencies
Go to the frontend directory and install dependencies:
cd examples/server/frontend
pnpm install
Build the server with CMake
Enable the frontend build option when configuring CMake:
cmake -B build -DSD_SERVER_BUILD_FRONTEND=ON
cmake --build build --config Release
If pnpm is available, the build system will automatically run:
pnpm run build
pnpm run build:header
and embed the generated frontend into the server binary.
Frontend Repository
The web frontend is maintained in a separate repository, https://github.com/leejet/sdcpp-webui.
If you want to modify the UI or frontend logic, please submit pull requests to the frontend repository.
This repository (stable-diffusion.cpp) only vendors the frontend periodically. Changes from the frontend repo are synchronized:
- approximately every 1–2 weeks, or
- when there are major frontend updates
Because of this, frontend changes will not appear here immediately after being merged upstream.
Using an external frontend
By default, the server uses the embedded frontend generated during the build (gen_index_html.h).
You can also serve a custom frontend file instead of the embedded one by using:
--serve-html-path <path-to-index.html>
For example:
sd-server --serve-html-path ./index.html
In this case, the server will load and serve the specified index.html file instead of the embedded frontend. This is useful when:
- developing or testing frontend changes
- using a custom UI
- avoiding rebuilding the binary after frontend modifications
Usage
For detailed command-line arguments, run:
./bin/sd-server -h
For completely black or white images or videos, NaNs, and the --linear-scale /
--attn-scale startup options, see Troubleshooting.