Loading...
Loading...
Prepare datasets and configure LoRA training for character consistency. Covers FLUX (AI-Toolkit, SimpleTuner, FluxGym) and SDXL (Kohya_ss) training with step-by-step guidance. Use when training custom character LoRAs.
npx skill4agent add mckruz/comfyui-expert comfyui-lora-training| Scenario | Recommendation |
|---|---|
| Need absolute consistency across many images | Train LoRA |
| Building a character series or ongoing project | Train LoRA |
| Quick one-off generation | Use zero-shot (InstantID/PuLID) |
| Limited references (1-5 images) | Use zero-shot |
| Testing concepts | Use zero-shot first, train if committing |
1. DATASET PREP
|-- Collect/generate 15-30 reference images
|-- Preprocess (crop, resize, diversify styles)
|-- Caption with trigger word + descriptions
|
2. CONFIGURE TRAINING
|-- Select training tool (Kohya/AI-Toolkit/FluxGym)
|-- Set hyperparameters based on model type
|-- Configure checkpointing
|
3. TRAIN
|-- Monitor loss curve
|-- Save checkpoints every 250-500 steps
|
4. EVALUATE
|-- Test each checkpoint with identical prompts
|-- Check identity accuracy, flexibility, overfitting
|-- Select best checkpoint
|
5. INTEGRATE
|-- Copy to ComfyUI models/loras/
|-- Update character profile with trigger word + strength
|-- Test in full workflow (LoRA + identity method)| Aspect | Minimum | Optimal | Maximum |
|---|---|---|---|
| Count | 10-15 | 20-30 | 50+ |
| Resolution | 512x512 | 1024x1024 | - |
| Format | PNG/high JPEG | PNG | - |
"photorealistic portrait, dslr photo"
"oil painting portrait"
"digital illustration"
"pencil sketch"
"watercolor portrait"sage_characterohwx_sagesks_personwomanredheadcharacter{trigger}, {subject type}, {clothing}, {pose}, {setting}, {lighting}, {style}dataset/{character_name}/{repeats}_{trigger_word}/
001.png + 001.txt
002.png + 002.txt
...10_sage_characternetwork:
type: lora
linear: 16 # Rank (16-32 for characters)
linear_alpha: 16 # Alpha = rank for FLUX
train:
batch_size: 1
gradient_accumulation_steps: 4
steps: 1500 # FLUX converges faster
lr: 4e-4 # Higher than SDXL
optimizer: adamw8bit
dtype: bf16
datasets:
- resolution: [1024]
caption_ext: "txt"
sample:
sample_every: 250
prompts:
- "{trigger}, photorealistic portrait"pretrained_model: "RealVisXL_V5.0.safetensors"
network_dim: 32 # Rank (16-64)
network_alpha: 16 # Usually dim/2
resolution: "1024,1024"
train_batch_size: 1
gradient_accumulation_steps: 4
learning_rate: 0.0001 # 1e-4
lr_scheduler: "cosine_with_restarts"
lr_scheduler_num_cycles: 3
max_train_epochs: 10
optimizer_type: "AdamW8bit"
mixed_precision: "bf16"
enable_bucket: true
min_snr_gamma: 5total_steps = (images x repeats x epochs) / batch_size
Target: 1500-3000 steps for SDXL
Example: 20 images x 10 repeats x 5 epochs / 1 = 1000 stepsuse_8bit_adam: true
gradient_checkpointing: true
cache_latents_to_disk: true
max_data_loader_n_workers: 0
train_batch_size: 1
gradient_accumulation_steps: 8
quantize_base_model: nf4 # SimpleTuner onlyPrompt 1: "{trigger}, photorealistic portrait, neutral expression"
Prompt 2: "{trigger}, photorealistic portrait, smiling, outdoor"
Prompt 3: "{trigger}, wearing formal suit, standing, office"
Prompt 4: "a person standing in a park" (WITHOUT trigger - should NOT produce character){ComfyUI}/models/loras/lora:
trained: true
model_file: "sage_character_flux.safetensors"
trigger_word: "sage_character"
best_strength: 0.8generation_history[Load Checkpoint] → [Load LoRA (0.7-0.9)] → [Apply PuLID/IP-Adapter (0.5-0.7)] → [Generate]| Issue | Solution |
|---|---|
| LoRA not activating | Check trigger word spelling, ensure loaded before KSampler |
| Identity drift at angles | Add more angle variety to dataset, reduce network_dim |
| Overfitting | Reduce epochs, increase dataset, lower network_dim |
| Style contamination | Better caption diversity, don't describe style in captions |
| Poor quality/artifacts | Check training images for compression, reduce LR |
references/lora-training.mdreferences/models.mdprojects/