MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / cosine_beta_schedule

Function cosine_beta_schedule

usr/diff/diffusion.py:167–177  ·  view source on GitHub ↗

cosine schedule as proposed in https://openreview.net/forum?id=-NEXDKk8gZ

(timesteps, s=0.008)

Source from the content-addressed store, hash-verified

165
166
167def cosine_beta_schedule(timesteps, s=0.008):
168 """
169 cosine schedule
170 as proposed in https://openreview.net/forum?id=-NEXDKk8gZ
171 """
172 steps = timesteps + 1
173 x = np.linspace(0, steps, steps)
174 alphas_cumprod = np.cos(((x / steps) + s) / (1 + s) * np.pi * 0.5) ** 2
175 alphas_cumprod = alphas_cumprod / alphas_cumprod[0]
176 betas = 1 - (alphas_cumprod[1:] / alphas_cumprod[:-1])
177 return np.clip(betas, a_min=0, a_max=0.999)
178
179
180class GaussianDiffusion(nn.Module):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected