ThereforeGames / blora_for_kohya

Tools needed for training B-LoRA method with sd-scripts.
22 stars 0 forks source link

B-LoRA for Kohya-SS

This repository contains tools needed for training B-LoRA files with kohya-ss/sd-scripts.

What is B-LoRA and why should I care?

The B-LoRA method "enables implicit style-content separation" for SDXL LoRAs. In other words, if you wish to train a character, you can use this method to avoid picking up unwanted styles, colors or layouts - i.e. features that often creep into character LoRAs by mistake.

B-LoRA's approach works quite well, and it deserves more recognition in the broader Stable Diffusion community.

Combining it with sd-scripts gives you access to awesome features like aspect ratio bucketing.

How does B-LoRA work?

B-LoRA targets specific unet blocks that correlate surprisingly well to content and style. It seems best to learn these traits in tandem, and then use the provided blora_slicer.py on the final LoRA to preserve only the traits you want to keep.

Additionally, the B-LoRA trainer has several non-standard options that I have specified in sdxl_blora_project.bat.

Setup and Use

  1. Install the Lycoris network.
  2. Download this repo and place all its files into the root of your kohya-ss directory.
  3. Make a copy of sdxl_blora_project.bat, adjust it to your needs (in particular, the topmost variables and paths), then launch to begin training.
  4. Run blora_slicer.bat on the resulting LoRA to filter out content or style blocks. This will produce a final, smaller LoRA that you can use in the WebUI or Comfy.

Note that while these batch files are for Windows, it should be trivial to adapt them to Linux.

If you're using the Kohya GUI instead of sd-scripts, the Lycoris features are pre-installed and you will need to plug in the sdxl_blora_project.bat settings by hand.


Notes on sdxl_blora_project.bat

Notes on blora_slicer.bat

This tool is adapted from B-LoRA's inference.py.

You only need to set up one argument:

Additional optional arguments are available:

Notes on Lycoris presets

The Lycoris preset determines which unet blocks to train.


⭐ Feel free to give this repo a star if you found it helpful.

Thank you to @slashedstar for introducing the idea of using Lycoris to recreate the B-LoRA method.