conditional_flow_matching
conditional_flow_matching
¶
Conditional flow matching utilities.
ConditionalFlowMatcher
¶
Implements the conditional flow matching interpolation API used by VersatIL.
The path convention is t=0 at source noise x0 and t=1 at target
data x1. For a batch time vector t and samples with arbitrary
trailing dimensions, this class builds the Gaussian bridge
x_t = t * x1 + (1 - t) * x0 + sigma * epsilon and the target velocity
u_t = x1 - x0.
Initialize the matcher with a constant bridge noise standard deviation.
Source code in src/versatil/models/layers/denoising/conditional_flow_matching.py
compute_mu_t
¶
Compute the bridge mean mu_t = t * x1 + (1 - t) * x0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
Tensor
|
Source samples, usually Gaussian noise, with shape |
required |
x1
|
Tensor
|
Target samples with the same shape as |
required |
t
|
Tensor
|
Per-sample times with shape |
required |
Source code in src/versatil/models/layers/denoising/conditional_flow_matching.py
compute_sigma_t
¶
compute_lambda
¶
Compute the score weighting coefficient used by score-CFM variants.
VersatIL currently trains the velocity target directly, but this method
preserves the standard matcher API for callers that expect the
2 * sigma_t / sigma**2 score weight.
Source code in src/versatil/models/layers/denoising/conditional_flow_matching.py
sample_xt
¶
Sample x_t from the conditional Gaussian bridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
Tensor
|
Source samples, usually Gaussian noise. |
required |
x1
|
Tensor
|
Target samples. |
required |
t
|
Tensor
|
Per-sample times. |
required |
epsilon
|
Tensor
|
Standard Gaussian noise with the same shape as |
required |
Source code in src/versatil/models/layers/denoising/conditional_flow_matching.py
compute_conditional_flow
¶
Compute the conditional velocity target u_t = x1 - x0.
The independent CFM path has a constant velocity along each source-target
pair, so t and xt are accepted for API symmetry but do not affect
the returned target.
Source code in src/versatil/models/layers/denoising/conditional_flow_matching.py
sample_noise_like
¶
Sample standard Gaussian noise with the same shape as tensor.
sample_location_and_conditional_flow
¶
Sample the objects needed for one CFM training target.
If t is omitted, times are sampled uniformly in [0, 1]. Returns
(t, x_t, u_t) by default, or (t, x_t, u_t, epsilon) when
return_noise is enabled.