Dive into Deep Learning · §17.3
逆时积分:ODE 与祖先链
连续性方程 · 概率流 ODE · Euler 步与数据均值 · 路径无关坐标 · 祖先链与逆向 SDE
动机
实验设置
为分离离散化误差与神经网络近似误差,我们将两个训练好的 TimeMLP(256, 3) 模型与精确混合 oracle 对比:
loss over the last 1,000 steps: velocity 4.919, noise 0.537
ema_v):沿 \mathbf{x}_t = (1 - t)\mathbf{x}_0 + t\boldsymbol\epsilon 在 \boldsymbol\epsilon - \mathbf{x}_0 上训练,达到理论速度下界(\approx 4.91)。ema_eps):沿保方差调度在 \boldsymbol\epsilon 上训练,达到理论噪声下界(\approx 0.54)。oracle):在任意 (\mathbf{x}, \alpha_t, \sigma_t) 处计算闭式混合后验均值 (\hat{\mathbf{x}}_0, \hat{\boldsymbol\epsilon})。概率输运
\frac{\partial p_t(\mathbf{x})}{\partial t} = -\nabla \cdot \big(p_t(\mathbf{x})\,\mathbf{u}_t(\mathbf{x})\big)
从条件点云到边缘密度
\mathbb{E}_{\mathbf{x}_0}\big[p_t(\mathbf{x} \mid \mathbf{x}_0)\,\mathbf{u}_t(\mathbf{x} \mid \mathbf{x}_0)\big] = p_t(\mathbf{x})\,\mathbf{u}_t(\mathbf{x})
概率流 ODE 的几何结构
\frac{d\mathbf{x}}{dt} = \mathbf{u}_t(\mathbf{x}), \qquad t: 1 \to 0
离散化概率流 ODE
\mathbf{u}_1(\mathbf{x}_1) = \mathbf{x}_1 - \mathbb{E}[\mathbf{x}_0] \quad \Longrightarrow \quad \mathbf{x}_1 - \mathbf{u}_1(\mathbf{x}_1) = \mathbb{E}[\mathbf{x}_0]
精确速度场轨迹
从五个固定初始点——原点 (0, 0) 与 (\pm 1.5, 0), (0, \pm 1.5)——对精确混合场 mix.velocity 积分,直观展示多步曲率如何划分先验空间:
start 1 step 10 steps 100 steps
( 0.00, 0.00) (-0.50, -0.70) (-1.91, -1.27) (-1.98, -1.30)
( 1.50, 0.00) (-0.50, -0.70) ( 2.73, -1.34) ( 2.90, -1.36)
(-1.50, 0.00) (-0.50, -0.70) (-2.92, -1.38) (-3.06, -1.40)
( 0.00, 1.50) (-0.50, -0.70) (-0.11, 2.59) (-0.09, 2.77)
( 0.00, -1.50) (-0.50, -0.70) (-1.98, -2.06) (-2.05, -2.17)
跨调度统一 ODE 积分
\bar{\mathbf{x}}_t = \frac{\mathbf{x}_t}{\alpha_t} = \mathbf{x}_0 + \bar\sigma_t\,\boldsymbol\epsilon, \qquad \frac{d\bar{\mathbf{x}}}{d\bar\sigma} = \hat{\boldsymbol\epsilon}(\bar{\mathbf{x}}, \bar\sigma)
通用预测器与 Euler 循环
将 make_pred(在匹配的对数信噪比处把任意网络输出映射为 (\hat{\mathbf{x}}_0, \hat{\boldsymbol\epsilon}))与 ode_sample 配对,即可让任意求解器在任意调度上积分任意训练好的模型:
'eps' 经 \hat{\mathbf{x}}_0 = (\mathbf{x}_t - \sigma_t\hat{\boldsymbol\epsilon})/\alpha_t 还原干净点,无法在 \alpha_1 = 0 处启动;在 VP 路径上,\alpha_1 \approx 0.007 > 0。实证 ODE 收敛性
从 2{,}000 个高斯起点在训练好的线性速度网络 ema_v 上运行 ode_sample,展示离散化误差随 K 增大的消退过程:

one step: mean [-0.511, -0.736] std [0.036, 0.027]
data: {'weights': [0.517, 0.292, 0.192], 'stray': 0.0145, 'spread': 0.488}
10 steps, network: {'weights': [0.522, 0.273, 0.206], 'stray': 0.0315, 'spread': 0.447}
100 steps, network: {'weights': [0.512, 0.278, 0.211], 'stray': 0.0125, 'spread': 0.475}
10 steps, oracle: {'weights': [0.522, 0.273, 0.206], 'stray': 0.019, 'spread': 0.459}
ode_sample against the loop on the exact field: 9e-05
剖析 10 步与 100 步运行
随机逆向马尔可夫链
\mathbf{x}_s \approx \underbrace{\Big[\mathbf{x}_t + \frac{\beta}{2}\nabla \log p_t + \sqrt{\beta}\,\mathbf{z}\Big]}_{\text{Langevin step } (h = \beta)} + \underbrace{\frac{\beta}{2}\big(\mathbf{x}_t + \nabla \log p_t\big)}_{\text{Flow ODE Euler step}}
Anderson 时间反演定理(1982)
d\mathbf{x} = \big[\mathbf{f}(\mathbf{x}, t) - g(t)^2\nabla_{\mathbf{x}} \log p_t(\mathbf{x})\big]\,dt + g(t)\,d\bar{\mathbf{W}}
祖先链对比概率流 ODE
我们从 20{,}000 个共享高斯起点 \mathbf{x}_1 出发运行 200 步祖先采样(VP 上的 ema_eps)与 100 步 Euler ODE(线性路径上的 ema_v),并以相同起点与相同注入噪声的精确 oracle 运行配对对照:

data: {'weights': [0.504, 0.299, 0.197], 'stray': 0.0103, 'spread': 0.476}
ancestral, network: {'weights': [0.502, 0.296, 0.202], 'stray': 0.0121, 'spread': 0.483}
ancestral, oracle: {'weights': [0.503, 0.296, 0.201], 'stray': 0.0121, 'spread': 0.482}
Euler, network: {'weights': [0.499, 0.305, 0.196], 'stray': 0.0127, 'spread': 0.471}
Euler, oracle: {'weights': [0.499, 0.304, 0.197], 'stray': 0.0107, 'spread': 0.474}
standard error of a weight: [0.0035, 0.0032, 0.0028]
ancestral: network and oracle end in different modes for 0.38% of the starts
Euler: network and oracle end in different modes for 0.21% of the starts
解读 20,000 样本实验
在 N = 20{,}000 个样本下,模式权重的二项标准误为 \sqrt{w(1-w)/N} \approx 0.0035,足以对分布精度做严格检验:
统一路径、目标与采样器
文献中每个扩散与流匹配模型都由三个模块化选择唯一确定——前向路径、回归目标与逆向积分器:
| 模型家族 | 前向路径 | 训练目标 | 逆向采样器 | 所在节 |
|---|---|---|---|---|
| 单水平 DSM | 固定平滑 \mathbf{x}_0 + \sigma\boldsymbol\epsilon | 分数 -\boldsymbol\epsilon/\sigma | 固定 \sigma Langevin MCMC | §17.1 |
| NCSN(Song 与 Ermon,2019) | 几何 VE 阶梯 \tilde\sigma_i | 分数 -\boldsymbol\epsilon/\tilde\sigma_i(权重 \tilde\sigma_i^2) | 退火 Langevin 阶梯 | §17.2 |
| DDPM(Ho 等,2020) | 线性 \beta VP(\alpha_t^2 + \sigma_t^2 = 1) | 噪声 \boldsymbol\epsilon | 祖先链(逆向 SDE) | §17.2–17.3 |
| 流匹配 / 校正流 | 线性 (1 - t)\mathbf{x}_0 + t\boldsymbol\epsilon | 速度 \boldsymbol\epsilon - \mathbf{x}_0 | 概率流 ODE 上的 Euler / Heun | §17.2–17.5 |
| \mathbf{v}-预测(Salimans 与 Ho) | 余弦 VP(\cos\frac{\pi t}{2}, \sin\frac{\pi t}{2}) | 角速度 \mathbf{v} = \alpha_t\boldsymbol\epsilon - \sigma_t\mathbf{x}_0 | ODE 或祖先采样器 | §17.2、§17.6 |
| EDM(Karras 等,2022) | VE 坐标 \bar{\mathbf{x}} = \mathbf{x}_0 + \bar\sigma\boldsymbol\epsilon | 预处理干净点 \hat{\mathbf{x}}_0 | \bar\sigma^{1/\rho} 网格上的二阶 Heun | §17.5–17.6 |
检验理解
检验你对逆时积分与采样器机制的理解:
解答:
核心要点
| 概念 / 采样器 | 数学方程 | 结构保证 | 实践表现 |
|---|---|---|---|
| 连续性方程 | \partial_t p_t = -\nabla \cdot (p_t \mathbf{u}_t) | 守恒总概率质量 | 保证 \mathbf{u}_t = \mathbb{E}[\dot{\mathbf{x}}_t \mid \mathbf{x}_t] 恢复精确模式权重 |
| 概率流 ODE | d\mathbf{x}/dt = \mathbf{u}_t(\mathbf{x})(t: 1 \to 0) | 光滑确定性双射 \mathbf{x}_1 \leftrightarrow \mathbf{x}_0 | 可复现样本、潜在编码与精确似然 |
| 单步 Euler 坍缩 | \mathbf{x}_1 - \mathbf{u}_1(\mathbf{x}_1) = \mathbb{E}[\mathbf{x}_0] | t = 1 处切线指向先验均值 | 所有起点坍缩至 \mathbb{E}[\mathbf{x}_0];弯曲路径需 \ge 10 步 |
| 重缩放 VE 坐标 | \bar{\mathbf{x}} = \mathbf{x}/\alpha_t, \;\bar\sigma = \sigma_t/\alpha_t | 任意路径上均有 d\bar{\mathbf{x}}/d\bar\sigma = \hat{\boldsymbol\epsilon}(\bar{\mathbf{x}}, \bar\sigma) | Euler 步 \mathbf{x}_s = \alpha_s\hat{\mathbf{x}}_0 + \sigma_s\hat{\boldsymbol\epsilon}(= \eta = 0 时的 DDIM) |
| DDPM 祖先步 | \frac{\mathbf{x}_t + \beta\nabla \log p_t}{\sqrt{1-\beta}} + \sqrt{\beta}\mathbf{z} | = \text{Flow ODE Euler step} + \text{Langevin step} | 离散化 Anderson 逆向 SDE;抑制漂移误差 |