tatakai1 / classifier_free_ddim

A simple implementation of classifier-free guidance DDIM on MNIST
MIT License
15 stars 1 forks source link

question about guidance for classifier free ddim #1

Open qhanson opened 3 months ago

qhanson commented 3 months ago

I observe the guidance in the code:

# predict noise using model
pred_noise_c = model(x_t, t, c, torch.ones(batch_size).int().to(device))
pred_noise_none = model(x_t, t, c, torch.zeros(batch_size).int().to(device))
pred_noise = (1+w)*pred_noise_c - w*pred_noise_none
## the last line equals
## pred_noise = pred_noise_c + w*(pred_noise_c - pred_noise_none)

This is a little different from what hugging face tutorial. Can we use the following classifier-free guidance?

pred_noise_c = model(x_t, t, c, torch.ones(batch_size).int().to(device))
pred_noise_none = model(x_t, t, c, torch.zeros(batch_size).int().to(device))
pred_noise = pred_noise_none + w*(pred_noise_c - pred_noise_none)
tatakai1 commented 3 months ago

The code here implements E.g. (6) from the paper "CLASSIFIER-FREE DIFFUSION GUIDANCE". The following classifier-free guidance may achieve similar results, although I have not verified this experimentally.