Skip to content

Commit 96bb2ff

Browse files
committed
alpha cosine noise schedule is now working for continuous time gaussian diffusion
1 parent 582bfe2 commit 96bb2ff

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

denoising_diffusion_pytorch/continuous_time_gaussian_diffusion.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ def forward(self, x):
5959

6060
# log(snr) that approximates the original linear schedule
6161

62+
def log(t, eps = 1e-20):
63+
return torch.log(t.clamp(min = eps))
64+
6265
def beta_linear_log_snr(t):
63-
return -torch.log(expm1(1e-4 + 10 * (t ** 2)))
66+
return -log(expm1(1e-4 + 10 * (t ** 2)))
6467

65-
def alpha_cosine_log_snr(t):
66-
raise NotImplementedError
68+
def alpha_cosine_log_snr(t, s = 0.008):
69+
return -log((torch.cos((t + s) / (1 + s) * torch.pi * 0.5) ** -2) - 1)
6770

6871
class learned_noise_schedule(nn.Module):
6972
""" described in section H and then I.2 of the supplementary material for variational ddpm paper """
@@ -135,6 +138,8 @@ def __init__(
135138

136139
if noise_schedule == 'linear':
137140
self.log_snr = beta_linear_log_snr
141+
elif noise_schedule == 'cosine':
142+
self.log_snr = alpha_cosine_log_snr
138143
elif noise_schedule == 'learned':
139144
log_snr_max, log_snr_min = [beta_linear_log_snr(torch.tensor([time])).item() for time in (0., 1.)]
140145

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name = 'denoising-diffusion-pytorch',
55
packages = find_packages(),
6-
version = '0.17.6',
6+
version = '0.17.7',
77
license='MIT',
88
description = 'Denoising Diffusion Probabilistic Models - Pytorch',
99
author = 'Phil Wang',

0 commit comments

Comments
 (0)