Artificial Intelligence 12 min read

Step-by-Step Guide to Training a LoRA Model with Flux1_dev on ComfyUI

This tutorial walks programmers through preparing a GPU cloud environment, installing ComfyUI, downloading Flux1_dev models, integrating a custom LoRA, labeling generated images, and finally training the LoRA using ai‑toolkit, providing detailed commands, configuration tips, and practical cost estimates.

Architecture and Beyond
Architecture and Beyond
Architecture and Beyond
Step-by-Step Guide to Training a LoRA Model with Flux1_dev on ComfyUI

Last weekend the author spent five hours training a LoRA based on Flux1_dev to generate personal photos, documenting a complete, beginner‑friendly workflow that can be followed by any programmer with no prior LoRA training experience.

Environment preparation : Use a cost‑effective GPU cloud provider (e.g., autodl) and select a machine with a 4090D GPU and sufficient storage. After the container starts, use the provided web terminal, which persists after the browser is closed.

Running ComfyUI with Flux :

cd ~/autodl-tmp

git clone https://github.com/comfyanonymous/ComfyUI
cd ComfyUI
conda create -n comfyui python=3.12 -y
conda init
source ~/.bashrc
conda activate comfyui
pip install -r requirements.txt
python main.py

Access the UI via an SSH tunnel, e.g.:

ssh -CNg -L 8188:127.0.0.1:8188 -p 49027 [email protected]

Open http://localhost:8188/ in a browser to see the ComfyUI interface.

Downloading and running Flux : Download the four required model files (flux1.dev fp8, VAE, CLIP, T5XXL) from the HF mirror into the appropriate models/ sub‑directories. Load the Flux demo workflow in ComfyUI and run the queue; the first run may take ~10 seconds longer due to model loading.

Adding a LoRA to the pipeline : Place a downloaded LoRA file into models/loras , add a LoRA node in the UI, and adjust its weight (typically between 0.5 and 1.0) to control the influence on generated images.

Data labeling (tagging) : After generating satisfactory images, label them using tools such as Florence 2, JoyCaption, MiniCPM, or WD14. The guide recommends combining multiple tools and performing manual verification to ensure high‑quality tags, adding a custom identifier (e.g., bbdr ) for later use.

Running the WD‑tagger :

git clone https://github.com/phppan/wd-swinv2-tagger-v3-script
cd wd-swinv2-tagger-v3-script/
conda create -n wds python=3.12 -y
conda activate wds
pip install -r requirements.txt
mkdir data
export HF_ENDPOINT=https://hf-mirror.com

Upload the prepared images to the data folder and execute:

python wd_tag.py

The script generates a .txt file per image containing the tags, including the custom bbdr token.

Training the LoRA : Clone the ai‑toolkit repository and set up a conda environment.

git clone https://github.com/ostris/ai-toolkit
cd ai-toolkit/
git submodule update --init --recursive
conda create -n aitool python=3.12 -y
conda activate aitool
pip3 install torch
pip3 install -r requirements.txt

Copy the example training config and edit it (name, training_folder, folder_path) to point to the labeled dataset:

cp config/examples/train_lora_flux_24gb.yaml ./config/bbdr.yaml
vim ./config/bbdr.yaml

Start training:

python run.py ./config/bbdr.yaml

When training finishes, the resulting LoRA file (e.g., bbdr.safetensors ) is placed in the configured output directory. Move it to ComfyUI/models/loras , select it in the UI, and include the custom tag in the prompt (e.g., bbdr, a girl, portrait ) to generate personalized images.

Additional tips: use a non‑GPU instance for lightweight tasks to save cost, schedule automatic shutdowns, and ensure input photos are taken within a consistent time period for best results.

PythonLoRAGPUmodel trainingAI image generationFluxComfyUI
Architecture and Beyond
Written by

Architecture and Beyond

Focused on AIGC SaaS technical architecture and tech team management, sharing insights on architecture, development efficiency, team leadership, startup technology choices, large‑scale website design, and high‑performance, highly‑available, scalable solutions.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.