stable-diffusion icon indicating copy to clipboard operation
stable-diffusion copied to clipboard

about the classifier-free guidance sampling code ?

Open JaosonMa opened this issue 1 year ago • 7 comments

in the paper , the latex is image image

so i think the code

def get_model_output(x, t):
            if unconditional_conditioning is None or unconditional_guidance_scale == 1.:
                e_t = self.model.apply_model(x, t, c)
            else:
                x_in = torch.cat([x] * 2)
                t_in = torch.cat([t] * 2)
                c_in = torch.cat([unconditional_conditioning, c])
                e_t_uncond, e_t = self.model.apply_model(x_in, t_in, c_in).chunk(2)
                e_t = e_t_uncond + unconditional_guidance_scale * (e_t - e_t_uncond)
            if score_corrector is not None:
                assert self.model.parameterization == "eps"
                e_t = score_corrector.modify_score(self.model, e_t, x, t, c, **corrector_kwargs)

            return e_t

from plms.py line 179 e_t = e_t_uncond + unconditional_guidance_scale * (e_t - e_t_uncond)

from my point , it should be e_t = e_t + unconditional_guidance_scale * (e_t - e_t_uncond)

can you tell me why? @apolinario @asanakoy @pesser @patrickvonplaten @rromb

JaosonMa avatar Sep 18 '23 01:09 JaosonMa

GLIDE has the same formulation as LDM. I wonder why

MoayedHajiAli avatar Sep 18 '23 05:09 MoayedHajiAli

If you figured out the reason, I would appreciate it if you can share it with me.

MoayedHajiAli avatar Sep 18 '23 05:09 MoayedHajiAli

I also hope I can find out why, and I will continue to search for answers, let's work together!

JaosonMa avatar Sep 18 '23 05:09 JaosonMa

@JaosonMa Any updates on this!? I still couldn't figure out the reason behind the modification.

MoayedHajiAli avatar Oct 09 '23 17:10 MoayedHajiAli

Have you found out the reason? I'm also wondering why

nshidqi avatar Dec 13 '23 07:12 nshidqi

sorry,i have not config this out

JaosonMa avatar Dec 13 '23 07:12 JaosonMa

You should see the DDPM paper e_t = e_t + unconditional_guidance_scale * (e_t - e_t_uncond) Makes the e_t one size bigger, which is not the case.

ChrisWang13 avatar May 11 '24 03:05 ChrisWang13