Train a FLUX LoRA with Kohya sd-scripts: Dataset, Config, network_dim

Prepare a dataset, configure flux_train_network.py, choose network_dim (rank) and network_alpha, and fit FLUX.1 LoRA training into 16 GB or less with sd-scripts.

7 min read2025-03-05

Train a FLUX LoRA with Kohya sd-scripts

LoRA (Low-Rank Adaptation) fine-tunes a model on your own images by training a small set of extra weights instead of the whole model. This guide builds a character or style LoRA for FLUX.1 Dev with kohya-ss/sd-scripts, using its flux_train_network.py script. Options and VRAM guidance follow the sd-scripts FLUX documentation.

NeuralDrift has not yet published a recorded FLUX LoRA training run, so this guide gives no training-time figures. Time depends on GPU, dataset size, resolution, repeats, epochs and memory-saving options.

#Hardware Requirements

The sd-scripts FLUX documentation gives these starting points by VRAM:

VRAMsd-scripts recommendation
24 GBBasic settings work (batch size 2)
16 GBBatch size 1 and --blocks_to_swap
12 GB--blocks_to_swap 16 and 8-bit AdamW
10 GB--blocks_to_swap 22, fp8 T5-XXL recommended
8 GB--blocks_to_swap 28, fp8 T5-XXL recommended

An RTX 5080 has 16 GB, so start from the 16 GB row. --blocks_to_swap moves transformer blocks between CPU and GPU. It saves VRAM at the cost of speed, and needs enough system RAM.

#Step 1 — Dataset Preparation

Training data quality drives most of the result.

  • →Quantity: a small, varied set is common for a character, and a larger set for a style.
  • →Resolution: 1024×1024 or larger source images. sd-scripts buckets mixed aspect ratios if you enable bucketing.
  • →Variety: different angles, lighting and expressions for a character; diverse examples for a style.
  • →Quality: sharp images with no compression artifacts or watermarks.

Folder Structure

sd-scripts' DreamBooth-style folder naming puts the repeat count in the folder name:

comfyui-workflow.json
my_dataset/ ├── img/ │ └── 10_mychar/ # "10" = repeats per epoch │ ├── image_001.jpg │ ├── image_001.txt # caption file │ └── ... ├── log/ └── model/

The number before the underscore is how many times each image is shown per epoch. Use more repeats for small datasets and fewer for large ones.

#Step 2 — Captioning

Every image needs a caption file with the same name. sd-scripts includes a WD14 tagger script that writes tag-style captions:

comfyui-workflow.json
python finetune/tag_images_by_wd14_tagger.py --batch_size 4 --caption_extension .txt ./my_dataset/img/10_mychar

FLUX's T5 text encoder reads natural language, so many trainers write short sentence captions instead of tags, or edit the tagger output. Either way, start every caption with a unique trigger word:

comfyui-workflow.json
mychar, a woman with blonde hair standing outdoors in sunlight

The trigger word (mychar) is what you put in prompts to activate the LoRA.

#Step 3 — Install sd-scripts

comfyui-workflow.json
git clone https://github.com/kohya-ss/sd-scripts cd sd-scripts python -m venv venv .\venv\Scripts\activate

Install PyTorch following the sd-scripts README, using a CUDA build that supports your GPU. RTX 50-series (Blackwell) cards need PyTorch built for CUDA 12.8 or newer, so older cu121 or cu124 commands will not work on an RTX 5080. Then:

comfyui-workflow.json
pip install -r requirements.txt accelerate config

#Step 4 — Training Command

FLUX.1 LoRA training needs four model files: the FLUX.1 model, CLIP-L, T5-XXL and the FLUX autoencoder (ae). This command follows the sd-scripts FLUX example, adjusted for 16 GB:

comfyui-workflow.json
accelerate launch --num_cpu_threads_per_process 1 flux_train_network.py ^ --pretrained_model_name_or_path C:/models/flux1-dev.safetensors ^ --clip_l C:/models/clip_l.safetensors ^ --t5xxl C:/models/t5xxl_fp16.safetensors ^ --ae C:/models/ae.safetensors ^ --train_data_dir C:/my_dataset/img --resolution 1024,1024 --enable_bucket ^ --output_dir C:/my_dataset/model --output_name mychar_lora_v1 ^ --network_module networks.lora_flux --network_dim 16 --network_alpha 1 ^ --optimizer_type AdamW8bit --learning_rate 1e-4 ^ --train_batch_size 1 --max_train_epochs 10 --save_every_n_epochs 2 ^ --mixed_precision bf16 --save_precision bf16 --fp8_base ^ --gradient_checkpointing --blocks_to_swap 18 ^ --cache_latents_to_disk --cache_text_encoder_outputs --cache_text_encoder_outputs_to_disk ^ --guidance_scale 1.0 --timestep_sampling flux_shift --model_prediction_type raw ^ --sdpa --seed 42

The ^ characters continue the command across lines in Windows Command Prompt. Use \ on Linux.

Several FLUX options matter more than they look:

  • →--guidance_scale 1.0: sd-scripts defaults to 3.5, and its docs say to set this explicitly; use 1.0 for FLUX.1.
  • →--timestep_sampling flux_shift and --model_prediction_type raw: the documented recommendations for FLUX.1.
  • →--cache_text_encoder_outputs: caches CLIP-L and T5-XXL outputs once, which reduces memory use during training.

#network_dim (rank) and network_alpha

Searches for flux_train_network.py network_dim rank usually come down to two settings:

--network_dim is the LoRA rank. Each adapted layer gets two small matrices of this inner dimension. A higher rank gives the LoRA more capacity to learn detail. It also makes the file larger, uses more VRAM, and makes it easier to overfit a small dataset. The sd-scripts FLUX example uses 16. Characters and styles commonly use 16–32; going much higher mainly pays off for broad styles with large datasets.

--network_alpha scales the LoRA's effect. sd-scripts scales the learned weights by alpha / dim. With --network_dim 16 --network_alpha 1, updates are scaled by 1/16, which acts like a lower effective learning rate. Setting alpha equal to dim removes the scaling.

Because of that scaling, change dim and alpha together, and retest the learning rate. If you raise dim from 16 to 32 but keep alpha at 1, the effective step size halves. If results come out weak or undertrained after changing rank, raise the learning rate or alpha.

Per-layer ranks are also possible: the sd-scripts docs note that network_reg_dims inside --network_args overrides the global --network_dim for matching layers.

Other settings:

  • →--learning_rate: 1e-4 is a common start for FLUX LoRAs. Lower it if the LoRA overpowers prompts.
  • →--max_train_epochs: save every couple of epochs and compare the checkpoints instead of trusting a single final file.

#Step 5 — Monitor Training

Run the command and watch the logged loss. It should trend down overall while fluctuating step to step. If it plateaus very early or spikes, lower the learning rate. To track runs, add --logging_dir C:/my_dataset/log and open the logs in TensorBoard.

#Step 6 — Evaluate Your LoRA

Test each saved checkpoint in ComfyUI with a fixed seed and prompt:

comfyui-workflow.json
mychar, portrait photo, professional lighting, sharp focus

Start with LoRA strength 0.8 and adjust from about 0.6 (subtle) to 1.0 (strong).

Good signs:

  • →The subject is recognizable at moderate strength
  • →The prompt still controls background, lighting and pose
  • →No artifacts or distortion

Bad signs:

  • →Only activates near strength 1.0 or above (undertrained)
  • →Everything looks like the subject, or prompts stop working (overtrained)
  • →Noise or artifacts (learning rate too high)

#Step 7 — Use It in ComfyUI

Copy the trained .safetensors file to ComfyUI/models/loras/. Load it with a LoRA loader node between the model loader and the sampler, then set its strength.

#Common Issues

Out of memory at start. Make sure --train_batch_size 1, --gradient_checkpointing, --fp8_base and --cache_text_encoder_outputs are set, then raise --blocks_to_swap. Using an fp8 T5-XXL file also helps on 10–12 GB cards.

CUDA errors on an RTX 50-series card. Your PyTorch build predates Blackwell support. Reinstall PyTorch built for CUDA 12.8 or newer; see the ComfyUI RTX 5080 setup guide.

Loss not decreasing. Check that the captions are correct and the trigger word is consistent, and that the dataset folder name includes the repeat count.

Subject not activating. Train more epochs, raise the learning rate, or increase network_alpha relative to network_dim.

Overfitting. Use fewer epochs or repeats, a lower rank, or a more varied dataset.

Slow training. --blocks_to_swap trades speed for VRAM, so use the lowest value that fits. Keep latent and text-encoder caching on.

CONTINUE LEARNING

NEXT REFERENCE

// NeuralDrift Weekly

Get NeuralDrift Weekly

Execution-tested workflows, compatibility findings, ComfyUI changes, and practical local-AI guidance — delivered weekly.

No spam, unsubscribe anytime. See our privacy policy.