You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This notebook builds a unified understanding of how Rectified Flow (RF) dynamics can be solved efficiently using the Unified Predictor–Corrector (UniPC) framework.
We begin by formulating rectified flow as a simple, deterministic motion in log-SNR space, where data points evolve along straight lines between pure noise and clean signal.
We then derive UniPC from first principles as a general solver for linear inhomogeneous ODEs, introducing its Green’s-function foundation and numerical discretization rules.
Finally, we apply UniPC to the rectified flow equation, showing how the continuous formulation reduces naturally to practical discrete updates, from the zeroth-order explicit Euler form to higher-order predictor–corrector variants.
Together, these sections provide both intuition and mathematical structure for how rectified flow models are integrated in practice, bridging physical dynamics, neural prediction, and numerical ODE solvers under a single unified lens.
1. Rectified Flow Formulation (RF)
Rectified flow describes a deterministic, straight-line evolution between a clean signal $x_0$ and a noise sample $\epsilon$.
The sample at any intermediate time $t$ is given by
This expresses the rectified flow ODE in log-SNR ($\lambda$) space, where integration proceeds from large negative $\lambda$ (noisy state) to large positive $\lambda$ (clean state).
2. Unified Predictor–Corrector (UniPC)
The Unified Predictor–Corrector (UniPC) method builds on the inhomogeneous linear ordinary differential equation (ODE) form often used in diffusion models and other generative solvers. Below we will derive it from first principles in a pedagogical way so that there is no mystery left.
2.1. Start from the inhomogeneous velocity equation
$$\frac{dx(t)}{dt} = A(t)x(t) + b(t)$$
This is a linear time-varying ODE.
$A(t)$ describes how the system scales or rotates the state $x(t)$.
$b(t)$ is a forcing term, representing an external contribution driving the evolution (for example, the denoising velocity in diffusion models).
Define the Green's function (or propagator) $G(t, s)$ so that the general solution becomes compact:
$$\begin{align*}
G\left(t,s\right)&\equiv\exp\left(\int_{s}^{t}A\left(\tau\right)d\tau\right) \\\
\rightarrow x\left(t\right)&=\underbrace{G\left(t,s\right)x\left(s\right)}_{\text{homogeneous solution}}+\underbrace{\int_{s}^{t}G\left(t,t'\right)b\left(t'\right)dt'}_{\text{forcing term solution}}
\end{align*}$$
2.8. Numerical Approximation and the UniPC Update Rule
In practice, we only evaluate this at a discrete set of time steps
$$t_0 < t_1 < \dots < t_N$$
and we want a fast, accurate way to approximate the integral term.
Moreover, so far we assumed $b$ depends only on $t$. We will now relax this and assume that in diffusion models $b=b_\theta(x(t),t)$, predicted by a neural network $\theta$.
2.8.1. Discretizing the Green's-function form
Let $x_i = x(t_i)$.
For a small step from $t_{i}$ to $t_{i+1}$,
In diffusion models, $A(t)$ and $b(t)$ are often simple functions of $t$,
so $G(t_{i+1},t_i)$ can be precomputed analytically, while the integral is approximated numerically.
where the coefficients $\beta_k$ are chosen so the local truncation error is $O(h_i^{p+1})$.
This step is fast because it only uses already-known drifts.
2.8.4. Corrector phase (implicit refinement)
After predicting $\tilde{x}_ {i+1}$, we evaluate the model again to get $b(\tilde{x}_ {i+1}, t_{i+1})$.
Then we correct the trajectory using a trapezoidal- or Adams–Moulton-like term:
where the the last term now includes the newest velocity estimate. This provides higher-order accuracy and stability, especially for stiff ODEs. Note that by definition $G_{i+1,i+1} = I$, therefore we could have skipped writing it.
3. Solution to Rectified Flow (RF) Using UniPC
Below we connect the last two sections and first arrive at the continuous expression for the RF formulation using UniPC and then derive the discrefe form.
3.1 The continuous form
Starting from the rectified-flow ODE derived at the end of section 1.,
This expression connects the rectified-flow dynamics in log-SNR space to the UniPC discretization framework,
showing that UniPC naturally integrates the straight-line flow between data and noise through the Green’s-function propagation factor $G(\lambda,s)$.
3.2 Zeroth-Order (Explicit Euler) Discretization
Taking the zeroth-order approximation of the integral term gives
Keep the perspective that $x_{0} \equiv x_{0,\theta}(x(\lambda), \lambda)$ is the output of the neural network: given a dirty signal $x(\lambda)$ and its relative noise level $x(\lambda)$, it computes the best estimate of the corresponding clean signal.
Now we take the zeroth-order approximation that $x_{0}$ does not change much within the small interval, so it can be taken outside the integral.