Surreal artwork of a girl surrounded by goldfish with text "How to Install Kohya GUI
,

Easy Installation of Kohya_ss GUI: Learn to Fine-Tune Stable Diffusion Models

Do you want to fine-tune Stable Diffusion models that can generate high-quality text and image pairs? Do you want to do it efficiently and effectively without requiring excessive computational resources and memory? If yes, then you need Kohya_ss GUI, a convenient and powerful interface for LoRA, Dreambooth and Textual Inversion training. This is a guide on the Kohya_ss GUI Installation, where you will easily learn how to install the Kohya_ss to to be used as an application to fine-tune Stable Diffusion models.

Low-Rank Adaptation

LoRA is an innovative technique that leverages the pre-trained model weights and injects trainable rank decomposition matrices into each layer of the Transformer architecture. This reduces the number of trainable parameters and the GPU memory requirement for fine-tuning, while achieving comparable or better performance than full fine-tuning. LoRA also does not introduce any additional inference latency, unlike some other techniques such as adapters.

DreamBooth Training

DreamBooth is a technique that fine-tunes diffusion models by injecting a custom subject to the model. For example, you can use DreamBooth to put your cat, your car, or your style into a text-to-image model. You only need a few images of your subject to train DreamBooth, and then you can use natural language sentences to guide the image generation. DreamBooth preserves the meaning of the original class, such as animal or vehicle, while adding your personal touch to the model.

Textual Inversion Embedding

Textual Inversion is a technique that fine-tunes the text embedding part of a diffusion model by adding a new word to represent a concept. For example, you can use Textual Inversion to add a word like “sunset” or “rainbow” to a model that does not have them. You only need a few text and image pairs of your concept to train Textual Inversion, and then you can use the new word in natural language sentences to generate images. Textual Inversion does not affect the rest of the model, so you can still use the existing words and classes.


Easy Installation of Kohya_ss GUI: Learn to Fine-Tune Stable Diffusion Models

Kohya GUI is a web-based application that enables you to easily integrate LoRA with PyTorch models, such as those from Hugging Face. You can select any model that can generate text and image pairs, such as stabilityai/stable-diffusion-xl-base-1.0, and fine-tune it on your own dataset. You can also monitor the training progress and visualize the generated samples in real-time.

In this tutorial, I will show you how to install Kohya GUI and use it to fine-tune stable diffusion models with DreamBooth, LoRA and Textual Inversion. I will also provide you with links for all my training workflows and provide you with you with beginner to advance tips and tricks to improve your results and avoid common pitfalls. By the end of this tutorial, you will have installed the Kohya_ss GUI and will be ready to start training your own Stable Diffusion models.

Before you start, you need to install the necessary packages for LoRa training. This tutorial requires you to have three packages installed on your system: Microsoft Visual C++ Redistributable, Python 3.10.9, and Git for windows. You can find a detailed guide on how to install them [here].

Clone the Kohya GUI Repository

Kohya_ss GUI Clone Repository
Kohya_ss GUI Clone Repository

After cloning the Kohya GUI repository folder, go to the ‘kohya_ss’ folder and look for the ‘setup’ Windows Batch File. Launch the command window by double clicking it and you’ll see the menu below in the command prompt.

After installing the necessary packages for LoRa training, you can copy the Kohya GitHub repository to your preferred drive using GitHub Desktop. I recommend creating a dedicated folder for Kohya LoRa training in your chosen location.

Kohya GUI Repository [https://github.com/bmaltais/kohya_ss]

  • Click on File > Clone repository

  • Go to URL tab

  • Copy and paste the Kohya GitHub Repository in the first line.

  • Choose your Local path for Installation

  • Click on Clone.

Install Kohya GUI

Kohya_ss GUI set up menu
Kohya_ss GUI set up menu
  • Install kohya_ss gui (Select this)

  • (Optional) Install cudann files (avoid unless you really need it)

  • (Optional) Install specific bitsandbytes versions

  • (Optional) Manually configure accelerate

  • (Optional) Start Kohya_ss GUI in browser

  • Quit

You’ll now be asked some questions on screen. Below is how to proceed:

[1] – Yes

[2] – No (recommended for most)

Enter your choice (1 or 2):

I have tested both of them on my RTX 3090 graphic card and I found that Torch version 1.12 is working better, so select [1] to proceed.

Please select a choice using the arrow or number keys, and selecting with enter

  • This Machine

  • AWS (Amazon SageMaker)

Please select a choice using the arrow or number keys, and selecting with enter

  • No distributed training

  • multi-CPU

  • multi-XPU

  • multi-GPU

  • multi-NPU

  • TPU

  • If you have a GPU card which has over 8gb VRAM, then select NO.

  • If you have a GPU card which has under 8gb VRAM, then select YES.

NO

NO

ALL

This is important, not all of the cards support bf16. If you have a lower VRAM GPU, then you should pick fp16 or bf16 depending on your card. I have over 8gb VRAM therefore, I am selecting, no.

  • No

  • fp16

  • bf16

  • fp8

  • Press 6. Quit

    Close the Command Prompt Window and your installation is complete.

Update: no longer recommended unless absolutely necessary.

The following steps are optional, but will increase the training speed. We are going to update the cuDNN file because on the KohyaSS GitHub repository page, they mentioned that cuDNN 8.6 dll files will significantly increase your learning speed when using NVIDIA 30X0/40X0 GPUs.

These steps enable larger training batch sizes and faster training speeds.
You can download them [here] to boost sample generation speed (almost 50% on a 4090 GPU).
After downloading the ZIP file, follow the installation steps below:

  • Unzip the downloaded file:

    Place the cudnn_windows folder in the root directory of the kohya_ss repository. (ie: D:\Kohya LoRa Training)

  • Run kohya’s setup.bat again:

    Select the option to ‘Install cudann files’. (Option 2.)

  • Done Installing CUDNN.

Updating Kohya_ss GUI

If a new release becomes available, you can upgrade your repository by running the following commands from the root directory of the project:

Type git pull in the root directory in CMD to update.

To update Kohya_ss GUI:

  • Go to the ‘Kohya_ss’ root directory, as shown in the image above.

  • Click on the empty directory bar and type cmd.

  • The command prompt window will launch with the ‘kohya_ss’ directory.

  • Type git pull and it will update the ‘kohya_ss GUI’.

  • Relaunch Kohya_ss GUI.

  • DONE!

Alternatively, you can copy the ‘kohya_ss’ root directory by right-clicking the folder root directory and selecting ‘Copy Address’.

  • Launch Command Prompt by typing cmd in your Windows search bar. (Type here to search bar, bottom left of Windows)

  • Type cd followed by the copied address, nFor example: cd D:\Kohya LoRa Training\kohya_ssn

  • Then type git pull.

  • Relaunch Kohya_ss GUI.n

  • DONE!

Here is how the commands look like in a code block:

cmd
git pull
cd D:\Kohya LoRa Training\kohya_ss
git pull

To start the Kohya UI:

  • Find the ‘gui’ windows batch file in your Kohya_ss installation folder and double click it.

    A new cmd window will show up with a public link to the Kohya UI that looks like this:

  • Running on local URL: http://127.0.0.1:7860’. (Yours will be different)
    This URL is the same as your Automatic1111 WebUI.

Kohya_ss GUI LoRa Interface
Kohya_ss GUI LoRa Interface
Image Captioning Methods: A Comparative Analysis of Their Strengths and Weaknesses
Image Captioning Methods: A Comparative Analysis of Their Strengths and Weaknesses

Find out the strengths and weaknesses of different Image Captioning Methods. A comparative analysis to help you choose the best method for your needs.

Congratulations!

You have successfully installed the Kohya_ss GUI. This is the first of a series of videos that will teach you how to train Stable Diffusion models. In the next blog, I will show you how to use the Kohya GUI Interface.

Next: Kohya GUI Interface:


Tags And Categories

In: ,

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Horizontal ad will be here