MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / step

Method step

diffusers/examples/community/scheduling_ufogen.py:376–459  ·  view source on GitHub ↗

Predict the sample from the previous timestep by reversing the SDE. This function propagates the diffusion process from the learned model outputs (most often the predicted noise). Args: model_output (`torch.Tensor`): The direct output from learne

(
        self,
        model_output: torch.Tensor,
        timestep: int,
        sample: torch.Tensor,
        generator: Optional[torch.Generator] = None,
        return_dict: bool = True,
    )

Source from the content-addressed store, hash-verified

374 return sample
375
376 def step(
377 self,
378 model_output: torch.Tensor,
379 timestep: int,
380 sample: torch.Tensor,
381 generator: Optional[torch.Generator] = None,
382 return_dict: bool = True,
383 ) -> Union[UFOGenSchedulerOutput, Tuple]:
384 """
385 Predict the sample from the previous timestep by reversing the SDE. This function propagates the diffusion
386 process from the learned model outputs (most often the predicted noise).
387
388 Args:
389 model_output (`torch.Tensor`):
390 The direct output from learned diffusion model.
391 timestep (`float`):
392 The current discrete timestep in the diffusion chain.
393 sample (`torch.Tensor`):
394 A current instance of a sample created by the diffusion process.
395 generator (`torch.Generator`, *optional*):
396 A random number generator.
397 return_dict (`bool`, *optional*, defaults to `True`):
398 Whether or not to return a [`~schedulers.scheduling_ufogen.UFOGenSchedulerOutput`] or `tuple`.
399
400 Returns:
401 [`~schedulers.scheduling_ddpm.UFOGenSchedulerOutput`] or `tuple`:
402 If return_dict is `True`, [`~schedulers.scheduling_ufogen.UFOGenSchedulerOutput`] is returned, otherwise a
403 tuple is returned where the first element is the sample tensor.
404
405 """
406 # 0. Resolve timesteps
407 t = timestep
408 prev_t = self.previous_timestep(t)
409
410 # 1. compute alphas, betas
411 alpha_prod_t = self.alphas_cumprod[t]
412 alpha_prod_t_prev = self.alphas_cumprod[prev_t] if prev_t >= 0 else self.final_alpha_cumprod
413 beta_prod_t = 1 - alpha_prod_t
414 # beta_prod_t_prev = 1 - alpha_prod_t_prev
415 # current_alpha_t = alpha_prod_t / alpha_prod_t_prev
416 # current_beta_t = 1 - current_alpha_t
417
418 # 2. compute predicted original sample from predicted noise also called
419 # "predicted x_0" of formula (15) from https://arxiv.org/pdf/2006.11239.pdf
420 if self.config.prediction_type == "epsilon":
421 pred_original_sample = (sample - beta_prod_t ** (0.5) * model_output) / alpha_prod_t ** (0.5)
422 elif self.config.prediction_type == "sample":
423 pred_original_sample = model_output
424 elif self.config.prediction_type == "v_prediction":
425 pred_original_sample = (alpha_prod_t**0.5) * sample - (beta_prod_t**0.5) * model_output
426 else:
427 raise ValueError(
428 f"prediction_type given as {self.config.prediction_type} must be one of `epsilon`, `sample` or"
429 " `v_prediction` for UFOGenScheduler."
430 )
431
432 # 3. Clip or threshold "predicted x_0"
433 if self.config.thresholding:

Callers

nothing calls this directly

Calls 4

previous_timestepMethod · 0.95
_threshold_sampleMethod · 0.95
randn_tensorFunction · 0.90

Tested by

no test coverage detected