Introduction
Fine-tuning large-scale image generation models often requires immense computational power, making it inaccessible to many developers and artists. sd-scripts is a comprehensive suite of training scripts that enables efficient Low-Rank Adaptation (LoRA) and native fine-tuning for Stable Diffusion models, allowing users to customize AI art styles and characters with consumer-grade hardware. With thousands of GitHub stars, it has become the industry standard for creating high-quality LoRAs and specialized models.
What Is sd-scripts?
sd-scripts is a collection of Python-based training and utility scripts designed for Stable Diffusion. It provides the core logic for training techniques such as LoRA, DreamBooth, and Textual Inversion, supporting a wide range of base models including Stable Diffusion 1.5, 2.x, SDXL, and newer architectures like Anima and HunyuanImage-2.1. Maintained by kohya-ss, it is licensed under the Apache License 2.0, ensuring it remains open and accessible for both personal and commercial development.
Why sd-scripts Matters
Before the widespread adoption of sd-scripts, fine-tuning a Stable Diffusion model required full-parameter updates, which were computationally expensive and produced massive model files. sd-scripts popularized the use of LoRA, which only trains a small subset of weights, drastically reducing VRAM requirements and resulting in small, portable model files (often under 100MB) that can be easily shared and mixed.
The project’s significance lies in its flexibility. By providing a CLI-first approach, it allows for precise control over hyperparameters like learning rates, optimizers (such as AdamW8bit), and mixed precision (fp16/bf16), which are critical for achieving professional-grade results in image generation.
Key Features
- LoRA Training: Implements Low-Rank Adaptation to create small, efficient adapters that can be applied to any base model to inject specific styles or characters.
- Native Fine-Tuning: Supports full U-Net and Text Encoder training for those who need deeper model customization beyond LoRA.
- DreamBooth Training: Enables the training of specific subjects (e.g., a person or a specific object) into a model using a small set of high-quality images.
- Textual Inversion: Allows the creation of new concepts or styles by finding a specific embedding vector in the text encoder.
- SDXL Support: Full integration for Stable Diffusion XL, allowing for higher resolution training and more complex prompt adherence.
- Inpainting Model Training: Specialized scripts for training models specifically for image inpainting tasks for SD 1.5 and SDXL.
- Model Conversion: Utilities to convert between different model formats, including .ckpt, .safetensors, and Diffusers format.
- Image Tagging: Integrated tools for automatically tagging images to create the necessary caption files for training datasets.
- LoRA Merging: Tools to combine multiple LoRA adapters into a single model or merge them into the base model.
- Advanced Optimizers: Support for high-efficiency optimizers like AdamW8bit and others to reduce VRAM usage during training.
How sd-scripts Compares
| Feature | sd-scripts | Standard DreamBooth | Textual Inversion |
|---|---|---|---|
| VRAM Requirements | Low (via LoRA) | High | Very Low |
| Training Speed | Fast | Slow | Moderate |
| Model Size | Small (~10-100MB) | Large (2-6GB) | Tiny (KB) |
| Flexibility | High | Moderate | Low |
While standard DreamBooth is excellent for subject fidelity, it often leads to model “overfitting” or “catastrophic forgetting,” where the model loses its general knowledge. sd-scripts’ implementation of LoRA provides a better balance between learning a new concept and maintaining the base model’s flexibility. Textual Inversion is extremely lightweight but often struggles to capture complex visual details compared to LoRA.
The primary differentiator for sd-scripts is its CLI-first architecture. Unlike GUI-based trainers, sd-scripts allows for the creation of reproducible training configurations (via .toml files), which is essential for professional workflows where consistency is across multiple training runs is required.
Getting Started: Installation
Windows Installation
To install on Windows, you need Python 3.10.6 and Git. First, give unrestricted script access to PowerShell by running Set-ExecutionPolicy Unrestricted in an administrator window.
git clone https://github.com/kohya-ss/sd-scripts.git
cd sd-scripts
python -m venv venv
.\venv\Scripts\activate
pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116
pip install --upgrade -r requirements.txt
accelerate config
Linux Installation
For Linux users, it is recommended to use a virtual environment (e.g., pyenv) to avoid polluting the host system. Install the NVIDIA drivers and CUDA toolkit first.
git clone https://github.com/kohya-ss/sd-scripts.git
cd sd-scripts
python -m venv venv
source venv/bin/activate
pip install --upgrade -r requirements.txt
accelerate config
Prerequisites
A compatible NVIDIA GPU with at least 8GB of VRAM is highly recommended for LoRA training. For SDXL training, 12GB-16GB of VRAM is preferred.
How to Use sd-scripts
The basic workflow for training a LoRA involves three main stages: data preparation, configuration, and execution. First, you must organize your images into folders named with a repeating number and a trigger word (e.g., 10_mycharacter), which tells the script how many times to repeat each image per epoch.
Next, you create a dataset configuration file (usually a .toml file) that defines the paths to your training images, the resolution, and the tagging requirements. This allows you to decouple the training parameters from the data organization.
Finally, you execute the training script using accelerate launch. This tool from Hugging Face ensures that the optimized training process is distributed across your hardware efficiently.
Code Examples
Below is a basic command to initiate LoRA training. This example uses the AdamW8bit optimizer to save VRAM and fp16 mixed precision for speed.
accelerate launch --num_cpu_threads_per_process 1 train_network.py
--pretrained_model_name_or_path="sd-v1-5.safetensors"
--dataset_config="dataset.toml"
--output_dir="./output"
--output_name="my_lora_model"
--save_model_as=safetensors
--max_train_steps=2000
--learning_rate=1e-4
--optimizer_type="AdamW8bit"
--mixed_precision="fp16"
This command tells the script to use a specific base model, a load a dataset configuration, and save the output as a safetensors file, which is the most secure and fast format for use in Stable Diffusion WebUIs.
Real-World Use Cases
Character Consistency: A digital artist can train a LoRA on 15-20 images of a specific original character to ensure that the character looks identical across different poses, outfits, and backgrounds in generated images.
Art Style Replication: A studio can train a model on the works of a specific artist or a particular art style (e.g., a 1950s travel poster style) to maintain a consistent visual identity across a marketing campaign.
Product Integration: An e-commerce company can train a LoRA on a specific physical product to allow for the same product to be placed in various AI-generated environments without needing a professional photo shoot for every scenario.
Customized Inpainting: A developer can use the inpainting training scripts to create a model that is specialized in fixing specific types of artifacts or adding specific clothing items to existing images.
Contributing to sd-scripts
The project is primarily maintained by kohya-ss and is open to community contributions. Since there is no formal CONTRIBUTING.md, users are encouraged to report bugs and request features through the GitHub Issues page. Pull requests are welcome for those who want to improve the training logic or add support for new model architectures.
The project follows standard GitHub flow: fork the repository, create a feature branch, and submit a pull request for the project maintainer to review.
Community and Support
The primary hub for support is the GitHub Discussions page, where users share their training hyperparameters and “recipes” for different types of models. Because the project is a CLI tool, much of the community knowledge is distributed across Discord servers dedicated to AI art and Stable Diffusion.
Detailed documentation is available in the repository’s README and specialized guides written by community members (often in Japanese and English translations).
Conclusion
sd-scripts provides the essential infrastructure for anyone serious about customizing Stable Diffusion. By moving beyond simple GUI wrappers, it offers the precision and reproducibility required for professional-grade AI image generation. Whether you are training a character LoRA or fine-tuning an entire model, sd-scripts is the most powerful and flexible tool available for the task.
If you are a developer or artist looking to push the boundaries of AI art, we recommend starting with the LoRA training quickstart. Star the repo, try the quickstart, and join the community to share your results.
What is sd-scripts and what problem does it solve?
sd-scripts is a collection of training scripts for Stable Diffusion that allows users to efficiently fine-tune models using techniques like LoRA, DreamBooth, and Textual Inversion. It solves the problem of high VRAM requirements and massive model sizes associated with traditional full-parameter fine-tuning.
How do I install sd-scripts?
Installation involves cloning the GitHub repository, setting up a Python virtual environment, installing PyTorch and the required dependencies from requirements.txt, and running the accelerate config command to configure your hardware acceleration.
How does sd-scripts compare to other training tools?
Unlike many GUI-based trainers, sd-scripts is a CLI-first tool that provides deeper control over hyperparameters and reproducibility through configuration files, making it the industry standard for high-quality LoRA training.
Can I use sd-scripts for SDXL training?
Yes, it fully supports SDXL, allowing for higher resolution training and multi-resolution datasets, which is critical for the larger generation models.
What are the minimum system requirements for sd-scripts?
The minimum requirement is a compatible NVIDIA GPU with at least 8GB of VRAM for basic LoRA training. For SDXL or full fine-tuning, 12GB to 24GB of VRAM is strongly recommended to avoid out-of-memory errors.
What is the difference between LoRA and DreamBooth in sd-scripts?
LoRA (Low-Rank Adaptation) creates a small adapter file that is portable and easy to mix, while DreamBooth is a full-model fine-tuning technique that modifies the base model’s weights directly, resulting in a larger file size.
Is sd-scripts free and open source?
Yes, sd-scripts is licensed under the Apache License 2.0, which means it is free to use for both personal and commercial projects, provided the license terms are followed.
