samplers¶
samplers
¶
Backward-compatibility shim: samplers moved to deltaflow.solvers.
EulerSolver
¶
Bases: BaseSolver
Explicit (forward) Euler integrator for the flow-matching ODE.
Integrates \(\mathrm{d}x/\mathrm{d}t = v_\theta(x, t)\) with the first-order update
using a single velocity evaluation per step. It is cheap but incurs
\(\mathcal{O}(\Delta t^2)\) local truncation error (\(\mathcal{O}(\Delta
t)\) global), so prefer HeunSolver when
accuracy at low step counts matters.
Source code in deltaflow/core/base_solver.py
sample
¶
Generate samples by integrating the velocity field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
initial state (shape/device/dtype template if |
required |
n_steps
|
int
|
number of Euler integration steps. |
50
|
x_cond
|
Optional[Tensor]
|
optional partially-noised starting point, if given the
initial state becomes |
None
|
t_start
|
float
|
starting time, used together with |
0.0
|
t_end
|
float
|
end time, defaults to |
1.0
|
**cond
|
Any
|
extra keyword arguments forwarded to the velocity model. |
{}
|
Source code in deltaflow/solvers/euler.py
HeunSolver
¶
Bases: BaseSolver
Heun (improved-Euler) second-order predictor-corrector integrator.
Each step takes an Euler predictor and averages the velocity at the current and predicted states,
This costs two velocity evaluations per step but has \(\mathcal{O}(\Delta t^3)\) local truncation error (\(\mathcal{O}(\Delta t^2)\) global), so it typically matches Euler's quality at half the number of steps. It is the trapezoidal-rule integrator widely used in EDM-style samplers.
Source code in deltaflow/core/base_solver.py
PosteriorSolver
¶
Bases: BaseSolver
Base-solver wrapper that adds a per-step measurement-likelihood gradient.
For an inverse problem with measurement \(y = A(x) + n\), this samples from the posterior \(p(x \mid y)\) by nudging an unconditional flow-matching solver toward the data-consistency term at every step. Given the current state \(x_t\) and velocity \(v_\theta(x_t, t)\), one step is
where \(\mathcal{T}\) is the flow-matching Tweedie decomposition that maps
\((x_t, v_t, t)\) to the clean-signal estimate \(\hat{x}_1\) (see
deltaflow.inverse.tweedie), and \(\eta\) is the guidance_scale.
The likelihood gradient is obtained by autograd, so if the velocity field
operates on VAE latents while \(A\) is defined on pixels, passing a decoder
to the likelihood object pulls the gradient back into latent space
automatically. Only the sampling-time ODE is modified. The pretrained
velocity field is untouched.
References
Kim et al., "FlowDPS: Flow-Driven Posterior Sampling for Inverse Problems" (2025), https://arxiv.org/abs/2503.08136. "Flower: A Flow-Matching Solver for Inverse Problems" (2025), https://arxiv.org/abs/2509.26287.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_solver
|
BaseSolver
|
any |
required |
likelihood
|
Likelihood
|
object with a |
required |
tweedie
|
Optional[BaseTweedie]
|
flow-matching Tweedie decomposition \(\mathcal{T}\) to derive
\(\hat{x}_1\) from \((x_t, v_t, t)\). Defaults to
|
None
|
guidance_scale
|
float
|
step size \(\eta\) on the likelihood gradient. Larger values snap harder to the measurement but risk over-shooting. |
1.0
|
grad_normalize
|
bool
|
if |
False
|