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
51.72k stars 5.43k forks source link

mixed up beta schedules - linear and sqrt_linear #1998

Open eps696 opened 10 months ago

eps696 commented 10 months ago

it seems beta schedules in comfyui are inconsistent with those from diffusers library.

in diffusers, e.g. euler (it's the same elsewhere):

        elif beta_schedule == "linear":
            self.betas = torch.linspace(beta_start, beta_end, num_train_timesteps, dtype=torch.float32)
        elif beta_schedule == "scaled_linear":
            # this schedule is very specific to the latent diffusion model.
            self.betas = torch.linspace(beta_start**0.5, beta_end**0.5, num_train_timesteps, dtype=torch.float32) ** 2

in comfyui:

    if schedule == "linear":
        betas = torch.linspace(linear_start ** 0.5, linear_end ** 0.5, n_timestep, dtype=torch.float64) ** 2
. . .
    elif schedule == "sqrt_linear":
        betas = torch.linspace(linear_start, linear_end, n_timestep, dtype=torch.float64)

are the names simply mistaken or there is a logics behind such swap?

comfyanonymous commented 10 months ago

That ComfyUI code is from the original stable diffusion repo.

eps696 commented 10 months ago

how does it change the fact that your beta schedulers are incorrect? [maybe it was originally a diffusers' mistake, but they seemeed to correct it now]

comfyanonymous commented 10 months ago

My beta schedulers are correct. That's what they call it in the original stable diffusion code where I copied it from.

eps696 commented 10 months ago

glad to hear you're so confident about that. hope this issue will allow others to understand better how torch.linspace(linear_start ** 0.5, linear_end ** 0.5, n_timestep, dtype=torch.float64) ** 2 can be called linear, while betas = torch.linspace(linear_start, linear_end, n_timestep, dtype=torch.float64) pretends to be sqrt_linear. you may close this issue if you want to.

that said, thanks a ton and a great respect for the coolest product in the area, it's really a fresh air amongst anything else.