scraed / CharacteristicGuidanceWebUI

Provide large guidance scale correction for Stable Diffusion web UI (AUTOMATIC1111), implementing the paper "Characteristic Guidance: Non-linear Correction for Diffusion Model at Large Guidance Scale"
https://scraed.github.io/CharacteristicGuidance/
Apache License 2.0
67 stars 6 forks source link

Characteristic Guidance Web UI (enhanced sampling for high CFG scale)

About

Characteristic Guidance Web UI is an extension of for the Stable Diffusion web UI (AUTOMATIC1111). It offers a theory-backed guidance sampling method with improved sample and control quality at high CFG scale (10-30).

This is the official implementation of Characteristic Guidance: Non-linear Correction for Diffusion Model at Large Guidance Scale. We are happy to announce that this work has been accepted by ICML 2024.

Features

Characteristic guidance offers improved sample generation and control at high CFG scale. Try characteristic guidance for

Characteristic guidance is compatible with every existing sampling methods in Stable Diffusion WebUI. It now have preliminary support for Forge UI and ControlNet. 1girl running mountain grass newspaper news english 1girl, handstand, sports, close_up StrawberryPancake 1girl, kimono

For more information and previews, please visit our project website: Characteristic Guidance Project Website.

Q&A: What's the difference with Dynamical Thresholding?

They are distinct and independent methods, can be used either independently or in conjunction.

Using Characteristic Guidance and Dynamical Thresholding simutaneously may further reduce saturation.

1girl_handstand_sportswear_gym

Prerequisites

Before installing and using the Characteristic Guidance Web UI, ensure that you have the following prerequisites met:

Installation

Follow these steps to install the Characteristic Guidance Web UI extension:

  1. Navigate to the "Extensions" tab in the Stable Diffusion web UI.
  2. In the "Extensions" tab, select the "Install from URL" option.
  3. Enter the URL https://github.com/scraed/CharacteristicGuidanceWebUI.git into the "URL for extension's git repository" field.
  4. Click on the "Install" button.
  5. After waiting for several seconds, a confirmation message should appear indicating successful installation: "Installed into stable-diffusion-webui\extensions\CharacteristicGuidanceWebUI. Use the Installed tab to restart".
  6. Proceed to the "Installed" tab. Here, click "Check for updates", followed by "Apply and restart UI" for the changes to take effect. Note: Use these buttons for future updates to the CharacteristicGuidanceWebUI as well.

Usage

The Characteristic Guidance Web UI features an interactive interface for both txt2img and img2img mode. Gradio UI for CharacteristicGuidanceWebUI

The characteristic guidance is slow compared to classifier-free guidance. We recommend the user to generate image with classifier-free guidance at first, then try characteristic guidance with the same prompt and seed to enhance the image.

Activation

Visualization and Testing

In practice, convergence is not always guaranteed. If characteristic guidance fails to converge at a certain time step, classifier-free guidance will be adopted at that time step.

Below are the parameters you can adjust to customize the behavior of the guidance correction:

Basic Parameters

Advanced Parameters

Please experiment with different settings, especially regularization strength and time range, to achieve better convergence for your specific use case. (According to my experience, high CFG scale need relatively large regularization strength and time range for convergence, while low CFG scale prefers lower regularization strength and time range for more guidance correction.)

How to Set Parameters (Preliminary Guide)

Here is my recommended approach for parameter setting:

  1. Start by running characteristic guidance with the default parameters (Use Regularization Strength=5 for Stable Diffusion XL).
  2. Verify convergence by clicking the Check Convergence button.
  3. If convergence is achieved easily:
    • Decrease the Regularization Strength and Regularization Range Over Time to enhance correction.
    • If the Regularization Strength is already minimal, consider increasing the Num. Basis for Correction for improved performance.
  4. If convergence is not reached:
    • Increment the Max Num. Characteristic Iteration to allow for additional iterations.
    • Should convergence still not occur, raise the Regularization Strength and Regularization Range Over Time for increased regularization.

Updates

June 24, 2024: Preliminary Support for Forge.

February 3, 2024: New parameters accelerating the generation.

January 28, 2024: Modify how parameter Reuse Correction of Previous Iteration works

January 28, 2024: Allow Num. Basis for Correction = 0

January 14, 2024: Bug fix: allow prompts with more than 75 tokens

January 13, 2024: Add support for V-Prediction model

January 12, 2024: Add support for 'AND' prompt combination

January 8, 2024: Improved Guidance Settings

January 6, 2024: Integration of ControlNet

January 3, 2024: UI Enhancement for Infotext

Compatibility and Issues

June 24, 2024: Inconsistent Forge Implementation.

Citation

If you utilize characteristic guidance in your research or projects, please consider citing our paper:


@misc{zheng2023characteristic,
      title={Characteristic Guidance: Non-linear Correction for DDPM at Large Guidance Scale},
      author={Candi Zheng and Yuan Lan},
      year={2023},
      eprint={2312.07586},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}