Skip to main content
This guide walks you through training a LoRA for Stable Diffusion from scratch. By the end you will have a .safetensors file you can load in any SD-compatible UI or inference pipeline.
LoRA is the best starting point for most training tasks. It requires a fraction of the VRAM that full fine-tuning needs, trains in minutes to hours rather than days, and produces portable adapter files that can be combined with other LoRAs. Start here before exploring DreamBooth or native fine-tuning.
1

Install sd-scripts

Follow the Installation guide to set up your Python environment, install PyTorch, and configure accelerate. Come back here once accelerate config completes successfully.
2

Prepare your dataset

Create a folder for your training images and place 10–50 high-quality images inside it. Each image needs a matching caption file with the same name and a .txt extension.
my_dataset/
└── img/
    └── 10_my_subject/
        ├── image_001.jpg
        ├── image_001.txt
        ├── image_002.jpg
        └── image_002.txt
The folder name 10_my_subject tells sd-scripts to repeat each image 10 times per epoch and use my_subject as the class token. Each .txt file should contain a short caption describing the image, for example:
a photo of my_subject sitting on a wooden bench
Next, create a dataset configuration file named my_dataset.toml:
[general]
shuffle_caption = true
caption_extension = ".txt"
keep_tokens = 1

[[datasets]]
resolution = 512
batch_size = 1

  [[datasets.subsets]]
  image_dir = "./my_dataset/img/10_my_subject"
  num_repeats = 10
For more dataset options, see the Dataset Preparation documentation.
3

Train the LoRA

With your virtual environment activated, run the following command from the sd-scripts root directory:
accelerate launch --num_cpu_threads_per_process 1 train_network.py \
  --pretrained_model_name_or_path="<path to SD model>" \
  --dataset_config="my_dataset.toml" \
  --output_dir="./output" \
  --output_name="my_lora" \
  --save_model_as=safetensors \
  --network_module=networks.lora \
  --network_dim=16 \
  --network_alpha=8 \
  --learning_rate=1e-4 \
  --max_train_steps=1000
Replace <path to SD model> with the path to your base model checkpoint (.safetensors or .ckpt).
All training commands use accelerate launch rather than calling the script directly. This ensures the correct device placement, mixed precision settings, and CPU thread configuration you set up during accelerate config are applied. Never run python train_network.py without accelerate launch.
Key parameters explained:
ParameterValueDescription
--network_modulenetworks.loraSelects the LoRA network implementation
--network_dim16LoRA rank — higher values capture more detail but increase file size
--network_alpha8Scaling factor, typically set to half of network_dim
--learning_rate1e-4Learning rate for the LoRA weights
--max_train_steps1000Total number of training steps
Training progress and loss are logged to TensorBoard. Start TensorBoard in a separate terminal:
tensorboard --logdir ./output
4

Find your output

When training finishes, your LoRA file is saved to ./output/my_lora.safetensors. You can load this file in AUTOMATIC1111, ComfyUI, or any other tool that supports LoRA adapters.The output directory also contains TensorBoard logs for reviewing your training curve.
5

Next steps

This quickstart uses minimal settings to get you running quickly. Once your first LoRA works, explore these topics to improve your results:

Dataset Preparation

Bucket-based resolution grouping, caption strategies, and regularization images.

LoRA Training

Full parameter reference for train_network.py, advanced network architectures (LoHa, LoKr), and SDXL/FLUX.1-specific options.

Fine-tuning

DreamBooth and native fine-tuning for deeper model adaptation.

Supported models

Overview of all supported model architectures and their capabilities.

Build docs developers (and LLMs) love