pub struct FlowMatchingModel {
pub velocity_net: CnfMlp,
pub config: FlowMatchingConfig,
}Expand description
Conditional Flow Matching model (Lipman et al. 2022).
Learns a velocity field v_θ(x, t) such that Euler integration from t=0 to t=1
transforms noise p_0 = N(0,I) into data p_1.
Loss: E[||v_θ(x_t, t) - u_t(x_t|x_0,x_1)||^2]
where x_t = (1-(1-σ)t)·x_0 + t·x_1 and u_t = x_1 - (1-σ)·x_0.
Fields§
§velocity_net: CnfMlpVelocity network: input [z; t] (dim z_dim + 1) → output z_dim.
config: FlowMatchingConfigConfiguration.
Implementations§
Source§impl FlowMatchingModel
impl FlowMatchingModel
Sourcepub fn new(config: FlowMatchingConfig) -> Self
pub fn new(config: FlowMatchingConfig) -> Self
Create a new FlowMatchingModel.
Sourcepub fn cfm_loss(
&self,
x0_batch: &[Vec<f64>],
x1_batch: &[Vec<f64>],
rng: &mut StdRng,
) -> f64
pub fn cfm_loss( &self, x0_batch: &[Vec<f64>], x1_batch: &[Vec<f64>], rng: &mut StdRng, ) -> f64
Conditional Flow Matching loss.
For each pair (x0, x1):
- Sample
t ~ U[0,1] - Compute
x_t = (1 - (1 - σ_min) * t) * x0 + t * x1 - Conditional vector field:
u_t = x1 - (1 - σ_min) * x0 - Loss term:
||v_θ(x_t, t) - u_t||^2
Sourcepub fn train_step(
&mut self,
x1_batch: &[Vec<f64>],
lr: f64,
rng: &mut StdRng,
) -> f64
pub fn train_step( &mut self, x1_batch: &[Vec<f64>], lr: f64, rng: &mut StdRng, ) -> f64
One training step: compute CFM loss and update via finite-differences.
Returns the CFM loss.
Auto Trait Implementations§
impl Freeze for FlowMatchingModel
impl RefUnwindSafe for FlowMatchingModel
impl Send for FlowMatchingModel
impl Sync for FlowMatchingModel
impl Unpin for FlowMatchingModel
impl UnsafeUnpin for FlowMatchingModel
impl UnwindSafe for FlowMatchingModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more