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

Init Flux LoRA Training

The node that actually runs a Flux LoRA train inside ComfyUI

By kijai·Created 2 years ago·Updated about a year ago· 1,157
Init Flux LoRA Training
  • flux_models
  • dataset
  • optimizer_settings
  • resume_args
  • block_args
  • loss_args
  • network_config
  • network_trainer
  • epochs_count
  • args
output_nameflux_lora
output_dirflux_trainer_output
network_dim4
network_alpha1.00
learning_rate0.0004
max_train_steps1500
apply_t5_attn_masktrue
cache_latents
cache_text_encoder_outputs
blocks_to_swap0
weighting_scheme
logit_mean0.00
logit_std1.00
mode_scale1.29
timestep_sampling
sigmoid_scale1.0
model_prediction_type
guidance_scale1.00
discrete_flow_shift1.0000
highvramfalse
fp8_basetrue
gradient_dtypefp32
save_dtypebf16
attention_modesdpa
sample_promptsillustration of a kitten | photograph of a turtle
additional_args
train_text_encoderdisabled
clip_l_lr0.0000
T5_lr0.0000
gradient_checkpointingenabled

This is the heart of the whole pack. If you want to train a Flux LoRA without ever leaving ComfyUI - no Kohya GUI, no ai-toolkit config file, no second Python environment - InitFluxLoRATraining is the node that sets the run up. Everything else in ComfyUI-FluxTrainer feeds into it or runs after it.

Under the hood, kijai is wrapping a slightly modified version of kohya-ss/sd-scripts, the same training code that powers the Kohya GUI. So the parameter names here are Kohya's parameter names - network_dim, network_alpha, learning_rate - which means any Flux LoRA guide written for Kohya translates almost directly. The pitch for doing it in Comfy at all is honest and small: you reuse the exact models you already inference with, you stay in one Python env, and you can wire up graphs to A/B settings. That's it. It won't be faster than ai-toolkit, and kijai himself says in the README that he has "very little previous experience in training anything" and that the default settings "aren't necessarily any good." Treat this as a capable Kohya front-end, not a magic beginner button.

How it fits together

Init doesn't train on its own - it initializes. You hand it three things it can't run without: flux_models (from a FluxTrainModelSelect node), a dataset JSON that points at your images and captions, and optimizer_settings (from one of the OptimizerConfig nodes). It builds a live trainer object and spits out network_trainer (type NETWORKTRAINER), which you then pipe into a FluxTrainLoop node to actually grind steps. It also outputs epochs_count so you know how many epochs your step count works out to, and args (the raw Kohya arguments) for debugging.

The inputs that actually matter

Most of the two-dozen knobs here you can leave alone on a first run. The ones a beginner should set:

  • network_dim (default 4) and network_alpha (default 1) - rank and its scaling. Kijai's defaults are unusually low; for a Flux character LoRA most people run something closer to rank 16. Bigger dim = more capacity and a bigger file.
  • learning_rate (default 0.0004) - this default of 4e-4 is the well-worn Flux.1 starting point, so it's a sane place to begin.
  • max_train_steps (default 1500) - the Flux sweet spot for a 15-25 image dataset is roughly 1,500-3,000 steps. Save intermediate checkpoints, because the final step is often not the best one.
  • blocks_to_swap - the VRAM lever. This is Kohya's block-swapping trick: it offloads transformer blocks to system RAM so a Flux LoRA fits in 12-16GB. Raise it if you OOM, leave it at 0 if you've got the headroom.
  • fp8_base (default true) - keeps the base model in fp8 to save memory. Standard for consumer cards.

There's also an optional network_config input: plug a TrainNetworkConfig node in there to train a LyCORIS/LoKr instead of a plain LoRA, which is what most people now reach for on Flux-class models.

Installing the pack

ComfyUI Manager is easiest - search ComfyUI Flux Trainer, install, restart. By hand:

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

Torch 2.4.0 or newer is strongly recommended. The example workflows also use nodes from kijai's ComfyUI-KJNodes (and optional debug nodes from rgthree-comfy), so grab those too. For the models: use the normal fp8 or fp16 Flux files, and make sure your VAE is the non-diffusers ae.safetensors - the diffusers-format VAE will not work.

Common issues

Dataset errors on the first run. The number-one beginner trip is the dataset. If you get Expecting value: line 1 column 1 (char 0), your dataset JSON is malformed or empty - build it with the pack's dataset node rather than typing JSON by hand. On Windows portable installs people have also had to move their dataset folder inside the ComfyUI directory for the paths to resolve. Get 20 well-captioned images sitting in the right place before you touch any of the training knobs.

It's experimental, and it changes. Kijai's README says this outright: both his nodes and Kohya's underlying Flux code are work-in-progress. If a workflow breaks after an update, that's the deal you signed up for. Keep the pack current and expect the occasional churn.

CategoryFluxTrainer

Inputs (37)

NameTypeDefaultDescription
flux_modelsTRAIN_FLUX_MODELS
datasetJSON
optimizer_settingsARGS
output_nameSTRINGflux_lora
output_dirSTRINGflux_trainer_outputpath to dataset, root is the 'ComfyUI' folder, with windows portable 'ComfyUI_windows_portable'
network_dimINT41–100000network dim
network_alphaFLOAT1.000–2048network alpha
learning_rateFLOAT0.00040–10learning rate
max_train_stepsINT15001–100000max number of training steps
apply_t5_attn_maskBOOLEANtrueapply t5 attention mask
cache_latentsCOMBOcaches text encoder outputs
cache_text_encoder_outputsCOMBOcaches text encoder outputs
blocks_to_swapINT0Previously known as split_mode, number of blocks to swap to save memory, default to enable is 18
weighting_schemeCOMBO5 options: logit_normal, sigma_sqrt, mode, cosmap, none
logit_meanFLOAT0.000–1mean to use when using the logit_normal weighting scheme
logit_stdFLOAT1.000–1std to use when using the logit_normal weighting scheme
mode_scaleFLOAT1.290–10Scale of mode weighting scheme. Only effective when using the mode as the weighting_scheme
timestep_samplingCOMBOMethod to sample timesteps: sigma-based, uniform random, sigmoid of random normal and shift of sigmoid (recommend value of 3.1582 for discrete_flow_shift)
sigmoid_scaleFLOAT1.00–10Scale factor for sigmoid timestep sampling (only used when timestep-sampling is sigmoid
model_prediction_typeCOMBOHow to interpret and process the model prediction: raw (use as is), additive (add to noisy input), sigma_scaled (apply sigma scaling).
guidance_scaleFLOAT1.001–32guidance scale, for Flux training should be 1.0
discrete_flow_shiftFLOAT1.00000–10for the Euler Discrete Scheduler, default is 3.0
highvramBOOLEANfalsememory mode
fp8_baseBOOLEANtrueuse fp8 for base model
gradient_dtypeCOMBOfp32the actual dtype training uses
save_dtypeCOMBObf16the dtype to save checkpoints as
attention_modeCOMBOsdpamemory efficient attention mode
sample_promptsSTRINGillustration of a kitten | photograph of a turtlevalidation sample prompts, for multiple prompts, separate by `|`
additional_argsoptSTRINGadditional args to pass to the training command
resume_argsoptARGSresume args to pass to the training command
train_text_encoderoptCOMBOdisabledalso train the selected text encoders using specified dtype, T5 can not be trained without clip_l
clip_l_lroptFLOAT0.00000–10text encoder learning rate
T5_lroptFLOAT0.00000–10text encoder learning rate
block_argsoptARGSlimit the blocks used in the LoRA
gradient_checkpointingoptCOMBOenableduse gradient checkpointing
loss_argsoptARGSloss args
network_configoptNETWORK_CONFIGadditional network config

Outputs (3)

NameTypeDescription
network_trainerNETWORKTRAINER
epochs_countINT
argsKOHYA_ARGS