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

Method p_sample

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

Source from the content-addressed store, hash-verified

259
260 @torch.no_grad()
261 def p_sample(self, x, t, cond, clip_denoised=True, repeat_noise=False):
262 b, *_, device = *x.shape, x.device
263 model_mean, _, model_log_variance = self.p_mean_variance(x=x, t=t, cond=cond, clip_denoised=clip_denoised)
264 noise = noise_like(x.shape, device, repeat_noise)
265 # no noise when t == 0
266 nonzero_mask = (1 - (t == 0).float()).reshape(b, *((1,) * (len(x.shape) - 1)))
267 return model_mean + nonzero_mask * (0.5 * model_log_variance).exp() * noise
268
269 def q_sample(self, x_start, t, noise=None):
270 noise = default(noise, lambda: torch.randn_like(x_start))

Callers 1

forwardMethod · 0.95

Calls 2

p_mean_varianceMethod · 0.95
noise_likeFunction · 0.70

Tested by

no test coverage detected