Linaqruf / kohya-trainer

Adapted from https://note.com/kohya_ss/n/nbf7ce8d80f29 for easier cloning
Apache License 2.0
1.85k stars 307 forks source link

Run on Runpod / Vast.ai #5

Closed andykaufseo closed 1 year ago

andykaufseo commented 1 year ago

Is there any way we can run this on a runpod or vast.ai instance? I tried but got suck along the way...

JeremiasGiglio commented 1 year ago

Any update?

vibrantrida commented 1 year ago

I've been trying to get this to work on Runpod for awhile, after a lot of failed attempts I realized it wasn't that hard. Here's what I did to run the diffusers fine-tuner notebook, I haven't tried the dreambooth notebook on runpod yet.

  1. Create a pod using one of the automatic1111's SD webui templates, and start the web terminal and run the following commands:

    cd /workspace
    git clone https://github.com/Linaqruf/kohya-trainer
    apt-get update && apt-get install unzip -y libgl1 libglib2.0-0
    pip install gdown
  2. Stop the web terminal then connect to jupyter lab, expand the kohya-trainer directory and open the kohya-trainer.ipynb notebook. Replace /content with /workspace (Use CTRL+F to search and replace all).

  3. You will have to skip the "Install Diffuser Fine Tuning" code block especially if you are only interested in the latest version of this repo.

  4. Modify the following code blocks:

    • Installing Dependencies Remove/Comment out the following line: !pip install -U -I --no-deps https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.15/xformers-0.0.15.dev0+189828c.d20221
    • Login to Huggingface hub If you want to commit your fine-tuned model to Huggingface later, change login to notebook_login, ex:
      from huggingface_hub import notebook_login
      notebook_login()
    • Install Pre-trained Model Modify this entire code block, replace it with the following code:
      
      #@title Install Pre-trained Model 
      %cd /workspace/kohya-trainer
      import os

    Check if directory exists

    if not os.path.exists('checkpoint'):

    Create directory if it doesn't exist

    os.makedirs('checkpoint')

    model_url = "https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.ckpt" model_name = "sd15"

    !gdown --fuzzy {model_url} -O /workspace/kohya-trainer/checkpoint/{model_name}.ckpt

    
    Change the `model_url` and `model_name` to whatever model it is you want to use as a base for your training. Do not forget to change the path to the model in code blocks following this one, it should point to where your model is located.
  5. After training, you will find your output in the /workspace/kohya-trainer/fine_tuned/ directory, the last.ckpt is usually what you want unless it is over-trained, move the model of your choice to /workspace/stable-diffusion-webui/models/Stable-diffusion. You can also do this inside the notebook by adding a new code cell:

    !mv /workspace/kohya-trainer/fine-tuned/last.ckpt /workspace/stable-diffusion-webui/models/Stable-diffusion/last.ckpt
  6. Go back to your pods dashboard and connect to the web server and wait for the web ui to load, refresh the model list on the top-left corner of the web ui and load your fine-tuned model. Do not forget to change the CLIP skip to 2 in the settings!