stable-diffusion.cpp/docs/models/lora.md
leejet 0d71f963af
Some checks are pending
CI / ubuntu-latest-cmake (push) Waiting to run
CI / ubuntu-latest-cmake-vulkan (push) Waiting to run
CI / Build and push container images (push) Waiting to run
CI / macOS-latest-cmake (push) Waiting to run
CI / windows-latest-cmake (cpu, -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_LIBS=ON -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON) (push) Waiting to run
CI / windows-latest-cmake (cuda12, -DSD_CUDA=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -DSD_BUILD_SHARED_LIBS=ON -DCMAKE_CUDA_ARCHITECTURES='61;70;75;80;86;89;90;100;120' -DCMAKE_CUDA_FL… (push) Waiting to run
CI / windows-latest-cmake (vulkan, -DSD_VULKAN=ON -DSD_BUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON) (push) Waiting to run
CI / windows-latest-rocm (push) Waiting to run
CI / ubuntu-latest-rocm (10.1.0, x64, gfx900;gfx906;gfx908;gfx90a;gfx90c;gfx942;gfx950;gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1153;gfx1200;gfx1201) (push) Waiting to run
CI / release (push) Blocked by required conditions
fix: restore runtime LoRA tensor counts and unify automatic LoRA mode selection (#2400)
2026-11-23 02:39:34 +08:00

3 KiB

LoRA

LoRA weights adapt a compatible base model. Select a LoRA by name and strength using <lora:NAME:STRENGTH> in the prompt.

Model files

Component Weights and downloads CLI option Requirement
Base model Compatible model checkpoint -m / model component options Required
LoRA weights marblesh.safetensors or marblesh.ckpt for the example --lora-model-dir and <lora:NAME:STRENGTH> in the prompt Match the base model family

Usage

Web UI

Load a compatible base model with its recipe, then select the LoRA for generation. See Web UI guide for the shared workflow.

DGL

Example Description
SD 1.5 with LoRA Apply the same LoRA to the UNet and text encoder.

Run a script

Edit paths, prompts and settings in the script's var block, then run from the build directory. Paths inside the script resolve from the working directory.

Windows (PowerShell)

.\bin\Release\sd-cli.exe -M dgl --script ..\docs\dgl\lora\sd1-5-lora.dgl

Linux/macOS

./bin/sd-cli -M dgl --script ../docs/dgl/lora/sd1-5-lora.dgl

Choose another script from the table to run a different task. Add --check to validate syntax and types without loading weights. See the shared run instructions for build paths and the server's file-access rules.

Legacy CLI

CLI examples use the shared path and shell conventions.

Windows (PowerShell)

.\bin\Release\sd-cli.exe `
  -m ..\models\checkpoints\v1-5-pruned-emaonly.safetensors `
  --lora-model-dir ..\models\loras `
  -p "a lovely cat<lora:marblesh:1>"

Linux/macOS

./bin/sd-cli \
  -m ../models/checkpoints/v1-5-pruned-emaonly.safetensors \
  --lora-model-dir ../models/loras \
  -p "a lovely cat<lora:marblesh:1>"

The example loads ../models/loras/marblesh.safetensors or ../models/loras/marblesh.ckpt (use backslashes on Windows).

Options

LoRA apply mode

There are two ways to apply LoRA: immediately and at_runtime. You can specify it using the --lora-apply-mode parameter.

The default auto mode chooses immediately for unquantized weights on the compute backend without row splitting. It chooses at_runtime for quantized, offloaded, or row-split weights. For scripts, see DGL LoRA combinations.

The immediately mode may have precision and compatibility issues with quantized parameters, but it usually offers faster inference speed and, in some cases, lower memory usage. In contrast, the at_runtime mode provides better compatibility and higher precision, but inference may be slower and memory usage may be higher in some cases.

Notes and limitations

Choose LoRA weights trained for the base model. See the WebUI-style LoRA syntax.