comfyanonymous / ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface.
https://www.comfy.org/
GNU General Public License v3.0
54.05k stars 5.73k forks source link

[ feature ] add more options to Flux ( from changes during development ) #4666

Open JorgeR81 opened 1 month ago

JorgeR81 commented 1 month ago

Feature Idea

Some of my images, from 2 or 3 weeks ago, now look a bit different.

I like both versions, but I'd like to make changes directly on the old ones.

Do you remember any changes that could be worth bring back as an option / node ?

Maybe some changes on model sampling or scheduling ?

Existing Solutions

If I play around with some values, I can get a similar look, but I can't just get it right.

Other

No response

Meizr commented 1 month ago

I'm inclined to think the old code was wrong, so I think the previous behaviour won't be back.

By now, assuming you're on commit 483004dd1d379837a06e1244e8e833ab1369dd50, if you desperatedly need to reproduce old images, you can revert to old behaviour by:

1 - adding this new function at the very end of file ComfyUI\comfy\ldm\common_dit.py

def rms_norm_FP32(x, weight, eps=1e-6):
    d_type = x.dtype
    x = x.float()
    if rms_norm_torch is not None:
        return rms_norm_torch(x, weight.shape, weight=comfy.ops.cast_to(weight, dtype=d_type, device=x.device), eps=eps)
    else:
        rrms = torch.rsqrt(torch.mean(x**2, dim=-1, keepdim=True) + eps)
        return (x * rrms).to(dtype=d_type) * comfy.ops.cast_to(weight, dtype=d_type, device=x.device)

2 - changing the return of "forward" function of class "RMSNorm" to call your new function in file ComfyUI\comfy\ldm\flux\layers.py like this:

return comfy.ldm.common_dit.rms_norm_FP32(x, self.scale, 1e-6)

After that, start comfyui, and the old behaviour will be back.

The two files must be like this:

ComfyUI\comfy\ldm\common_dit.py image

ComfyUI\comfy\ldm\flux\layers.py image

Keep in mind old code is probably wrong, so the images you were getting before could be a result of code inaccuracy (even if they are aestheticly better)