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
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.