import torch from musubi_tuner.ltx_2.components.protocols import DiffusionStepProtocol from musubi_tuner.ltx_2.utils import to_velocity class EulerDiffusionStep(DiffusionStepProtocol): """ First-order Euler method for diffusion sampling. Takes a single step from the current noise level (sigma) to the next by computing velocity from the denoised prediction and applying: sample + velocity * dt. """ def step( self, sample: torch.Tensor, denoised_sample: torch.Tensor, sigmas: torch.Tensor, step_index: int ) -> torch.Tensor: sigma = sigmas[step_index] sigma_next = sigmas[step_index + 1] dt = sigma_next - sigma velocity = to_velocity(sample, sigma, denoised_sample) return (sample.to(torch.float32) + velocity.to(torch.float32) * dt).to(sample.dtype)