CompVis / stable-diffusion

A latent text-to-image diffusion model
https://ommer-lab.com/research/latent-diffusion-models/
Other
67.41k stars 10.08k forks source link

Why `make_beta_schedule` does not return linear schedule? #314

Open yutoe05 opened 1 year ago

yutoe05 commented 1 year ago

It seems that the beta schedule returned by make_beta_schedule("linear",...) is not linear but quadratic. Instead, the returned beta is linear when schedule == "sqrt_linear". Why is it implemented in this way?

https://github.com/CompVis/stable-diffusion/blob/69ae4b35e0a0f6ee1af8bb9a5d0016ccb27e36dc/ldm/modules/diffusionmodules/util.py#L21-L43

wenhao728 commented 6 months ago

Hi @yutoe05 Have you come across any explanations regarding this matter? I revisited the LDM paper and searched, but unfortunately, I haven't found any clarifications on the topic.

yutoe05 commented 6 months ago

Hi wenhao728.

Unfortunately, I couldn't find any explanations. Anyway, it seems they use linspace()**2 as default.

newbie2niubility commented 6 months ago

Hi @yutoe05, For the fomula of generating x{t} from x{t-1}, the coefficient before noise is sqrt_beta_t. So I guess torch.linspace(linear_start ** 0.5, linear_end ** 0.5, n_timestep, dtype=torch.float64) ** 2 means add noise linearly.

yutoe05 commented 5 months ago

Hi @newbie2niubility, I see. As you said, while originally in DDPM, the "noise schedule" is used with respect to the variance, it might be used with respect to the standard deviation of noise in latent diffusion. Thank you.