ode_solvers
ode_solvers
¶
ODE solvers for flow matching integration.
Provides reusable ODE solver functions for integrating velocity fields in flow matching models. Used for both latent space priors and action decoders.
euler_step
¶
Single Euler integration step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Tensor
|
Current state tensor (B, D) |
required |
velocity
|
Tensor
|
Velocity at current state (B, D) |
required |
dt
|
float
|
Integration step size |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Next state: z_{t+dt} = z_t + dt * v_t |
Source code in src/versatil/models/layers/denoising/ode_solvers.py
heun_step
¶
Heun's method (2nd order) integration step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Tensor
|
Current state tensor (B, D) |
required |
velocity_fn
|
Callable[[Tensor, Tensor], Tensor]
|
Function that computes velocity given (z, t_tensor) |
required |
t
|
float
|
Current time in [0, 1] |
required |
dt
|
float
|
Integration step size |
required |
batch_size
|
int
|
Batch size |
required |
device
|
device
|
Device for tensors |
required |
dtype
|
dtype
|
Data type for tensors |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Next state: z_{t+dt} = z_t + dt * (v_t + v_{t+dt}) / 2 |
Source code in src/versatil/models/layers/denoising/ode_solvers.py
rk4_step
¶
4th order Runge-Kutta integration step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Tensor
|
Current state tensor (B, D) |
required |
velocity_fn
|
Callable[[Tensor, Tensor], Tensor]
|
Function that computes velocity given (z, t_tensor) |
required |
t
|
float
|
Current time in [0, 1] |
required |
dt
|
float
|
Integration step size |
required |
batch_size
|
int
|
Batch size |
required |
device
|
device
|
Device for tensors |
required |
dtype
|
dtype
|
Data type for tensors |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Next state using RK4: z_{t+dt} = z_t + dt * (k1 + 2k2 + 2k3 + k4) / 6 |
Source code in src/versatil/models/layers/denoising/ode_solvers.py
integrate_ode
¶
Integrate ODE from t=0 to t=1 using specified solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z_init
|
Tensor
|
Initial state tensor (B, D) |
required |
velocity_fn
|
Callable[[Tensor, Tensor], Tensor]
|
Function that computes velocity given (z, t_tensor) where t_tensor has shape (B,) with values in [0, 1] |
required |
num_steps
|
int
|
Number of integration steps |
required |
solver
|
str
|
ODE solver type ("euler", "heun", or "rk4") |
value
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Final state tensor (B, D) after integration from t=0 to t=1 |
Raises:
| Type | Description |
|---|---|
ValueError
|
If num_steps is not positive or solver is not recognized. |