Skip to content

Laplace Scheduler for DDPM #11320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_consistency_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_ddim.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_ddim_cogvideox.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_ddim_inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_ddim_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
9 changes: 9 additions & 0 deletions src/diffusers/schedulers/scheduling_ddpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down Expand Up @@ -206,6 +213,8 @@ def __init__(
elif beta_schedule == "squaredcos_cap_v2":
# Glide cosine schedule
self.betas = betas_for_alpha_bar(num_train_timesteps)
elif beta_schedule == "laplace":
self.betas = betas_for_alpha_bar(num_train_timesteps, alpha_transform_type="laplace")
elif beta_schedule == "sigmoid":
# GeoDiff sigmoid schedule
betas = torch.linspace(-6, 6, num_train_timesteps)
Expand Down
9 changes: 9 additions & 0 deletions src/diffusers/schedulers/scheduling_ddpm_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down Expand Up @@ -214,6 +221,8 @@ def __init__(
elif beta_schedule == "squaredcos_cap_v2":
# Glide cosine schedule
self.betas = betas_for_alpha_bar(num_train_timesteps)
elif beta_schedule == "laplace":
self.betas = betas_for_alpha_bar(num_train_timesteps, alpha_transform_type="laplace")
elif beta_schedule == "sigmoid":
# GeoDiff sigmoid schedule
betas = torch.linspace(-6, 6, num_train_timesteps)
Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_deis_multistep.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_dpm_cogvideox.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_dpmsolver_sde.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_euler_discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_heun_discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_k_dpm_2_discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_lcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_lms_discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_pndm.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_repaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_sasolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_tcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_unclip.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down
7 changes: 7 additions & 0 deletions src/diffusers/schedulers/scheduling_unipc_multistep.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def betas_for_alpha_bar(

def alpha_bar_fn(t):
return math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2

elif alpha_transform_type == "laplace":

def alpha_bar_fn(t):
lmb = - 0.5 * math.copysign(1, 0.5 - t) * math.log(1 - 2 * math.fabs(0.5 - t) + 1e-6)
snr = math.exp(lmb)
return math.sqrt(snr / (1 + snr))

elif alpha_transform_type == "exp":

Expand Down