| 38 | |
| 39 | |
| 40 | def step(self, model_output, timestep, sample, to_final=False, **kwargs): |
| 41 | if isinstance(timestep, torch.Tensor): |
| 42 | timestep = timestep.cpu() |
| 43 | timestep_id = torch.argmin((self.timesteps - timestep).abs()) |
| 44 | sigma = self.sigmas[timestep_id] |
| 45 | if to_final or timestep_id + 1 >= len(self.timesteps): |
| 46 | sigma_ = 1 if (self.inverse_timesteps or self.reverse_sigmas) else 0 |
| 47 | else: |
| 48 | sigma_ = self.sigmas[timestep_id + 1] |
| 49 | prev_sample = sample + model_output * (sigma_ - sigma) |
| 50 | return prev_sample |
| 51 | |
| 52 | |
| 53 | def return_to_timestep(self, timestep, sample, sample_stablized): |