This repository provides a Windows-focused Gradio GUI for [Kohya's Stable Diffusion trainers](https://github.com/kohya-ss/sd-scripts). The GUI allows you to set the training parameters and generate and run the required CLI commands to train the model.
If you run on Linux and would like to use the GUI, there is now a port of it as a docker container. You can find the project [here](https://github.com/P2Enjoy/kohya_ss-docker).
This step is optional but can improve the learning speed for NVIDIA 30X0/40X0 owners. It allows for larger training batch size and faster training speed.
Due to the file size, I can't host the DLLs needed for CUDNN 8.6 on Github. I strongly advise you download them for a speed boost in sample generation (almost 50% on 4090 GPU) you can download them [here](https://b1.thefileditch.ch/mwxKTEtelILoIbMbruuM.zip).
Training a LoRA currently uses the `train_network.py` code. You can create a LoRA network by using the all-in-one `gui.cmd` or by running the dedicated LoRA training GUI with:
Once you have created the LoRA network, you can generate images via auto1111 by installing [this extension](https://github.com/kohya-ss/sd-webui-additional-networks).
This is usually related to an installation issue. Make sure you do not have any python modules installed locally that could conflict with the ones installed in the venv:
This will store your a backup file with your current locally installed pip packages and then uninstall them. Then, redo the installation instructions within the kohya_ss venv.
- Add `--use_lion_optimizer` to each training script to use [Lion optimizer](https://github.com/lucidrains/lion-pytorch).
- Please install Lion optimizer with `pip install lion-pytorch` (it is not in ``requirements.txt`` currently.)
- Add `--lowram` option to `train_network.py`. Load models to VRAM instead of VRAM (for machines which have bigger VRAM than RAM such as Colab and Kaggle). Thanks to Isotr0py!
- Default behavior (without lowram) has reverted to the same as before 14 Feb.
- Fixed git commit hash to be set correctly regardless of the working directory. Thanks to vladmandic!
- For LoRAs where the activation word is unknown, this script compares the output of Text Encoder after applying LoRA to that of unapplied to find out which token is affected by LoRA. Hopefully you can figure out the activation word. LoRA trained with captions does not seem to be able to interrogate.
- Following feature is reverted to be the same as before. Sorry for confusion:
> Now the number of data in each batch is limited to the number of actual images (not duplicated). Because a certain bucket may contain smaller number of actual images, so the batch may contain same (duplicated) images.
- Add new tool to sort, group and average crop image in a dataset
- Caption dropout is supported in ``train_db.py``, ``fine_tune.py`` and ``train_network.py``. Thanks to forestsource!
- ``--caption_dropout_rate`` option specifies the dropout rate for captions (0~1.0, 0.1 means 10% chance for dropout). If dropout occurs, the image is trained with the empty caption. Default is 0 (no dropout).
- ``--caption_dropout_every_n_epochs`` option specifies how many epochs to drop captions. If ``3`` is specified, in epoch 3, 6, 9 ..., images are trained with all captions empty. Default is None (no dropout).
- ``--caption_tag_dropout_rate`` option specified the dropout rate for tags (comma separated tokens) (0~1.0, 0.1 means 10% chance for dropout). If dropout occurs, the tag is removed from the caption. If ``--keep_tokens`` option is set, these tokens (tags) are not dropped. Default is 0 (no droupout).
- The bulk image downsampling script is added. Documentation is [here](https://github.com/kohya-ss/sd-scripts/blob/main/train_network_README-ja.md#%E7%94%BB%E5%83%8F%E3%83%AA%E3%82%B5%E3%82%A4%E3%82%BA%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88) (in Jpanaese). Thanks to bmaltais!
- Typo check is added. Thanks to shirayu!
- Add option to autolaunch the GUI in a browser and set the server_port. USe either `gui.ps1 --inbrowser --server_port 3456`or `gui.cmd -inbrowser -server_port 3456`
-`--bucket_reso_steps` and `--bucket_no_upscale` options are added to training scripts (fine tuning, DreamBooth, LoRA and Textual Inversion) and `prepare_buckets_latents.py`.
-`--bucket_reso_steps` takes the steps for buckets in aspect ratio bucketing. Default is 64, same as before.
- Any value greater than or equal to 1 can be specified; 64 is highly recommended and a value divisible by 8 is recommended.
- If less than 64 is specified, padding will occur within U-Net. The result is unknown.
- If you specify a value that is not divisible by 8, it will be truncated to divisible by 8 inside VAE, because the size of the latent is 1/8 of the image size.
- If the `--bucket_no_upscale` option is specified, images smaller than the bucket size will be processed without upscaling.
- Internally, a bucket smaller than the image size is created (for example, if the image is 300x300 and `bucket_reso_steps=64`, the bucket is 256x256). The image will be trimmed.
- Now the number of data in each batch is limited to the number of actual images (not duplicated). Because a certain bucket may contain smaller number of actual images, so the batch may contain same (duplicated) images.
- Instead of always cropping the center of the image, the image is shifted left, right, up, and down to be used as the training data. This is expected to train to the edges of the image.
- Implementation of discussion [#34](https://github.com/kohya-ss/sd-scripts/discussions/34).
-`--persistent_data_loader_workers` option is added to `fine_tune.py`, `train_db.py` and `train_network.py`. This option may significantly reduce the waiting time between epochs. Thanks to hitomi!
-`--debug_dataset` option is now working on non-Windows environment. Thanks to tsukimiya!
-`networks/resize_lora.py` script is added. This can approximate the higher-rank (dim) LoRA model by a lower-rank LoRA model, e.g. 128 to 4. Thanks to mgz-dev!
-`.bmp` and `.jpeg` are supported. Thanks to breakcore2 and p1atdev!
- The default weights of `tag_images_by_wd14_tagger.py` is now `SmilingWolf/wd-v1-4-convnext-tagger-v2`. You can specify another model id from `SmilingWolf` by `--repo_id` option. Thanks to SmilingWolf for the great work.
- To change the weight, remove `wd14_tagger_model` folder, and run the script again.
-`--max_data_loader_n_workers` option is added to each script. This option uses the DataLoader for data loading to speed up loading, 20%~30% faster.
-`--recursive` option is added to `merge_dd_tags_to_metadata.py` and `merge_captions_to_metadata.py`, only works with `--full_path`.
-`make_captions_by_git.py` is added. It uses [GIT microsoft/git-large-textcaps](https://huggingface.co/microsoft/git-large-textcaps) for captioning.
-`requirements.txt` is updated. If you use this script, [please update the libraries](https://github.com/kohya-ss/sd-scripts#upgrade).
- Usage is almost the same as `make_captions.py`, but batch size should be smaller.
-`--remove_words` option removes as much text as possible (such as `the word "XXXX" on it`).
-`--skip_existing` option is added to `prepare_buckets_latents.py`. Images with existing npz files are ignored by this option.
-`clean_captions_and_tags.py` is updated to remove duplicated or conflicting tags, e.g. `shirt` is removed when `white shirt` exists. if `black hair` is with `red hair`, both are removed.
- Tag frequency is added to the metadata in `train_network.py`. Thanks to space-nuko!
- __All tags and number of occurrences of the tag are recorded.__ If you do not want it, disable metadata storing with `--no_metadata` option.
- Add `--lr_scheduler_num_cycles` and `--lr_scheduler_power` options for `train_network.py` for cosine_with_restarts and polynomial learning rate schedulers. Thanks to mgz-dev!
- Fixed U-Net `sample_size` parameter to `64` when converting from SD to Diffusers format, in `convert_diffusers20_original_sd.py`
- Add `--network_alpha` option to specify `alpha` value to prevent underflows for stable training. Thanks to CCRcmcpe!
- Details of the issue are described [here](https://github.com/kohya-ss/sd-webui-additional-networks/issues/49).
- The default value is `1`, scale `1 / rank (or dimension)`. Set same value as `network_dim` for same behavior to old version.
- LoRA with a large dimension (rank) seems to require a higher learning rate with `alpha=1` (e.g. 1e-3 for 128-dim, still investigating).
- For generating images in Web UI, __the latest version of the extension `sd-webui-additional-networks` (v0.3.0 or later) is required for the models trained with this release or later.__
- Add more metadata such as dataset/reg image dirs, session ID, output name etc... See [this pull request](https://github.com/kohya-ss/sd-scripts/pull/77) for details. Thanks to space-nuko!
- __Now the metadata includes the folder name (the basename of the folder contains image files, not the full path).__ If you do not want it, disable metadata storing with `--no_metadata` option.
- Add `--training_comment` option. You can specify an arbitrary string and refer to it by the extension.
It seems that the Stable Diffusion web UI now supports image generation using the LoRA model learned in this repository.
Note: At this time, it appears that models learned with version 0.4.0 are not supported. If you want to use the generation function of the web UI, please continue to use version 0.3.2. Also, it seems that LoRA models for SD2.x are not supported.
- Fix a part of LoRA modules are not trained when `gradient_checkpointing` is enabled.
- Add `--save_last_n_epochs_state` option. You can specify how many state folders to keep, apart from how many models to keep. Thanks to shirayu!
- Fix Text Encoder training stops at `max_train_steps` even if `max_train_epochs` is set in `train_db.py`.
- Added script to check LoRA weights. You can check weights by `python networks\check_lora_weights.py <model file>`. If some modules are not trained, the value is `0.0` like following.
-`lora_te_text_model_encoder_layers_11_*` is not trained with `clip_skip=2`, so `0.0` is okay for these modules.
- You can set the number of workers for DataLoader with `--max_data_loader_n_workers`, default is 8. The lower number may reduce the main memory usage and the time between epochs, but may cause slower data loading (training).
- Fix loading some VAE or .safetensors as VAE is failed for `--vae` option. Thanks to Fannovel16!
- Add negative prompt scaling for `gen_img_diffusers.py` You can set another conditioning scale to the negative prompt with `--negative_scale` option, and `--nl` option for the prompt. Thanks to laksjdjf!
- Emergency fix for new version of gradio causing issues with drop down menus. Please run `pip install -U -r requirements.txt` to fix the issue after pulling this repo.