kohya_ss, ShivamShrirao, bmaltais, C43H66N12O12S2, DeXtmL, nitrosocke
Based on my testing this setup consumes around 11425MiB / 12282MiB of VRAM provided all other GPU consuming applications are closed.
You must have git installed to continue. Clone the kohya_ss repo
git clone https://github.com/bmaltais/kohya_ss.git
We need bitsandbytes_windows folder inside this repo, so we will clone it to the current directory. Let's leave this for a while and clone the ShivamShiraro repo
git clone https://github.com/ShivamShrirao/diffusers.git
So you now have 2 folders in your directory kohya_ss and diffusers
Copy the bitsandbytes_windows folder inside kohya_ss folder to diffusers/example/dreambooth folder. You should now have a folder structure like this
└── diffusers
└── example
└── dreambooth
├── concepts_list.json
├── DreamBooth_Stable_Diffusion.ipynb
├── launch.sh
├── launch_inpaint.sh
├── README.md
├── requirements.txt
├── requirements_flax.txt
├── train_dreambooth.py
├── train_dreambooth_flax.py
├── train_dreambooth_inpainting.py
└── bitsandbytes_windowsReplace the contents of requirements.txt with the following
accelerate
transformers>=4.21.0
ftfy
albumentations
tensorboard
modelcards
You must have Python 3.10.6 installed on your system. Open Command Prompt and run the following commands
python -m venv --system-site-packages 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 git+https://github.com/ShivamShrirao/diffusers.git
pip install -U -r requirements.txt
pip install OmegaConf
pip install pytorch_lightning
pip install -U -I --no-deps https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl
pip install bitsandbytes==0.35.0
copy .\bitsandbytes_windows\*.dll .\venv\Lib\site-packages\bitsandbytes\
copy .\bitsandbytes_windows\cextension.py .\venv\Lib\site-packages\bitsandbytes\cextension.py
copy .\bitsandbytes_windows\main.py .\venv\Lib\site-packages\bitsandbytes\cuda_setup\main.pyType accelerate config and answer the following propmpts in this order:
accelerate config
NOTE: Redirects are currently not supported in Windows or MacOs.
In which compute environment are you running? ([0] This machine, [1] AWS (Amazon SageMaker)): 0
Which type of machine are you using? ([0] No distributed training, [1] multi-CPU, [2] multi-GPU, [3] TPU [4] MPS): 0
Do you want to run your training on CPU only (even if a GPU is available)? [yes/NO]: NO
Do you want to use DeepSpeed? [yes/NO]: NO
What GPU(s) (by id) should be used for training on this machine as a comma-seperated list? [all]: all
Do you wish to use FP16 or BF16 (mixed precision)? [NO/fp16/bf16]: fp16
Note
allis case sensitive. You should type it as it is
Create a file called launch.bat with the following contents
accelerate launch --num_cpu_threads_per_process 6 train_dreambooth.py ^
--pretrained_model_name_or_path="runwayml/stable-diffusion-v1-5" ^
--pretrained_vae_name_or_path="stabilityai/sd-vae-ft-mse" ^
--output_dir="./output" ^
--with_prior_preservation --prior_loss_weight=1.0 ^
--seed=494481440 ^
--resolution=512 ^
--train_batch_size=1 ^
--train_text_encoder ^
--mixed_precision="fp16" ^
--use_8bit_adam ^
--gradient_checkpointing ^
--gradient_accumulation_steps=1 ^
--learning_rate=1e-6 ^
--lr_scheduler="constant" ^
--lr_warmup_steps=0 ^
--num_class_images=200 ^
--sample_batch_size=4 ^
--max_train_steps=800 ^
--save_interval=200 ^
--save_sample_prompt="photograph zwx person" ^
--concepts_list="concepts_list.json" ^
--n_save_sample=5 ^
--save_min_steps=800
pause
Edit concepts_list.json and add your own concepts.
[
{
"instance_prompt": "photo of zwx person",
"class_prompt": "photo of person",
"instance_data_dir": "../../../data/zwx",
"class_data_dir": "../../../data/person"
}
]Note paths should NOT use \ instead use /
You place your training images to instance_data_dir . The class_data_dir images will be automatically generated based on the class you are training. For more detailed explanation visit the original notebook
Open the terminal and activate the venv and run the script
.\venv\Scripts\activate
launch.batOn the diffusers repo go to diffusers/scripts/ folder. Open a terminal and run the following commands
convert_diffusers_to_original_stable_diffusion.py --model_path <folder input path> --checkpoint_path <model output path> --half| Name | Description |
|---|---|
| model_path | Is a folder as diffusers model outputs as a folder. In this case it would be ./output as defined in the --output_dir parameter |
| checkpoint_path | Is the path where you want to save your .ckpt file. This path should include the filename.ckpt eg. /models/filename.cpkt |
hey, I have kohya running no probs already and wanted to try this but ran into problems. After some head scratching I realised terminal wasn't liking the copy command used for bits and bytes.
Changing to the following fixed the problem and it's all running now -
Thanks for the guide :)