Skip to content

Classifier free guidance #8460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 27, 2025

Conversation

virginiafdez
Copy link
Contributor

Fixes #8448

Description

Classifier-free guidance scale can be used in the sampling methods of diffusion models to strengthen the conditioning. It's been used in one of the generative MONAI tutorials, but the actual Inferers (DiffusionInferer, and ControlNetDiffusionInferer) do not support this feature. This means that, whenever users want to use CFG, they have to either copy the Inferer object or write their own sampling method.
This PR incorporates classifier-free guidance into the inferer objects by modifying their sampling method and adding an argument cfg to the sampling method to control this.
This should not change the default behaviour (cfg=None), although some rewriting has been necessary.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes (to test_controlnet_inferers.py, test_diffusion_inferer.py and test_latent_diffusion_inferer.py).
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

Virginia Fernandez and others added 12 commits May 9, 2025 15:10
Signed-off-by: Virginia Fernandez <[email protected]>
Signed-off-by: Virginia Fernandez <[email protected]>
….ac.uk>\nI, Virginia Fernandez <[email protected]>, hereby add my Signed-off-by to this commit: 79f357a\nSigned-off-by: Virginia Fernandez <[email protected]>

Signed-off-by: Virginia Fernandez <[email protected]>
Signed-off-by: Virginia Fernandez <[email protected]>
….ac.uk>

I, Virginia Fernandez <[email protected]>, hereby add my Signed-off-by to this commit: 79f357a

Signed-off-by: Virginia Fernandez <[email protected]>
Signed-off-by: Virginia Fernandez <[email protected]>
@virginiafdez virginiafdez marked this pull request as ready for review May 27, 2025 13:46
@ericspod ericspod requested a review from KumoLiu May 27, 2025 13:52
Copy link
Member

@ericspod ericspod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@KumoLiu
Copy link
Contributor

KumoLiu commented May 27, 2025

/build

@ericspod ericspod enabled auto-merge (squash) May 27, 2025 15:32
@ericspod ericspod merged commit 2d41655 into Project-MONAI:dev May 27, 2025
25 checks passed
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.

Classifier-free guidance added to the Inferers
3 participants