Skip to content

feat: Add Condition Embedding Perturbation (CEP) noise support - #2371

Open
gesen2egee wants to merge 1 commit into
kohya-ss:mainfrom
gesen2egee:feat/cep-noise
Open

feat: Add Condition Embedding Perturbation (CEP) noise support#2371
gesen2egee wants to merge 1 commit into
kohya-ss:mainfrom
gesen2egee:feat/cep-noise

Conversation

@gesen2egee

Copy link
Copy Markdown
Contributor

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.)
  • Full fine-tuning scripts: flux_train.py, flux_train_control_net.py, sdxl_train.py, sdxl_train_control_net.py, sd3_train.py, lumina_train.py
  • DreamBooth (train_db.py)
  • Textual Inversion (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 ($\gamma$). Set to 0.0 to disable (default behavior). The paper recommends 1.0.
  • --cep_noise_type (str, default: "gaussian"): The type of perturbation noise. Choose between gaussian and uniform.

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).

  • Preventing Overfitting: Adding slight perturbations helps prevent the model from memorizing the limited prompts, enhancing the generative diversity of the character/style.
  • Tuning for Small Datasets: While the paper recommends $\gamma = 1.0$ for pre-training, a smaller value (e.g., 0.2 to 0.5) is recommended when starting on small datasets to avoid breaking the text-image alignment. If you notice overfitting, you can gradually increase --cep_noise up to 1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant