How to Train Flux LoRa Locally with Kohya ss
Prepare training data
example training data:
https://drive.google.com/file/d/1PQ_I1mqLPJ5QxqqKWtXS3UpJ292-jmkQ/view?usp=sharing
download and unzip
for example your unzip location would be:
D:/samples/
and inside it :
D:/samples/1_fernsoso_girl/001.png & 001.txt .. .. ..
Install Git
https://git-scm.com/downloads/win
Download flux.1-dev
https://huggingface.co/black-forest-labs/FLUX.1-dev
Download kohya ss
Then we need to download kohya ss to our machine.
go to this github repo and clone it out.
https://github.com/bmaltais/kohya_ss
for example your local disk location is :
D:/git
then:
cd D:/git
git clone https://github.com/bmaltais/kohya_ss.git
Install Python
We also need to have a python installation in our machine as well. Kohya ss recommends Python 3.10.11 so we’re gonna use that.
https://www.python.org/downloads/release/python-31011/
Download Windows installer (64-bit) and install it to your machine
for example your python installation location is :
D:/Python-3-10-11
Create Python virtual environment
Go to your local git repo disk location:
cd D:/git/kohya-ss
since Flux training codes aren’t merged into main branch yet, we need to checkout sd3-flux.1 branch
git checkout sd3-flux.1
then we need to create a python environment to install the required library
mkdir venv
cd venv
D:/Python-3-10-11/python.exe -m venv flux
Install the required libraries
after the virtual environment is created, go back to base dir:
cd D:/git/kohya-ss
then activate the virtual environment:
./venv/flux/Scripts/Activate
After that we can start installing the python requirements
pip install -r requirements.txt
pip install torch==2.4.1+cu124 torchvision==0.19.1+cu124 xformers==0.0.28.post1 --index-url https://download.pytorch.org/whl/cu124
pip install -r requirements_windows.txt
Launch kohya web ui
Now we’re ready to launch kohya web gui
python kohya_gui.py
if you see this then it means you can launch kohya web gui successfully
in your web browser, go to the url displayed above. Usually it will be
http://127.0.0.1:7860 or http://localhost:7860/
go to LoRa and Training tab
Next we need to fill in the Flux.1 related values, i.e : VAE Path, CLIP-L Path , and T5-XXL Path
The first two should be available from the flux1-dev download directory
As for T5-XXL Path, our flux1-dev text_encoder_2 dir contains models that are split into two files, but this field only accepts single file so we need to find a single file safetensors for it.
I managed to find one below. Download the t5xxl_fp16.safetensors and put the file path to the field there
https://huggingface.co/comfyanonymous/flux_text_encoders/tree/main
Now we are ready to train, just hit “Start Training “ button.
Training finished
After the training is finished, go to the output folder you specified above, and the LoRa safetensors would be there. In the cases of settings above, the LoRa file will be:
D:/training_output/fern.safetensors