MCPcopy Index your code
hub / github.com/VisionXLab/OF-Diff / stochastic_encode

Method stochastic_encode

ldm/models/diffusion/ddim.py:301–314  ·  view source on GitHub ↗
(self, x0, t, use_original_steps=False, noise=None)

Source from the content-addressed store, hash-verified

299
300 @torch.no_grad()
301 def stochastic_encode(self, x0, t, use_original_steps=False, noise=None):
302 # fast, but does not allow for exact reconstruction
303 # t serves as an index to gather the correct alphas
304 if use_original_steps:
305 sqrt_alphas_cumprod = self.sqrt_alphas_cumprod
306 sqrt_one_minus_alphas_cumprod = self.sqrt_one_minus_alphas_cumprod
307 else:
308 sqrt_alphas_cumprod = torch.sqrt(self.ddim_alphas)
309 sqrt_one_minus_alphas_cumprod = self.ddim_sqrt_one_minus_alphas
310
311 if noise is None:
312 noise = torch.randn_like(x0)
313 return (extract_into_tensor(sqrt_alphas_cumprod, t, x0.shape) * x0 +
314 extract_into_tensor(sqrt_one_minus_alphas_cumprod, t, x0.shape) * noise)
315
316 @torch.no_grad()
317 def decode(self, x_latent, cond, t_start, unconditional_guidance_scale=1.0, unconditional_conditioning=None,

Callers

nothing calls this directly

Calls 1

extract_into_tensorFunction · 0.90

Tested by

no test coverage detected