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

Method p_sample

usr/diff/shallow_diffusion_tts.py:278–284  ·  view source on GitHub ↗
(self, x, t, cond, clip_denoised=True, repeat_noise=False)

Source from the content-addressed store, hash-verified

276
277 @torch.no_grad()
278 def p_sample(self, x, t, cond, clip_denoised=True, repeat_noise=False):
279 b, *_, device = *x.shape, x.device
280 model_mean, _, model_log_variance = self.p_mean_variance(x=x, t=t, cond=cond, clip_denoised=clip_denoised)
281 noise = noise_like(x.shape, device, repeat_noise)
282 # no noise when t == 0
283 nonzero_mask = (1 - (t == 0).float()).reshape(b, *((1,) * (len(x.shape) - 1)))
284 return model_mean + nonzero_mask * (0.5 * model_log_variance).exp() * noise
285
286 def q_sample(self, x_start, t, noise=None):
287 noise = default(noise, lambda: torch.randn_like(x_start))

Callers 2

forwardMethod · 0.95
forwardMethod · 0.45

Calls 2

p_mean_varianceMethod · 0.95
noise_likeFunction · 0.70

Tested by

no test coverage detected