RFC: ComfyUI Training Modules #24
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
RFC: ComfyUI Training Modules
Summary
This RFC proposes the addition of training capabilities to ComfyUI, enabling users to create and fine-tune LoRA (Low-Rank Adaptation) models directly through the ComfyUI interface. The proposal includes a set of node implementations for loading image datasets, training LoRAs, visualizing training progress, and saving trained models.
Basic example
The basic workflow would allow users to:
Load an image dataset:

Train a LoRA on these images:

Save the resulting LoRA:

Visualize training loss:

Motivation
Currently, users who want to create custom LoRA models need to:
Adding training capabilities directly to ComfyUI would:
Detailed design
The implementation consists of four main components:
1. Image Dataset Loading
Two nodes are proposed for loading image datasets:
LoadImageSetNode: Loads individual images selected by the userLoadImageSetFromFolderNode: Loads all images from a specified folderThese nodes offer options for handling images of different sizes (stretch, crop, pad) and prepare the images for training.
2. LoRA Training Node
The
TrainLoraNodeis the core component that handles the training process:The training process:
3. Model Saving Node
The
SaveLoRAnode enables users to save their trained LoRA models:The node saves the LoRA weights in SafeTensors format, with a filename that includes the number of training steps and a timestamp.
4. Training Visualization Node
The
LossGraphNodevisualizes the training progress:This node generates a graph showing the training loss over time, providing visual feedback on the training process.
Supporting Components
The implementation also includes several support classes:
TrainSampler: A custom sampler that performs gradient updates during the sampling processLoraDiffandBiasDiff: Weight wrapper classes that apply LoRA adaptations to model weightsDrawbacks
Adoption strategy
EXPERIMENTAL = Trueflag to indicate the developing nature of the featureUnresolved questions
Implementation Plan
Phase 1: Basic LoRA Training
Initial implementation of the nodes described in this RFC.
Phase 2: Enhanced Features
Phase 3: Workflow Integration
Phase 4: Model Format
Links
Full Rendered Proposal
Discussion Thread
Important: Do NOT comment on this PR. Please use the discussion thread linked above to provide feedback, as it provides branched discussions that are easier to follow. This also makes the edit history of the PR clearer.