Dive into Deep Learning · §17.3
逆時間積分:ODE と祖先連鎖
連続の式・確率フロー ODE・オイラーステップとデータ平均・経路非依存の座標系・祖先連鎖と逆 SDE
動機
実験設定
離散化誤差とニューラルネットワークの近似誤差を切り分けるため、訓練した 2 つの TimeMLP(256, 3) モデルを混合分布の厳密な oracle と比較する。
loss over the last 1,000 steps: velocity 4.919, noise 0.537
ema_v):\boldsymbol\epsilon - \mathbf{x}_0 をターゲットとして \mathbf{x}_t = (1 - t)\mathbf{x}_0 + t\boldsymbol\epsilon 上で訓練され、理論的な速度損失の下限(\approx 4.91)に到達ema_eps):ノイズ \boldsymbol\epsilon をターゲットとして分散保持スケジュール上で訓練され、理論的なノイズ損失の下限(\approx 0.54)に到達oracle):混合分布の閉形式の事後平均 (\hat{\mathbf{x}}_0, \hat{\boldsymbol\epsilon}) を任意の (\mathbf{x}, \alpha_t, \sigma_t) で計算確率輸送
\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]
厳密な速度場の軌跡
混合分布の厳密な速度場 mix.velocity を、原点 (0, 0) と (\pm 1.5, 0), (0, \pm 1.5) の 5 つの固定初期点から積分すると、複数ステップの曲率が事前分布をどのように分割するかがわかる。
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)
汎用予測器とオイラーループ
同じ対数信号対雑音比で任意のネットワーク出力を (\hat{\mathbf{x}}_0, \hat{\boldsymbol\epsilon}) に変換する make_pred と 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 の実験的収束
ode_sample を訓練済みの線形速度ネットワーク ema_v 上で 2{,}000 個のガウス初期点から実行すると、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
200 回の祖先ステップ(VP 経路上の ema_eps)と 100 回のオイラー ODE ステップ(線形経路上の ema_v)を共通の 20{,}000 個のガウス初期点 \mathbf{x}_1 から実行し、同一の初期点と注入ノイズを用いた厳密な 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 となり、分布の精度を鋭敏に検証できる。
経路・ターゲット・サンプラの統一
文献に登場するあらゆる拡散モデルとフローマッチングモデルは、順方向経路・回帰目標・逆時間積分器という 3 つのモジュール選択によって規定される。
| モデル族 | 順方向経路 | 訓練ターゲット | 逆時間サンプラ | 該当節 |
|---|---|---|---|---|
| 単一レベル DSM | 固定ぼかし \mathbf{x}_0 + \sigma\boldsymbol\epsilon | スコア -\boldsymbol\epsilon/\sigma | 固定 \sigma ランジュバン MCMC | §17.1 |
| NCSN(Song & Ermon, 2019) | 幾何 VE ラダー \tilde\sigma_i | スコア -\boldsymbol\epsilon/\tilde\sigma_i(重み \tilde\sigma_i^2) | アニーリング付きランジュバンラダー | §17.2 |
| DDPM(Ho et al., 2020) | 線形 \beta VP(\alpha_t^2 + \sigma_t^2 = 1) | ノイズ \boldsymbol\epsilon | 祖先連鎖(逆 SDE) | §17.2〜17.3 |
| フローマッチング / Rectified Flow | 線形 (1 - t)\mathbf{x}_0 + t\boldsymbol\epsilon | 速度 \boldsymbol\epsilon - \mathbf{x}_0 | フロー ODE 上のオイラー / 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 et al., 2022) | VE 座標 \bar{\mathbf{x}} = \mathbf{x}_0 + \bar\sigma\boldsymbol\epsilon | 前処理付きクリーンな点 \hat{\mathbf{x}}_0 | \bar\sigma^{1/\rho} グリッド上の 2 次 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 | 再現可能なサンプル、潜在コード、厳密な尤度 |
| 1 ステップオイラー崩壊 | \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) | オイラーステップ \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 を離散化し、ドリフト誤差を減衰 |