Nodes/ComfyUI Flux Trainer/Init SDXL LoRA Training
ComfyUI Node

Init SDXL LoRA Training

Train an SDXL or Illustrious LoRA without leaving ComfyUI

By kijai·Created 2 years ago·Updated about a year ago· 1,156
Init SDXL LoRA Training
  • SDXL_models
  • dataset
  • optimizer_settings
  • resume_args
  • block_args
  • loss_args
  • network_config
  • network_trainer
  • epochs_count
  • args
output_nameSDXL_lora
output_dirSDXL_trainer_output
network_dim16
network_alpha16.00
learning_rate0
max_train_steps1500
cache_latents
cache_text_encoder_outputs
highvramfalse
blocks_to_swap0
fp8_basefalse
gradient_dtypefp32
save_dtypefp16
attention_modesdpa
train_text_encoderdisabled
clip_l_lr0.0000
clip_g_lr0.0000
sample_prompts_posillustration of a kitten | photograph of a turtle
sample_prompts_neg
gradient_checkpointingenabled
additional_args

Despite living in a pack called Flux Trainer, this node trains SDXL LoRAs - and by extension anything on the SDXL lineage, including Illustrious and Pony checkpoints. If you already inference SDXL in ComfyUI and want to train a character or style LoRA on the same machine, in the same environment, without setting up Kohya's GUI, this is the node that runs the show.

It's a wrapper around kohya-ss/sd-scripts, so the settings are the settled, decade-of-guides SDXL vocabulary. That's actually the strong case for training SDXL here: SDXL recipes are done. The rank/alpha tables and learning rates stopped moving years ago, and this node's defaults reflect them, unlike the more experimental Flux side of the pack.

How it works

InitSDXLLoRATraining takes your models, your dataset, and an optimizer config, and builds a trainer object you then step through with a FluxTrainLoop node (yes, the loop node is shared across model types). The three inputs it can't run without: SDXL_models (from an SDXLModelSelect node), dataset (a JSON describing your image folder and captions), and optimizer_settings (from an OptimizerConfig node). Out comes network_trainer (NETWORKTRAINER) that drives the loop, plus epochs_count and the raw args.

The inputs that matter

The good news is the defaults here are genuinely usable for SDXL:

  • network_dim (default 16) and network_alpha (default 16) - 16/16 is a solid, community-backed starting point for an SDXL person LoRA. If you want the classic alpha-at-half-rank behavior, drop alpha to 8. For styles, people often go lower on dim.
  • learning_rate (default 1e-6) - note this is deliberately conservative. SDXL commonly trains anywhere from 1e-5 to 1e-4; you'll likely want to raise this, especially with a plain constant scheduler.
  • max_train_steps (default 1500) - the old SDXL rule of thumb is 100-200 steps per image, so scale this to your dataset size.
  • train_text_encoder (disabled or clip_l) - SDXL is one of the last architectures where training the text encoder still helps. Flip it to clip_l and set clip_l_lr/clip_g_lr if you want it; leave it off for a faster, safer run.
  • blocks_to_swap and fp8_base - the VRAM levers. SDXL LoRA fits comfortably in 12GB at rank 32, so you often won't need either, but they're there for tight cards.

Installing the pack

Through ComfyUI Manager, search ComfyUI Flux Trainer, install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/kijai/ComfyUI-FluxTrainer
pip install -r ComfyUI-FluxTrainer/requirements.txt

Torch 2.4.0+ recommended, and the example workflows lean on kijai's ComfyUI-KJNodes, so install that too. For SDXL you just point SDXLModelSelect at a normal SDXL checkpoint - no separate VAE juggling like the Flux side needs.

Common issues

Your dataset isn't set up right. This is the most common wall people hit with the whole pack. Captions live in .txt files next to your images, the folder path has to resolve (Windows portable users sometimes have to keep the dataset folder inside the ComfyUI directory), and a bad or empty dataset JSON throws a cryptic parse error rather than a friendly message. Sort the dataset before touching training knobs.

Anime bases want tag captions, not sentences. If you're training on Illustrious, Pony, or NoobAI, caption with WD14-style Danbooru tags - comma-separated tags matching how those models were trained - not natural-language descriptions. Natural language is for Flux-class models.

The default learning rate looks tiny. It is. Don't assume the shipped 1e-6 is optimal; kijai's own README warns the defaults "aren't necessarily any good." Start from a known SDXL recipe and use the pack's validation nodes to sanity-check before committing to a long run.

CategoryFluxTrainer/SDXL

Inputs (28)

NameTypeDefaultDescription
SDXL_modelsTRAIN_SDXL_MODELS
datasetJSON
optimizer_settingsARGS
output_nameSTRINGSDXL_lora
output_dirSTRINGSDXL_trainer_outputpath to dataset, root is the 'ComfyUI' folder, with windows portable 'ComfyUI_windows_portable'
network_dimINT161–100000network dim
network_alphaFLOAT16.000–2048network alpha
learning_rateFLOAT00–10learning rate
max_train_stepsINT15001–100000max number of training steps
cache_latentsCOMBOcaches text encoder outputs
cache_text_encoder_outputsCOMBOcaches text encoder outputs
highvramBOOLEANfalsememory mode
blocks_to_swapINT00–100option for memory use reduction. The maximum number of blocks that can be swapped is 36 for SDXL.5L and 22 for SDXL.5M
fp8_baseBOOLEANfalseuse fp8 for base model
gradient_dtypeCOMBOfp32the actual dtype training uses
save_dtypeCOMBOfp16the dtype to save checkpoints as
attention_modeCOMBOsdpamemory efficient attention mode
train_text_encoderCOMBOdisabledalso train the selected text encoders using specified dtype, T5 can not be trained without clip_l
clip_l_lrFLOAT0.00000–10text encoder learning rate
clip_g_lrFLOAT0.00000–10text encoder learning rate
sample_prompts_posSTRINGillustration of a kitten | photograph of a turtlevalidation sample prompts, for multiple prompts, separate by `|`
sample_prompts_negSTRINGvalidation sample prompts, for multiple prompts, separate by `|`
gradient_checkpointingCOMBOenableduse gradient checkpointing
additional_argsoptSTRINGadditional args to pass to the training command
resume_argsoptARGSresume args to pass to the training command
block_argsoptARGSlimit the blocks used in the LoRA
loss_argsoptARGSloss args
network_configoptNETWORK_CONFIGadditional network config

Outputs (3)

NameTypeDescription
network_trainerNETWORKTRAINER
epochs_countINT
argsKOHYA_ARGS