losses¶
losses
¶
Training objectives: conditional flow matching and delta (guidance) alignment.
ConditionalFlowMatchingLoss
¶
Bases: BaseLoss
Regress a velocity field onto the conditional target velocity of a path.
Conditional flow matching trains \(v_\theta\) to match the per-pair target velocity \(u_t\) of a probability path by minimising
where \((x_t, u_t)\) are produced by the chosen interpolant (for the
linear path, \(x_t = (1-t)x_0 + t x_1\) and \(u_t = x_1 - x_0\)). Although
the target is only defined conditionally on \((x_0, x_1)\), its
regression minimiser is the marginal velocity field that transports noise
onto data, which is exactly the field the sampler integrates.
References
Lipman et al., "Flow Matching for Generative Modeling" (2023), https://arxiv.org/abs/2210.02747.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interpolant
|
Optional[BaseInterpolant]
|
the probability path to regress against. Defaults to
|
None
|
coupling
|
Optional[BaseCoupling]
|
optional train-time coupling that produces \((x_0, x_1)\)
pairs from a batch of \(x_1\). See
|
None
|
loss_type
|
str
|
one of |
'l2'
|
time_scale
|
float
|
scales the continuous \(t \in [0, 1]\) before it reaches the model, e.g. to match a diffusion-style time embedding. |
1.0
|
Source code in deltaflow/losses/conditional_flow_matching.py
DeltaAlignmentLoss
¶
Bases: Module
Combined flow-matching and delta-alignment loss.
The total objective linearly combines the velocity-regression term with the multi-scale guidance-alignment term,
where, at each hierarchy level \(l\), the alignment term compares the guidance-difference embeddings \(z^{(i)}_l = g_l\bigl(\text{GAP}(\Delta h^{(i)}_l)\bigr)\) of two augmented views \(i \in \{1, 2\}\) via a cosine dissimilarity,
During the alignment phase, \(\mathcal{L}_\text{flow}\) is computed over all four velocity predictions (two views by two conditioning modes) to preserve both the guided and unguided generative pathways while the alignment term shapes the guidance representation.
References
Di Via et al., "CDPM-Align: Multi-Scale Guidance-Aligned Diffusion Pretraining for Robust Few-Shot Anatomical Landmark Detection" (2026), https://arxiv.org/abs/2606.04898.
Source code in deltaflow/losses/delta_alignment.py
EquilibriumMatchingLoss
¶
Bases: BaseLoss
Regress a time-invariant field onto the Equilibrium Matching target.
Equilibrium Matching (EqM) trains a field \(f_\theta\) to match an
energy-compatible target along the straight noise-to-data path. For an
interpolation coefficient \(\gamma \in [0, 1]\) (a noise level), noise
\(x_0\) and data \(x_1\), the corrupted sample and target are produced by
an EquilibriumInterpolant,
and the objective is (the paper's Eq. 3, up to the target-sign convention below)
\(\gamma\) is implicit, and there is no time at all. Unlike flow
matching, where the model is conditioned on time \(t\), an EqM field is
time-invariant and noise-unconditional, \(f_\theta(x)\). The coefficient
\(\gamma\) is not seen by the model, and neither is any surrogate time.
This loss therefore queries the model as model(x, **cond), passing no
time (and no \(\gamma\)) at all, matching BaseEquilibriumField.
Target sign. The interpolant returns \(u_\gamma = c(\gamma)(x_1 - x_0)\)
(data minus noise), so the field points from noise toward data and is
sampled by gradient ascent \(x \leftarrow x + \eta f(x)\) in
EquilibriumSolver. This matches the official EqM code. The
paper writes the mirror-image \((\epsilon - x)c(\gamma)\) with descent, the
two conventions are equivalent under a global sign flip.
References
Wang and Du, "Equilibrium Matching: Generative Modeling with Implicit Energy-Based Models" (2025), https://arxiv.org/abs/2510.02300.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interpolant
|
Optional[BaseEquilibriumInterpolant]
|
the energy-compatible path. Defaults to
|
None
|
coupling
|
Optional[BaseCoupling]
|
optional train-time coupling that produces \((x_0, x_1)\)
pairs from a batch of \(x_1\). See
|
None
|
loss_type
|
str
|
one of |
'l2'
|
Source code in deltaflow/losses/equilibrium_matching.py
delta_alignment_loss
¶
Multi-scale alignment loss on guidance-difference embeddings.
For each hierarchy level l and each of two augmented views i in {1, 2}::
delta_h_l_i = h_cond_i[l] - h_uncond_i[l]
z_l_i = projector_l(GAP(delta_h_l_i)), L2-normalized
loss_l = 1 - cos(z_l_1, z_l_2)
Returns the average of loss_l over all levels present in every
feature dict and in projector.