Prerequisites
Before you install sd-scripts, make sure your system meets the following requirements:
- Python 3.10.x — Python 3.11.x and 3.12.x may work but are not officially tested.
- Git — Required to clone the repository and pull updates.
- NVIDIA GPU with CUDA support — A CUDA 12.4-capable GPU is recommended. The default PyTorch install targets CUDA 12.4.
Python 3.10.x is the recommended version. Other versions (3.11.x, 3.12.x) are not fully tested and may produce unexpected behavior with some dependencies.
Install
Windows required dependencies
Download and install the following before proceeding:You also need to allow PowerShell to run virtual environment activation scripts. Open an administrator PowerShell window and run:Set-ExecutionPolicy Unrestricted
Answer A when prompted, then close the administrator window.Installation steps
Open a regular PowerShell terminal and run each command in order:Clone the repository
git clone https://github.com/kohya-ss/sd-scripts.git
cd sd-scripts
Create and activate a virtual environment
python -m venv venv
.\venv\Scripts\activate
If python is not recognized, try py -m venv venv instead.Install PyTorch with CUDA support
pip install torch==2.6.0 torchvision==0.21.0 --index-url https://download.pytorch.org/whl/cu124
This installs PyTorch 2.6.0 for CUDA 12.4. If you use a different CUDA version, change the index URL accordingly. For CUDA 12.1 use cu121.Install requirements
pip install --upgrade -r requirements.txt
Configure accelerate
When prompted, use these answers:- This machine
- No distributed training
- NO
- NO
- NO
- all
- fp16
Answer bf16 to the last question if you want to use bfloat16 mixed precision. If you see ValueError: fp16 mixed precision requires a GPU, answer 0 for the GPU selection question to explicitly select GPU 0. Linux/WSL2 prerequisites
Make sure the NVIDIA driver and CUDA toolkit are installed on your system before proceeding.Clone the repository
git clone https://github.com/kohya-ss/sd-scripts.git
cd sd-scripts
Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate
Install PyTorch with CUDA support
pip install torch==2.6.0 torchvision==0.21.0 --index-url https://download.pytorch.org/whl/cu124
Change cu124 to match your installed CUDA version if needed. For CUDA 12.1 use cu121.Install requirements
pip install --upgrade -r requirements.txt
Configure accelerate
When prompted, use these answers:- This machine
- No distributed training
- NO
- NO
- NO
- all
- fp16
Answer bf16 to the last question if you prefer bfloat16 mixed precision. DeepSpeed (optional, Linux/WSL2 only)
DeepSpeed enables ZeRO optimization for large-scale training. Install it inside your activated virtual environment:pip install deepspeed==0.16.7
DeepSpeed support is experimental. It is only available on Linux and WSL2.
About requirements.txt and PyTorch
requirements.txt does not include PyTorch. The correct PyTorch version depends on your GPU architecture and CUDA version, so you must install it separately before running pip install -r requirements.txt.
PyTorch 2.6.0 or later is required. The scripts are tested with PyTorch 2.6.0.
For RTX 50 series GPUs, use PyTorch 2.8.0 with CUDA 12.8 or 12.9. The existing requirements.txt is compatible with that version.
Key packages installed by requirements.txt include:
accelerate — Distributed training and mixed precision launcher
transformers, diffusers — Model loading and inference
bitsandbytes — 8-bit optimizers for reduced VRAM usage
safetensors — Safe model serialization format
prodigyopt, lion-pytorch — Alternative optimizers
tensorboard — Training metrics visualization
Upgrading
When a new release is available, pull the latest code and reinstall requirements:
cd sd-scripts
git pull
.\venv\Scripts\activate
pip install --use-pep517 --upgrade -r requirements.txt
cd sd-scripts
git pull
source venv/bin/activate
pip install --use-pep517 --upgrade -r requirements.txt
Upgrading PyTorch
To upgrade PyTorch independently, run the same pip install torch==... command from the installation steps above with your target version.
xformers provides memory-efficient attention implementations that can reduce VRAM usage and speed up training. Install it inside your activated virtual environment:
pip install xformers --index-url https://download.pytorch.org/whl/cu124
Change the CUDA version in the URL to match your environment. xformers may not be available for all GPU architectures.