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,
eta: float = 0.3,
generator: Optional[torch.Generator] = None,
return_dict: bool = True,
)
| 523 | self._begin_index = None |
| 524 | |
| 525 | def step( |
| 526 | self, |
| 527 | model_output: torch.Tensor, |
| 528 | timestep: int, |
| 529 | sample: torch.Tensor, |
| 530 | eta: float = 0.3, |
| 531 | generator: Optional[torch.Generator] = None, |
| 532 | return_dict: bool = True, |
| 533 | ) -> Union[TCDSchedulerOutput, Tuple]: |
| 534 | """ |
| 535 | Predict the sample from the previous timestep by reversing the SDE. This function propagates the diffusion |
| 536 | process from the learned model outputs (most often the predicted noise). |
| 537 | |
| 538 | Args: |
| 539 | model_output (`torch.Tensor`): |
| 540 | The direct output from learned diffusion model. |
| 541 | timestep (`int`): |
| 542 | The current discrete timestep in the diffusion chain. |
| 543 | sample (`torch.Tensor`): |
| 544 | A current instance of a sample created by the diffusion process. |
| 545 | eta (`float`): |
| 546 | A stochastic parameter (referred to as `gamma` in the paper) used to control the stochasticity in every |
| 547 | step. When eta = 0, it represents deterministic sampling, whereas eta = 1 indicates full stochastic |
| 548 | sampling. |
| 549 | generator (`torch.Generator`, *optional*): |
| 550 | A random number generator. |
| 551 | return_dict (`bool`, *optional*, defaults to `True`): |
| 552 | Whether or not to return a [`~schedulers.scheduling_tcd.TCDSchedulerOutput`] or `tuple`. |
| 553 | Returns: |
| 554 | [`~schedulers.scheduling_utils.TCDSchedulerOutput`] or `tuple`: |
| 555 | If return_dict is `True`, [`~schedulers.scheduling_tcd.TCDSchedulerOutput`] is returned, otherwise a |
| 556 | tuple is returned where the first element is the sample tensor. |
| 557 | """ |
| 558 | if self.num_inference_steps is None: |
| 559 | raise ValueError( |
| 560 | "Number of inference steps is 'None', you need to run 'set_timesteps' after creating the scheduler" |
| 561 | ) |
| 562 | |
| 563 | if self.step_index is None: |
| 564 | self._init_step_index(timestep) |
| 565 | |
| 566 | assert 0 <= eta <= 1.0, "gamma must be less than or equal to 1.0" |
| 567 | |
| 568 | # 1. get previous step value |
| 569 | prev_step_index = self.step_index + 1 |
| 570 | if prev_step_index < len(self.timesteps): |
| 571 | prev_timestep = self.timesteps[prev_step_index] |
| 572 | else: |
| 573 | prev_timestep = torch.tensor(0) |
| 574 | |
| 575 | timestep_s = torch.floor((1 - eta) * prev_timestep).to(dtype=torch.long) |
| 576 | |
| 577 | # 2. compute alphas, betas |
| 578 | alpha_prod_t = self.alphas_cumprod[timestep] |
| 579 | beta_prod_t = 1 - alpha_prod_t |
| 580 | |
| 581 | alpha_prod_t_prev = self.alphas_cumprod[prev_timestep] if prev_timestep >= 0 else self.final_alpha_cumprod |
| 582 |
nothing calls this directly
no test coverage detected