Fabrice-TIERCELIN commited on
Commit
58d7bcd
·
verified ·
1 Parent(s): db3260f

Upload diffusion_steps.py

Browse files
packages/ltx-core/src/ltx_core/diffusion_steps.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ from ltx_core.components.protocols import DiffusionStepProtocol
4
+ from ltx_core.utils import to_velocity
5
+
6
+
7
+ class EulerDiffusionStep(DiffusionStepProtocol):
8
+ """
9
+ First-order Euler method for diffusion sampling.
10
+ Takes a single step from the current noise level (sigma) to the next by
11
+ computing velocity from the denoised prediction and applying: sample + velocity * dt.
12
+ """
13
+
14
+ def step(
15
+ self, sample: torch.Tensor, denoised_sample: torch.Tensor, sigmas: torch.Tensor, step_index: int
16
+ ) -> torch.Tensor:
17
+ sigma = sigmas[step_index]
18
+ sigma_next = sigmas[step_index + 1]
19
+ dt = sigma_next - sigma
20
+ velocity = to_velocity(sample, sigma, denoised_sample)
21
+
22
+ return (sample.to(torch.float32) + velocity.to(torch.float32) * dt).to(sample.dtype)