Simple ComfyUI nodes to set the actual amount of noise in img2img, ensuring consistent behavior when changing schedulers.
- Use
Custom Nodes Manager > Install via Git URLin ComfyUI-Manager - Or clone the repository into
custom_nodes/manually (there are no external dependencies, so that's all)
There are several ways to use these nodes:
-
simply connect
Actual Denoisenode to your KSampler, choose scheduler and choose actual_denoise.Be aware that actual_denoise and denoise are different values, so you need to use different values for it (see the next example)
-
chain "Actual Denoise Inverse" and "Actual Denoise" to use usual denoise instead of actual_denoise.
You can use any scheduler you're used to in the first Inverse node (that one will be used to map denoise into actual_denoise), and set scheduler you want to use right now in the second node
- use
(Step)versions of the same nodes if you're usingKSampler (Advanced)(start_at_step,end_at_stepinstead ofdenoise)
That way, when you change the scheduler but keep the actual_denoise value the same, the image will get the exact same amount of noise (unlike when you fix denoise directly).
Since different schedulers use different amount of noise on a certain step, different denoise values behave differently with different schedulers.
So in order to simplify the img2img workflow and avoid manual denoise adjustments whenever you change schedulers,
you can set actual_denoise (actual amount of noise) and then calculate denoise based on the scheduler you're using.
Suppose I generated an image with this basic txt2img workflow:
Then I want to do img2img to add some effects and fix some details. Here's the basic img2img workflow:
So my original txt2img prompt was:
1girl,
amami haruka, idolmaster,
standing, singing, idol, looking at viewer, dynamic pose, outstretched arm,
foreshortening, depth of field, blurry background, spotlight,
official style,
absurdres, masterpiece, very aesthetic, best quality, very awa, very aesthetic,
I'm adding these tags in order to add some effects and make lighting better:
vivid colors, saturated, glowstick, (sparkle:1.1), bokeh, light particles, light rays, (glowing eyes:0.95), (aura, green aura:1.2),
And also I add dark into negative prompt, because I noticed that it heavily impacts the model and the image tends to become much lighter.
After I've decided on prompts, I need to choose denoise value. I'll use the same sampler and scheduler for now. Here is what I get with different denoise values with euler beta:
Note how many green aura the model adds depending on the denoise, and how much it changes her hands. If my goal is to add some effects without changing the image too much (because I like how her hands look on the original image), the sweet spot would probably be around 0.55. Values >=0.65 change her left hand, while values <=0.45 don't add enough effects (0.6 makes the hand look malformed, so I choose 0.55 or 0.5).
Now suppose I want to change the scheduler (and optionally sampler). Let's use uni_pc kl_optimal:
As you can see, now the same sweet spot would be around 0.6. Why is that?
That happened because of how KSampler uses denoise value: it simply multiplies your number of steps by 1 / denoise to get the total number of steps,
and then starts the denoising process from total_steps - steps step.
That's a common misconception that denoise=0.5 means that it adds 50% to the image and starts the denoising process from that.
The actual amount of added noise depends on the scheduler that is being used.
The scheduler defines the relationship between step / total_steps (percentage of steps) and the amount of noise on that step.
Here's how you can see the actual plot (thanks to KJNodes):
Here are plots for some schedulers (it might be difficult to see the difference just by looking at the graph):
The effect might not seem relevant to you (0.5 vs 0.6), but in different img2img scenarios that would have a different effect. Personally, I always kept in mind something like "if I switch from simple to kl_optimal I need to also raise the denoise a bit".
So what's the solution? Of course you can manually adjust denoise whenever you vary the scheduler,
but another solution is to choose not the steps / total_steps, but the actual amount of noise.
Instead of setting denoise you can set actual_denoise (actual amount of noise) and then calculate denoise based on the scheduler you're using.