feat: Add Condition Embedding Perturbation (CEP) noise support - #2371
Open
gesen2egee wants to merge 1 commit into
Open
feat: Add Condition Embedding Perturbation (CEP) noise support#2371gesen2egee wants to merge 1 commit into
gesen2egee wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR implements Condition Embedding Perturbation (CEP) Noise, which is based on the paper:
"Slight Corruption in Pre-training Data Makes Better Diffusion Models" (arXiv:2405.20494).
Adding slight perturbation/noise to condition/text embeddings during training has been shown to improve generative quality, diversity, and prompt adherence.
This feature is integrated into all main training scripts, including:
train_network.py(LoRA/network trainers for SD 1.5, SDXL, SD3, Flux, Lumina, Anima, etc.)flux_train.py,flux_train_control_net.py,sdxl_train.py,sdxl_train_control_net.py,sd3_train.py,lumina_train.pytrain_db.py)train_textual_inversion.py,sdxl_train_textual_inversion.py)The implementation includes filtering logic to ensure that the perturbation noise is only applied to the actual floating-point text/conditioning embeddings, while keeping auxiliary variables like Attention Masks and Coordinate IDs intact.
New Arguments
--cep_noise(float, default:0.0): The perturbation noise strength (0.0to disable (default behavior). The paper recommends1.0.--cep_noise_type(str, default:"gaussian"): The type of perturbation noise. Choose betweengaussiananduniform.Application on Small Datasets / LoRA / DreamBooth
CEP Noise serves as an effective regularizer to prevent overfitting, which is a common issue when training on small datasets (e.g., character/style LoRA, DreamBooth).
0.2to0.5) is recommended when starting on small datasets to avoid breaking the text-image alignment. If you notice overfitting, you can gradually increase--cep_noiseup to1.0.