You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds support for the Euler CFG++ and Euler Ancestral CFG++ samplers: CFG++.
The logic from the code has been adapted from their repository and checked against ComfyUI's implementation and I tried to keep the sampler style as close as possible to the existing ones.
Some changes were needed in src/stable-diffusion.cpp as this specific sampler requires the unconditioned output in order to work.
This currently doesn't work with Spectrum cache.
As any CFG++ sampler you must use very low CFG values (for SDXL often less than 2).
I'd be very grateful if anyone could review this, as it's the first sampler I implement that requires this kind of changes.
I still think it's a good addition to the samplers. I tend to see more coherent generations at relatively higher CFGs, however I may be biased, this requires more testing.
When I'll have some time I'll try to create a grid showing the differences in CFGs between the sampler variants to have a better idea whether this is worth adding as a sampler or not.
From some initial testing with a SDXL model (cyberrealisticXL_V90, positive prompt: "a cute cat, best quality,", negative prompt: "worst quality,", 20 steps, seed 42, discrete scheduler) the biggest image similarity between Euler and Euler CFG++ is at 4.5 and 1.1 CFG (91.62% SSIM 61.07 MSE).
There's also a high similarity between CFG 1.4 and 5.5 (90%).
Other than that, as the CFG++ paper specifies this method allows for a smoother trajectory of generation:
Positive prompt: "a cute cat, best quality, black background",
Negative prompt: "worst quality, photo,",
Seed: 42, Scheduler: discrete
I did some more testing, on a more complex generation there appears to be an increase in difference in the generated images.
On the same test model (cyberrealisticXL_V90), 20 steps with positive prompt: "dog jumping towards a door, outdoors, grass, house, best quality, photography" and negative prompt: "worst quality," here's what I get:
CFG
4.0
4.5
5.0
5.5
6.0
Euler
CFG
1.1
1.2
1.3
1.4
Euler CFG++
CFG
1.5
1.6
1.7
1.8
Euler CFG++
The highest similarity in this case comes from 5.5 and 1.3 and it's still just 78%:
I can't really say if it's better or not, however given the smooth generation trajectory I think that this method may introduce less artifacts in certain kind of images (I just managed to get it to happen on very few samples, but I'm not that good at writing prompts so I can't really test that aspect so well).
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
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.
This PR adds support for the Euler CFG++ and Euler Ancestral CFG++ samplers: CFG++.
The logic from the code has been adapted from their repository and checked against ComfyUI's implementation and I tried to keep the sampler style as close as possible to the existing ones.
Some changes were needed in
src/stable-diffusion.cppas this specific sampler requires the unconditioned output in order to work.This currently doesn't work with Spectrum cache.
As any CFG++ sampler you must use very low CFG values (for SDXL often less than 2).
I'd be very grateful if anyone could review this, as it's the first sampler I implement that requires this kind of changes.