精读 SD3:训练目标
这一页按论文原文的顺序,一句一句读 §2(Simulation-Free Training of Flows)、§3(Flow Trajectories,含 3.1 的三种抽 \(t\) 分布)和 §5.1(61 种训练方式的比较,含 Table 1、Table 2、Fig. 3 的原文分析),开头先读 §1 里交代动机的三段。每一节先给原文位置和原句,再逐句解读;公式都给出完整推导,可以展开看。
直观的动画讲解在 入门课(一维玩具例子),这一页只在需要时链接过去。建议左边开着论文 PDF 或本站的 中英对照版,读一句对一句。
要读的全部原文位置
按论文顺序排列,页码按 arXiv 2403.03206v1 的 PDF。
| 论文位置 | 讲了什么 | 本页 |
|---|---|---|
| §1 第 2、3 段 + 贡献 (i)(p.2) | 路径选择影响训练和采样;直路一步就能走;RF 理论好但实践中没站稳;SD3 的做法是给 RF 重新加权 | 精读 1 |
| §2 第 1 段,Eq. 1(p.2) | 用 ODE 定义生成模型;直接解 ODE 太贵,改为回归一个向量场 | 精读 2 |
| §2 Eq. 2、3(p.2 到 3) | 前向路径 \(z_t=a_tx_0+b_t\epsilon\);边界条件;边际分布 \(p_t\) | 精读 3 |
| §2 Eq. 4、5(p.3) | 条件路径 \(\psi_t(\cdot\mid\epsilon)\)、条件速度 \(u_t(z\mid\epsilon)\) | 精读 4 |
| §2 Eq. 6(p.3)+ 附录 B.1 Eq. 26 到 29(p.20) | 边际速度;它为什么能推动 \(p_t\) | 精读 5 |
| §2 Eq. 7、8(p.3)+ 附录 B.1 Eq. 30 到 36(p.20) | FM 损失、CFM 损失、两者等价 | 精读 6 |
| §2 Eq. 9、10(p.3) | 把条件速度写成显式形式;log-SNR \(\lambda_t\) | 精读 7 |
| §2 Eq. 11、12 + \(\mathcal L_w\)(p.3) | 改写成噪声预测;统一的加权损失;"权重不改变最优解" | 精读 8 |
| §3 Eq. 13 到 17(p.3)+ LDM-Linear 段(p.4) | RF、EDM、Cosine、(LDM-)Linear 四种路径各自的 \(a_t,b_t\) 和权重 | 精读 9 |
| §3.1 第 1 段 + Eq. 18(p.4) | 中间的 \(t\) 最难;换抽样分布 = 加权 | 精读 10 |
| §3.1 Eq. 19 到 22(p.4)+ Fig. 11(p.22)+ 附录 B.4(p.21) | logit-normal、mode、CosMap 三种分布 | 精读 11 |
| §5.1 第 1 段(p.5)+ 附录 B.3(p.21) | 控制变量、为什么不比 loss、评测指标、训练细节 | 精读 12 |
| §5.1.1 变体列表(p.5 到 6) | 61 个变体分别是什么 | 精读 12 |
| §5.1.1 排名方法 + Table 1 + 结论两段(p.6) | 非支配排序、24 种情况取平均、主要结论 | 精读 13 |
| §5.1.1 Table 2 段 + Fig. 3 段(p.6 到 7) | 两个指标的取舍;少步数时 RF 的优势 | 精读 14 |
| §5.2 第 1 句(p.6) | 对 5.1 的一句话总结 | 总结 |
为什么路径的选择重要
读完这几段,你应该能说出 SD3 第一个贡献要解决的问题,以及"重新加权"这个关键词从哪来。
"While specifying a forward path from data to noise leads to efficient training, it also raises the question of which path to choose. This choice can have important implications for sampling. For example, a forward process that fails to remove all noise from the data can lead to a discrepancy in training and test distribution and result in artifacts such as gray image samples (Lin et al., 2024)."
- "specifying a forward path from data to noise leads to efficient training":扩散模型的训练办法是先人为规定"图片怎么一步步变成噪声"(前向路径),再让网络学着倒回去。规定好路径后,训练时只要抽一个时刻、按公式直接算出混合结果,不用一步步模拟,所以高效。这就是 §2 标题 "Simulation-Free" 的意思(精读 2)。
- "which path to choose":路径有无数种(每个时刻图片占多少、噪声占多少),选哪一种是个真问题。§3 列出了四种常见选择。
- "fails to remove all noise from the data":原文说的是前向过程"没能把数据完全变成噪声",也就是到了 \(t=1\) 还残留一点图片信号。训练时网络从没见过纯噪声,但生成时却从纯噪声出发,训练和测试的输入分布不一致。
- "gray image samples (Lin et al., 2024)":Lin et al. 发现 SD 系列因此很难生成很亮或很暗的图,结果偏灰。这说明路径的端点必须设对,这也是 Eq. 3 前边界条件 \(a_1=0,b_1=1\) 的意义(精读 3)。
"Importantly, the choice of the forward process also influences the learned backward process and, thus, the sampling efficiency. While curved paths require many integration steps to simulate the process, a straight path could be simulated with a single step and is less prone to error accumulation. Since each step corresponds to an evaluation of the neural network, this has a direct impact on the sampling speed."
- "influences the learned backward process":网络学到的是"倒回去"的速度场,前向路径决定了这个速度场长什么样。
- "curved paths require many integration steps … a straight path could be simulated with a single step":采样就是用 Euler 法沿速度场走(入门课第 2 课图 2)。路弯,每一步都会走偏,只能切细;路直,一步就到。
- "each step corresponds to an evaluation of the neural network":每走一步要调用一次网络。步数少 = 生成快。
"A particular choice for the forward path is a so-called Rectified Flow …, which connects data and noise on a straight line. Although this model class has better theoretical properties, it has not yet become decisively established in practice. So far, some advantages have been empirically demonstrated in small and medium-sized experiments (Ma et al., 2024), but these are mostly limited to class-conditional models. In this work, we change this by introducing a re-weighting of the noise scales in rectified flow models, similar to noise-predictive diffusion models (Ho et al., 2020). Through a large-scale study, we compare our new formulation to existing diffusion formulations and demonstrate its benefits."
- "connects data and noise on a straight line":RF 的路径是 \(z_t=(1-t)x_0+t\epsilon\),每一对(图片,噪声)之间一条直线(Eq. 13)。
- "not yet become decisively established in practice":当时主流文生图(SD1、SDXL、DALL-E 等)都还用传统扩散的路径。RF 的优势只在中小规模、类别条件(比如 ImageNet 按类别生成)上被验证过,Ma et al. (2024) 就是 SiT。
- "a re-weighting of the noise scales":这是 SD3 第一个贡献的核心。"noise scales" 指不同的时刻 \(t\)(不同的噪声强度)。重新加权 = 训练时让某些噪声强度更重要。§3.1 说明这等价于"多抽某些 \(t\)"(Eq. 18)。
- "similar to noise-predictive diffusion models (Ho et al., 2020)":DDPM 的 ε 预测损失本身就隐含了一种对噪声强度的加权,而它在实践中效果很好。SD3 想给 RF 也找一个好的加权。
- "Through a large-scale study, we compare":这就是 §5.1 的 61 个变体比较。
"(i) We conduct a large-scale, systematic study on different diffusion model and rectified flow formulations to identify the best setting. For this purpose, we introduce new noise samplers for rectified flow models that improve performance over previously known samplers."
- "new noise samplers":就是 §3.1 的抽 \(t\) 分布(logit-normal、mode、CosMap)。论文里 "sampler" 有两个意思:这里指训练时抽 \(t\) 的方式;§5.1 的 "sampler settings" 指生成时的采样设置(步数、CFG)。别混。
ODE 与"免模拟"训练
读完这段,你应该能解释 §2 标题 "Simulation-Free Training of Flows" 的每个词。
"We consider generative models that define a mapping between samples \(x_1\) from a noise distribution \(p_1\) to samples \(x_0\) from a data distribution \(p_0\) in terms of an ordinary differential equation (ODE), \(dy_t=v_\Theta(y_t,t)\,dt\), (1) where the velocity \(v\) is parameterized by the weights \(\Theta\) of a neural network."
- "a mapping between samples \(x_1\) … to samples \(x_0\)":生成模型 = 一个把噪声样本变成数据样本的映射。下标 1 是噪声,0 是数据。
- "in terms of an ordinary differential equation":这个映射不是一步到位,而是由一个 ODE 描述的连续运动:点 \(y_t\) 在每个时刻按速度 \(v_\Theta(y_t,t)\) 移动。从 \(t=1\) 的噪声出发,沿 ODE 走到 \(t=0\),就得到数据。
- "\(v\) is parameterized by the weights \(\Theta\) of a neural network":速度场就是神经网络:输入位置和时刻,输出速度。\(\Theta\) 是网络参数。
"Prior work by Chen et al. (2018) suggested to directly solve Equation (1) via differentiable ODE solvers. However, this process is computationally expensive, especially for large network architectures that parameterize \(v_\Theta(y_t,t)\). A more efficient alternative is to directly regress a vector field \(u_t\) that generates a probability path between \(p_0\) and \(p_1\)."
- "directly solve Equation (1) via differentiable ODE solvers":Chen et al. (2018) 是 Neural ODE。做法是:训练的每一步都真的把 ODE 从头积分一遍("模拟"),看终点对不对,再把误差反向传播回每一步。
- "computationally expensive":积分一次要调用网络几十上百次,训练一步就要这么多次前向和反向。网络一大,根本训不动。
- "directly regress a vector field \(u_t\)":替代办法:如果事先知道"正确的速度场" \(u_t\) 在每个点的值,就可以像普通回归一样,随便抽一个点、让网络输出去逼近 \(u_t\),不用积分。这就是 simulation-free(免模拟):训练时不模拟 ODE。
- "that generates a probability path between \(p_0\) and \(p_1\)":"generates" 是术语:如果所有点按 \(u_t\) 走,它们在每个时刻的整体分布正好是 \(p_t\),就说 \(u_t\) 生成了概率路径 \(p_t\)。下面几节就是在构造这样一个 \(u_t\),并说明怎么回归它。
前向路径与边际分布
读完这段,你应该能解释 Eq. 2 每个符号、边界条件的作用,以及 \(p_t(z_t\mid\epsilon)\) 和 \(p_t(z_t)\) 的区别。
"To construct such a \(u_t\), we define a forward process, corresponding to a probability path \(p_t\) between \(p_0\) and \(p_1=\mathcal N(0,1)\), as \(z_t=a_tx_0+b_t\epsilon\) where \(\epsilon\sim\mathcal N(0,I)\). (2)"
- "To construct such a \(u_t\), we define a forward process":思路是倒着来:先规定"数据怎么变成噪声",再从这个过程反推出速度场。
- "\(p_1=\mathcal N(0,1)\)":噪声分布是标准正态(高维时是 \(\mathcal N(0,I)\),每个维度独立)。
- "\(z_t=a_tx_0+b_t\epsilon\)":时刻 \(t\) 的样本 = \(a_t\) 份图片 + \(b_t\) 份噪声。\(x_0\) 从数据里取,\(\epsilon\) 现抽。\(a_t,b_t\) 是两个只跟 \(t\) 有关的数,选不同的 \(a_t,b_t\) 就是不同的扩散方法(§3)。
"For \(a_0=1,b_0=0,a_1=0\) and \(b_1=1\), the marginals, \(p_t(z_t)=\mathbb E_{\epsilon\sim\mathcal N(0,I)}\,p_t(z_t\mid\epsilon)\), (3) are consistent with the data and noise distribution."
- "\(a_0=1,b_0=0,a_1=0,b_1=1\)":边界条件:\(t=0\) 时 \(z_0=x_0\)(纯图片),\(t=1\) 时 \(z_1=\epsilon\)(纯噪声)。精读 1 里"灰图"问题就是 \(a_1\neq0\) 造成的。注意 EDM(\(a_t\equiv1\))不满足这一条,它靠 \(b_t\) 变得极大来近似。
- "\(p_t(z_t\mid\epsilon)\)":条件分布:噪声 \(\epsilon\) 固定,只让图片 \(x_0\) 随机,\(z_t\) 的分布。它就是整个数据分布被缩小 \(a_t\) 倍、再平移 \(b_t\epsilon\)。\(t=1\) 时缩成 \(\epsilon\) 这一个点。
- "\(p_t(z_t)=\mathbb E_\epsilon\,p_t(z_t\mid\epsilon)\)":边际分布:把所有可能的 \(\epsilon\) 平均起来。也就是"图片和噪声都随机时,\(z_t\) 的分布"。入门课第 3 课图 3 右边的直方图就是它。
- "consistent with the data and noise distribution":代入边界条件:\(p_0\) 就是数据分布,\(p_1\) 就是 \(\mathcal N(0,I)\)。所以 \(p_t\) 是一条从数据连续变到噪声的"概率路径"。
条件路径与条件速度
读完这段,你应该能读懂 \(\psi_t(\cdot\mid\epsilon)\) 和 \(u_t(z\mid\epsilon)\) 的写法,并能自己算出 RF 的条件速度。
"To express the relationship between \(z_t\), \(x_0\) and \(\epsilon\), we introduce \(\psi_t\) and \(u_t\) as \(\psi_t(\cdot\mid\epsilon):x_0\mapsto a_tx_0+b_t\epsilon\) (4), \(u_t(z\mid\epsilon):=\psi_t'(\psi_t^{-1}(z\mid\epsilon)\mid\epsilon)\) (5)."
- "\(\psi_t(\cdot\mid\epsilon):x_0\mapsto a_tx_0+b_t\epsilon\)":\(\psi_t\) 是一个函数。竖线后的 \(\epsilon\) 是固定的条件,点 "\(\cdot\)" 是空着的输入位置,\(\mapsto\) 读作"映射到"。整句:噪声固定为 \(\epsilon\) 时,把图片 \(x_0\) 送到时刻 \(t\) 的位置 \(a_tx_0+b_t\epsilon\)。
- "\(\psi_t^{-1}(z\mid\epsilon)\)":反函数:已知噪声 \(\epsilon\) 和现在的位置 \(z\),倒推出起点 \(x_0=\frac{z-b_t\epsilon}{a_t}\)。
- "\(\psi_t'(\cdots\mid\epsilon)\)":对 \(t\) 求导:\(\psi_t'(x_0\mid\epsilon)=a_t'x_0+b_t'\epsilon\),就是起点为 \(x_0\) 的那条路在时刻 \(t\) 的速度。
- 合起来:\(u_t(z\mid\epsilon)\) = "噪声是 \(\epsilon\)、现在在 \(z\):先倒推出起点,再求那条路此刻的速度"。它对每个 \(z\) 都有定义,是一整张速度地图。
"Since \(z_t\) can be written as solution to the ODE \(z_t'=u_t(z_t\mid\epsilon)\), with initial value \(z_0=x_0\), \(u_t(\cdot\mid\epsilon)\) generates \(p_t(\cdot\mid\epsilon)\)."
- "\(z_t\) can be written as solution to the ODE \(z_t'=u_t(z_t\mid\epsilon)\), with initial value \(z_0=x_0\)":从 \(x_0\) 出发、按 \(u_t(\cdot\mid\epsilon)\) 走,走出来的轨迹正好就是 \(z_t=a_tx_0+b_t\epsilon\)。这是按定义成立的:\(u_t\) 就是从这条轨迹求导得来的。
- "\(u_t(\cdot\mid\epsilon)\) generates \(p_t(\cdot\mid\epsilon)\)":所有图片 \(x_0\sim p_0\) 一起按这张地图走,任意时刻它们的整体分布就是条件分布 \(p_t(\cdot\mid\epsilon)\)。
推导:RF 的条件速度
- RF:\(a_t=1-t,\ b_t=t\),所以 \(a_t'=-1,\ b_t'=1\)。
- 倒推起点:\(x_0=\frac{z-t\epsilon}{1-t}\)。
- 求速度:\(u_t(z\mid\epsilon)=-x_0+\epsilon=\epsilon-\frac{z-t\epsilon}{1-t}=\frac{\epsilon-z}{1-t}\)。
- 读法:终点是 \(\epsilon\),从 \(z\) 出发朝它直走,速度 = 剩余距离 ÷ 剩余时间。
- 如果 \(z\) 就在这一对的直线上(\(z=(1-t)x_0+t\epsilon\)),代入得 \(\epsilon-x_0\)。这就是 RF 的训练目标。
边际速度:把条件平均掉
读完这段,你应该能读懂 Eq. 6 里的权重 \(\frac{p_t(z\mid\epsilon)}{p_t(z)}\),并大致说出附录 B.1 前半在证明什么。
"Remarkably, one can construct a marginal vector field \(u_t\) which generates the marginal probability paths \(p_t\) (Lipman et al., 2023) (see B.1), using the conditional vector fields \(u_t(\cdot\mid\epsilon)\): \(u_t(z)=\mathbb E_{\epsilon\sim\mathcal N(0,I)}\,u_t(z\mid\epsilon)\frac{p_t(z\mid\epsilon)}{p_t(z)}\) (6)"
- "Remarkably":值得惊讶的地方:每个 \(\epsilon\) 各有一张条件地图,各自只负责"自己那一族"的分布;但把它们按适当的权重平均,得到的一张地图就能推动整体的边际分布 \(p_t\)。
- "marginal vector field \(u_t\) which generates the marginal probability paths \(p_t\)":我们真正需要的是它:从 \(p_1\)(纯噪声)出发按 \(u_t\) 倒着走,每个时刻分布都是 \(p_t\),到 \(t=0\) 就是数据分布。
- "\(\frac{p_t(z\mid\epsilon)}{p_t(z)}\)":权重。分子:噪声是 \(\epsilon\) 时,\(z_t\) 落在 \(z\) 的可能性;分母:不管噪声是什么,落在 \(z\) 的总可能性。比值就是"在所有经过 \(z\) 的路里,噪声为 \(\epsilon\) 的路占多大比例"。按贝叶斯公式,\(p(\epsilon)\frac{p_t(z\mid\epsilon)}{p_t(z)}=p(\epsilon\mid z_t=z)\)。
- 所以 Eq. 6 就是 \(u_t(z)=\mathbb E\big[u_t(z\mid\epsilon)\ \big|\ z_t=z\big]\):所有可能经过 \(z\) 的路的条件速度,按"经过的可能性"加权平均。交叉点上 A、B 各占一半:\(\tfrac12(+4)+\tfrac12(-4)=0\)。
"Following (Lipman et al., 2023), to see that \(u_t(z)\) generates \(p_t\), we note that the continuity equation provides a necessary and sufficient condition: \(\frac{d}{dt}p_t(x)+\nabla\cdot[p_t(x)v_t(x)]=0\leftrightarrow v_t\) generates probability density path \(p_t\). (26) Therefore it suffices to show that \(-\nabla\cdot[u_t(z)p_t(z)]=\dots=\frac{d}{dt}p_t(z)\) (27 to 29)"
- "continuity equation":连续性方程,物理里的"质量守恒":某处密度变化的速度 = 流进来减流出去(\(\nabla\cdot\) 是散度,表示净流出)。一个速度场生成某条概率路径,当且仅当它们满足这个方程。
- 证明思路(Eq. 27 到 29):把 Eq. 6 代进 \(u_t(z)p_t(z)\),分母 \(p_t(z)\) 正好消掉,得到 \(\mathbb E_\epsilon[u_t(z\mid\epsilon)p_t(z\mid\epsilon)]\)。每个条件场都满足自己的连续性方程(精读 4 最后一句),对 \(\epsilon\) 取平均后,再用 Eq. 3 把条件分布平均成边际分布,就得到边际场满足连续性方程。
FM 与 CFM
读完这段,你应该能读懂两个损失期望下标的区别,并一步步跟下附录 B.1 的等价证明。
"While regressing \(u_t\) with the Flow Matching objective \(\mathcal L_{FM}=\mathbb E_{t,p_t(z)}\lVert v_\Theta(z,t)-u_t(z)\rVert_2^2\) (7) directly is intractable due to the marginalization in Equation 6, Conditional Flow Matching (see B.1), \(\mathcal L_{CFM}=\mathbb E_{t,p_t(z\mid\epsilon),p(\epsilon)}\lVert v_\Theta(z,t)-u_t(z\mid\epsilon)\rVert_2^2\) (8) with the conditional vector fields \(u_t(z\mid\epsilon)\) provides an equivalent yet tractable objective."
- "\(\mathbb E_{t,p_t(z)}\)":FM 的期望下标:抽一个 \(t\),从边际分布 \(p_t\) 抽一个 \(z\)。标签是边际速度 \(u_t(z)\)。
- "intractable due to the marginalization in Equation 6":intractable = 算不出来。原因就是 Eq. 6 里要对 \(\epsilon\)(等价地,对所有数据)求平均。
- "\(\mathbb E_{t,p_t(z\mid\epsilon),p(\epsilon)}\)":CFM 的期望下标:抽 \(t\),抽噪声 \(\epsilon\sim p(\epsilon)\),再在这个噪声下抽 \(z\sim p_t(z\mid\epsilon)\),也就是取一张图 \(x_0\)、算 \(z=a_tx_0+b_t\epsilon\)。标签是条件速度 \(u_t(z\mid\epsilon)\),RF 下是 \(\epsilon-x_0\)。训练时每一批都这样抽,用这一批的平均代替期望。
- "equivalent yet tractable":等价(最优解和梯度都一样,下面证明)且算得出来。
"The equivalence of objectives \(\mathcal L_{FM}\leftrightharpoons\mathcal L_{CFM}\) follows from \(\mathcal L_{FM}(\Theta)=\mathbb E_{t,p_t(z)}\lVert v_\Theta-u_t(z)\rVert^2\) (30) \(=\mathbb E\lVert v_\Theta\rVert^2-2\mathbb E_{t,p_t(z)}\langle v_\Theta\mid u_t(z)\rangle+c\) (31) \(=\mathbb E\lVert v_\Theta\rVert^2-2\mathbb E_{t,p_t(z\mid\epsilon),p(\epsilon)}\langle v_\Theta\mid u_t(z\mid\epsilon)\rangle+c\) (32) \(=\mathbb E_{t,p_t(z\mid\epsilon),p(\epsilon)}\lVert v_\Theta-u_t(z\mid\epsilon)\rVert^2+c'=\mathcal L_{CFM}(\Theta)+c'\) (33) where \(c,c'\) do not depend on \(\Theta\) …"
逐行解读 Eq. 30 到 36
- Eq. 30 → 31:平方展开 \(\lVert v-u\rVert^2=\lVert v\rVert^2-2\langle v,u\rangle+\lVert u\rVert^2\)。最后一项和网络参数 \(\Theta\) 无关,记作常数 \(c\)。
- 第一项 \(\mathbb E\lVert v_\Theta\rVert^2\):只依赖 \(z\) 的分布。按 FM 的方式抽 \(z\)(从 \(p_t\))和按 CFM 的方式抽(先 \(\epsilon\) 后 \(z\)),\(z\) 的分布都是 \(p_t\)(Eq. 3),所以两种写法相等。
- Eq. 31 → 32,关键一步:交叉项里把边际速度换成条件速度,靠的是 Eq. 34 到 36。
- Eq. 34:把条件版的交叉项写成积分 \(\int dz\,d\epsilon\ p_t(z\mid\epsilon)p(\epsilon)\langle v_\Theta(z,t)\mid u_t(z\mid\epsilon)\rangle\)。
- Eq. 35:乘上再除以 \(p_t(z)\),并把对 \(\epsilon\) 的积分挪到内积的右边:\(\int dz\,p_t(z)\langle v_\Theta\mid\int d\epsilon\ \frac{p_t(z\mid\epsilon)}{p_t(z)}p(\epsilon)u_t(z\mid\epsilon)\rangle\)。(能挪是因为 \(v_\Theta(z,t)\) 不依赖 \(\epsilon\)。)
- Eq. 36:内层积分正是 Eq. 6 的边际速度 \(u_t(z)\),所以等于 FM 的交叉项 \(\mathbb E_{p_t(z)}\langle v_\Theta\mid u_t(z)\rangle\)。
- Eq. 32 → 33:再把平方配回去,只不过这次配的是条件速度,多出来的 \(\lVert u_t(z\mid\epsilon)\rVert^2\) 也和 \(\Theta\) 无关。所以 \(\mathcal L_{FM}=\mathcal L_{CFM}+c'\),梯度相同,最优解相同。
显式形式与 log-SNR
读完这段,你应该能自己从 Eq. 5 推出 Eq. 9 和 Eq. 10,并说清 \(\lambda_t\) 的含义。
"To convert the loss into an explicit form we insert \(\psi_t'(x_0\mid\epsilon)=a_t'x_0+b_t'\epsilon\) and \(\psi_t^{-1}(z\mid\epsilon)=\frac{z-b_t\epsilon}{a_t}\) into (5) \(z_t'=u_t(z_t\mid\epsilon)=\frac{a_t'}{a_t}z_t-\epsilon b_t\big(\frac{a_t'}{a_t}-\frac{b_t'}{b_t}\big)\). (9)"
推导 Eq. 9
- Eq. 5:\(u_t(z\mid\epsilon)=\psi_t'(x_0\mid\epsilon)\),其中 \(x_0=\psi_t^{-1}(z\mid\epsilon)=\frac{z-b_t\epsilon}{a_t}\)。
- 代入:\(u=a_t'\cdot\frac{z-b_t\epsilon}{a_t}+b_t'\epsilon=\frac{a_t'}{a_t}z-\frac{a_t'b_t}{a_t}\epsilon+b_t'\epsilon\)。
- 把含 \(\epsilon\) 的两项合并并提出 \(b_t\):\(-\epsilon b_t\big(\frac{a_t'}{a_t}-\frac{b_t'}{b_t}\big)\)。得到 Eq. 9。
- RF 检验:\(\frac{a_t'}{a_t}=\frac{-1}{1-t}\),\(\frac{b_t'}{b_t}=\frac1t\),\(u=\frac{-z}{1-t}+\epsilon t\big(\frac{1}{1-t}+\frac1t\big)=\frac{\epsilon-z}{1-t}\),和精读 4 一致。
- "explicit form":Eq. 5 是抽象定义,Eq. 9 是能直接代数的式子。要点:速度 = 一项只和 \(z\) 有关(网络看得到)+ 一项正比于噪声 \(\epsilon\)(网络看不到,要猜)。
"Now, consider the signal-to-noise ratio \(\lambda_t:=\log\frac{a_t^2}{b_t^2}\). With \(\lambda_t'=2\big(\frac{a_t'}{a_t}-\frac{b_t'}{b_t}\big)\), we can rewrite Equation (9) as \(u_t(z_t\mid\epsilon)=\frac{a_t'}{a_t}z_t-\frac{b_t}{2}\lambda_t'\epsilon\) (10)"
- "signal-to-noise ratio \(\lambda_t:=\log\frac{a_t^2}{b_t^2}\)":严格说这是信噪比的对数(log-SNR)。\(a_t^2\) 是信号(图片)的"能量",\(b_t^2\) 是噪声的能量。\(\lambda_t\) 大 = 图片清楚,小 = 几乎全是噪声。满足边界条件时,\(t\) 从 0 到 1,\(\lambda_t\) 从 \(+\infty\) 降到 \(-\infty\)(LDM-Linear 是离散的有限步,\(\lambda\) 只在约 +7 到 −5.4 之间,见图 1)。RF 下 \(\lambda_t=2\log\frac{1-t}{t}\),\(t=0.5\) 时为 0。
- "\(\lambda_t'=2\big(\frac{a_t'}{a_t}-\frac{b_t'}{b_t}\big)\)":求导:\(\lambda_t=2\log a_t-2\log b_t\),\((\log a_t)'=\frac{a_t'}{a_t}\)。所以 Eq. 9 括号里那一坨正好是 \(\frac{\lambda_t'}{2}\)。
- "rewrite Equation (9) as …":代进去就是 Eq. 10。好处是:不同方法的 \(a_t,b_t\) 千差万别,但都能用同一个量 \(\lambda_t\) 来描述"现在有多吵"。图 1 右边就是四种路径的 \(\lambda_t\)。
改写成噪声预测,统一的加权损失
读完这段,你应该能推出 Eq. 12、\(\mathcal L_w\) 里 \(w_t\) 的来历,并理解"加权不改变最优解"。
"Next, we use Equation (10) to reparameterize Equation (8) as a noise-prediction objective: \(\mathcal L_{CFM}=\mathbb E\lVert v_\Theta(z,t)-\frac{a_t'}{a_t}z+\frac{b_t}{2}\lambda_t'\epsilon\rVert_2^2\) (11) \(=\mathbb E\big(-\frac{b_t}{2}\lambda_t'\big)^2\lVert\epsilon_\Theta(z,t)-\epsilon\rVert_2^2\) (12) where we defined \(\epsilon_\Theta:=\frac{-2}{\lambda_t'b_t}\big(v_\Theta-\frac{a_t'}{a_t}z\big)\)."
推导 Eq. 11、12
- Eq. 11:把 Eq. 10 的条件速度代进 CFM(Eq. 8)的 \(u_t(z\mid\epsilon)\),减号分配进去。
- 定义 \(\epsilon_\Theta\):让网络的速度输出"翻译"成一个噪声猜测:\(v_\Theta-\frac{a_t'}{a_t}z=-\frac{b_t\lambda_t'}{2}\epsilon_\Theta\)。
- 代回 Eq. 11:\(v_\Theta-\frac{a_t'}{a_t}z+\frac{b_t}{2}\lambda_t'\epsilon=-\frac{b_t\lambda_t'}{2}\epsilon_\Theta+\frac{b_t\lambda_t'}{2}\epsilon=-\frac{b_t\lambda_t'}{2}(\epsilon_\Theta-\epsilon)\)。
- 取平方范数:\(\big(\frac{b_t}{2}\lambda_t'\big)^2\lVert\epsilon_\Theta-\epsilon\rVert^2\)。这就是 Eq. 12。
- "reparameterize … as a noise-prediction objective":速度和噪声之间只差一个已知的线性变换。所以"让网络预测速度"和"让网络预测噪声"本质相同,只是损失前面多了一个随 \(t\) 变的系数 \(\big(\frac{b_t}{2}\lambda_t'\big)^2\)。这个系数就是 CFM 隐含的权重。
"Note that the optimum of the above objective does not change when introducing a time-dependent weighting. Thus, one can derive various weighted loss functions that provide a signal towards the desired solution but might affect the optimization trajectory. For a unified analysis of different approaches, including classic diffusion formulations, we can write the objective in the following form (following Kingma & Gao (2023)): \(\mathcal L_w(x_0)=-\frac12\mathbb E_{t\sim\mathcal U(t),\epsilon\sim\mathcal N(0,I)}\big[w_t\lambda_t'\lVert\epsilon_\Theta(z_t,t)-\epsilon\rVert^2\big]\), where \(w_t=-\frac12\lambda_t'b_t^2\) corresponds to \(\mathcal L_{CFM}\)."
- "the optimum … does not change when introducing a time-dependent weighting":最优解是"在每个 \(t\)、每个 \(z\) 上,猜成条件平均"(精读 6)。给不同 \(t\) 乘不同的正数权重,每个 \(t\) 自己的最优解不变,所以整体最优解不变。
- "provide a signal towards the desired solution but might affect the optimization trajectory":但网络的能力是有限的,训练也不会真的达到最优。权重决定网络"把力气花在哪些 \(t\) 上",所以会影响实际训练出的模型。这就是后面要比较不同权重的原因。
- "\(\mathcal L_w\) … \(t\sim\mathcal U(t)\)":统一形式:\(t\) 均匀抽,每个 \(t\) 乘权重 \(w_t\)。前面的 \(-\frac12\lambda_t'\) 是为了让 \(w_t\) 能直接看成"在 \(\lambda\) 上的权重"(下面的进阶框)。因为 \(\lambda_t'<0\),这个系数是正的。
- "\(w_t=-\frac12\lambda_t'b_t^2\) corresponds to \(\mathcal L_{CFM}\)":让 \(\mathcal L_w\) 和 Eq. 12 相等:\(-\frac12w_t\lambda_t'=\frac{b_t^2}{4}\lambda_t'^2\),两边除以 \(-\frac12\lambda_t'\) 得 \(w_t=-\frac12\lambda_t'b_t^2\)。
换元 \(d\lambda=\lambda_t'\,dt\):\(\mathcal L_w=-\frac12\int_0^1 w_t\lambda_t'\,\mathbb E\lVert\epsilon_\Theta-\epsilon\rVert^2dt=\frac12\int_{-\infty}^{\infty}w(\lambda)\,\mathbb E\lVert\epsilon_\Theta-\epsilon\rVert^2d\lambda\)。也就是说,每种方法最终都等价于"在各个噪声强度 \(\lambda\) 上,对噪声预测误差按 \(w(\lambda)\) 加权"。这样就能把不同路径放在同一个横轴上比较,见精读 9 的图 2。
四种路径:RF、EDM、Cosine、LDM-Linear
读完这节,你应该能说出每种方法的 \(a_t,b_t\)、网络输出什么、权重是什么,并推出 RF 的 \(w_t=\frac{t}{1-t}\)。
"In this work, we consider different variants of the above formalism … Rectified Flows (RFs) … define the forward process as straight paths between the data distribution and a standard normal distribution, i.e. \(z_t=(1-t)x_0+t\epsilon\), (13) and uses \(\mathcal L_{CFM}\) which then corresponds to \(w_t^{RF}=\frac{t}{1-t}\). The network output directly parameterizes the velocity \(v_\Theta\)."
推导 \(w_t^{RF}=\frac{t}{1-t}\)
- \(\lambda_t=\log\frac{(1-t)^2}{t^2}=2\log\frac{1-t}{t}\)。
- \(\lambda_t'=2\big(\frac{-1}{1-t}-\frac1t\big)=\frac{-2}{t(1-t)}\)。
- \(w_t=-\frac12\lambda_t'b_t^2=-\frac12\cdot\frac{-2}{t(1-t)}\cdot t^2=\frac{t}{1-t}\)。
- 换成 \(\lambda\):\(\frac{t}{1-t}=e^{-\lambda/2}\)。噪声越多(\(\lambda\) 越小)权重越大。
- "uses \(\mathcal L_{CFM}\)":普通 RF 就是 CFM,\(t\) 均匀抽,不额外加权。
- "directly parameterizes the velocity":网络直接输出速度 \(v_\Theta\),训练标签是 \(\epsilon-x_0\)。
"EDM (Karras et al., 2022) uses a forward process of the form \(z_t=x_0+b_t\epsilon\) (14) where \(b_t=\exp F_{\mathcal N}^{-1}(t\mid P_m,P_s^2)\) with \(F_{\mathcal N}^{-1}\) being the quantile function of the normal distribution with mean \(P_m\) and variance \(P_s^2\). Note that this choice results in \(\lambda_t\sim\mathcal N(-2P_m,(2P_s)^2)\) for \(t\sim\mathcal U(0,1)\) (15). The network is parameterized through an F-prediction … and the loss can be written as \(\mathcal L_{w_t^{EDM}}\) with \(w_t^{EDM}=\mathcal N(\lambda_t\mid-2P_m,(2P_s)^2)(e^{-\lambda_t}+0.5^2)\) (16)"
- "\(z_t=x_0+b_t\epsilon\)":图片不缩小(\(a_t\equiv1\)),只往上叠噪声。所以 \(t=1\) 时并不是纯噪声,而是噪声大到把图片淹没(图 1 里 EDM 的 \(b_t\) 冲出上界)。
- "quantile function":分位函数是累积分布函数的反函数:\(F^{-1}(0.5)=P_m\),\(t\) 接近 0 或 1 时趋向 \(\mp\infty\)。
- "results in \(\lambda_t\sim\mathcal N(-2P_m,(2P_s)^2)\)":推导:\(a_t=1\),所以 \(\lambda_t=-2\log b_t=-2F^{-1}(t)\)。\(t\) 均匀时 \(F^{-1}(t)\) 服从 \(\mathcal N(P_m,P_s^2)\)(逆变换采样),乘以 \(-2\) 就是 \(\mathcal N(-2P_m,(2P_s)^2)\)。所以 EDM 的 \(P_m,P_s\) 直接控制"训练时噪声强度的分布":\(P_m\) 越大越偏向高噪声。
- "F-prediction":EDM 的网络输出是噪声和图片的一种按 \(\lambda\) 变化的组合,不必细究,统一形式里只看权重。
- "\((e^{-\lambda_t}+0.5^2)\)":0.5 是 EDM 假设的数据标准差 \(\sigma_{data}\)。前面的正态密度就是 Eq. 15 的抽样分布。
"(Nichol & Dhariwal, 2021) proposed a forward process of the form \(z_t=\cos(\frac\pi2t)x_0+\sin(\frac\pi2t)\epsilon\). (17) In combination with an \(\epsilon\)-parameterization and loss, this corresponds to a weighting \(w_t=\mathrm{sech}(\lambda_t/2)\). When combined with a v-prediction loss (Kingma & Gao, 2023), the weighting is given by \(w_t=e^{-\lambda_t/2}\)."
- "\(\cos(\frac\pi2t)x_0+\sin(\frac\pi2t)\epsilon\)":\(a_t^2+b_t^2=1\),叫"方差保持"(variance preserving):混合后的总方差不变。\(\lambda_t=2\log\cot(\frac\pi2t)\)。
- "\(\epsilon\)-parameterization and loss … \(\mathrm{sech}(\lambda_t/2)\)":网络预测噪声、损失就是 \(\lVert\epsilon_\Theta-\epsilon\rVert^2\)(不额外加权)。代进统一形式:\(-\frac12w_t\lambda_t'=1\),\(w_t=\frac{-2}{\lambda_t'}\)。cosine 下 \(\lambda_t'=\frac{-2\pi}{\sin(\pi t)}\),\(w_t=\frac{\sin(\pi t)}{\pi}\),而 \(\mathrm{sech}(\lambda_t/2)=\frac{2}{\cot+\tan}=\sin(\pi t)\),只差常数 \(\pi\)。
- "v-prediction … \(e^{-\lambda_t/2}\)":v 预测是让网络输出 \(a_t\epsilon-b_tx_0\)(Salimans & Ho 提出),对应的权重是 \(e^{-\lambda/2}\)。
"LDM (Rombach et al., 2022) uses a modification of the DDPM schedule (Ho et al., 2020). Both are variance preserving schedules, i.e. \(b_t=\sqrt{1-a_t^2}\), and define \(a_t\) for discrete timesteps \(t=0,\dots,T-1\) in terms of diffusion coefficients \(\beta_t\) as \(a_t=(\prod_{s=0}^t(1-\beta_s))^{\frac12}\). For given boundary values \(\beta_0\) and \(\beta_{T-1}\), DDPM uses \(\beta_t=\beta_0+\frac{t}{T-1}(\beta_{T-1}-\beta_0)\) and LDM uses \(\beta_t=\big(\sqrt{\beta_0}+\frac{t}{T-1}(\sqrt{\beta_{T-1}}-\sqrt{\beta_0})\big)^2\)."
- "variance preserving … \(b_t=\sqrt{1-a_t^2}\)":和 cosine 一样方差保持,只是 \(a_t\) 的曲线不同。
- "discrete timesteps … \(a_t=(\prod(1-\beta_s))^{1/2}\)":DDPM 是离散的 \(T\) 步(通常 1000 步),每一步把信号乘 \(\sqrt{1-\beta_s}\),累乘起来就是 \(a_t\)。
- "DDPM uses … LDM uses …":DDPM 让 \(\beta\) 线性增长;LDM 让 \(\sqrt\beta\) 线性增长(再平方),即 SD 代码里的 "scaled linear"。eps/linear 就是 SD1、SDXL 的训练方式。
中间最难;换抽样分布就是加权
读完这段,你应该能解释"两端的最优预测是均值"这句话,并推出 Eq. 18。
"The RF loss trains the velocity \(v_\Theta\) uniformly on all timesteps in \([0,1]\). Intuitively, however, the resulting velocity prediction target \(\epsilon-x_0\) is more difficult for \(t\) in the middle of \([0,1]\), since for \(t=0\), the optimal prediction is the mean of \(p_1\), and for \(t=1\) the optimal prediction is the mean of \(p_0\)."
- "trains … uniformly on all timesteps":普通 RF 里 \(t\sim\mathcal U(0,1)\),每个时刻一样重要。
- "for \(t=0\), the optimal prediction is the mean of \(p_1\)":\(t=0\) 时 \(z=x_0\),网络完全知道图片,未知的只有噪声 \(\epsilon\)。目标是 \(\epsilon-x_0\),平方误差下最好的猜法是 \(\mathbb E[\epsilon]-x_0=-x_0\),也就是"噪声猜成它的均值 0"。原文说"最优预测是 \(p_1\) 的均值"指的就是这一点:对未知部分只能猜均值。
- "for \(t=1\) the optimal prediction is the mean of \(p_0\)":\(t=1\) 时 \(z=\epsilon\),噪声完全知道,未知的是图片,最好的猜法是 \(\epsilon-\mathbb E[x_0]\),即把图片猜成数据的平均。
- "more difficult for \(t\) in the middle":两端都只要猜一个固定的平均值,函数很简单(接近线性);中间图片和噪声混在一起,网络得判断"这到底是哪类图",函数复杂。入门课第 7 课图 7 画出了这个形状变化。
"In general, changing the distribution over \(t\) from the commonly used uniform distribution \(\mathcal U(t)\) to a distribution with density \(\pi(t)\) is equivalent to a weighted loss \(\mathcal L_{w_t^\pi}\) with \(w_t^\pi=\frac{t}{1-t}\pi(t)\) (18). Thus, we aim to give more weight to intermediate timesteps by sampling them more frequently."
推导 Eq. 18
- RF 在每个 \(t\) 上的损失记作 \(L(t)\)。均匀抽 \(t\):总损失 \(\int_0^1 L(t)\,dt\)。按 \(\pi(t)\) 抽:\(\int_0^1\pi(t)L(t)\,dt\)。
- 后者等于"均匀抽,再乘权重 \(\pi(t)\)"。
- RF 自己在统一形式里的权重是 \(\frac{t}{1-t}\)(精读 9),再乘 \(\pi(t)\),就是 \(w_t^\pi=\frac{t}{1-t}\pi(t)\)。
- "give more weight to intermediate timesteps by sampling them more frequently":为什么用"多抽"而不是"乘权重":两者期望相同,但乘大权重会让个别样本的梯度很大、方差大;多抽则每个样本权重一样,训练更稳。论文没展开这一点,这是常见的理由。
三种抽 \(t\) 的分布
读完这段,你应该能推出 logit-normal 的密度、说明 mode 的参数范围从哪来,并推出 CosMap 的 Eq. 21、22。
"One option for a distribution that puts more weight on intermediate steps is the logit-normal distribution … Its density, \(\pi_{ln}(t;m,s)=\frac{1}{s\sqrt{2\pi}}\frac{1}{t(1-t)}\exp\big(-\frac{(\mathrm{logit}(t)-m)^2}{2s^2}\big)\), (19) where \(\mathrm{logit}(t)=\log\frac{t}{1-t}\), has a location parameter, \(m\), and a scale parameter, \(s\). The location parameter enables us to bias the training timesteps towards either data \(p_0\) (negative \(m\)) or noise \(p_1\) (positive \(m\)). As shown in Figure 11, the scale parameters controls how wide the distribution is. In practice, we sample the random variable \(u\) from a normal distribution \(u\sim\mathcal N(u;m,s)\) and map it through the standard logistic function."
推导 Eq. 19(换元)
- 抽 \(u\sim\mathcal N(m,s^2)\),令 \(t=\frac{1}{1+e^{-u}}\)(logistic 函数),则 \(u=\mathrm{logit}(t)\)。
- 密度换元:\(\pi(t)=p_u(\mathrm{logit}(t))\cdot\big|\frac{d\,\mathrm{logit}(t)}{dt}\big|\)。
- \(\frac{d}{dt}\log\frac{t}{1-t}=\frac1t+\frac{1}{1-t}=\frac{1}{t(1-t)}\)。
- 代入正态密度即得 Eq. 19。
- "towards either data \(p_0\) (negative \(m\)) or noise \(p_1\) (positive \(m\))":\(m<0\) 时 \(u\) 多为负,\(t\) 多小于 0.5,偏数据端;\(m>0\) 偏噪声端。
- "the scale parameters controls how wide":\(s\) 小 = 集中在 \(t=\mathrm{sigmoid}(m)\) 附近(\(m=0\) 时就是中间);\(s\) 很大时,\(u\) 经常很大或很小,\(t\) 反而堆到两端。
- "In practice, we sample \(u\) … and map it through the standard logistic function":实现只有两行:抽正态,过 sigmoid。SD3 最后用 \(m=0,s=1\)(高分辨率时再加平移,见第三部分精读 5)。交互演示见 入门课第 8 课图 8。
"The logit-normal density always vanishes at the endpoints 0 and 1. To study whether this has adverse effects on the performance, we also use a timestep sampling distribution with strictly positive density on \([0,1]\). For a scale parameter \(s\), we define \(f_{mode}(u;s)=1-u-s\cdot\big(\cos^2(\frac\pi2u)-1+u\big)\). (20) For \(-1\le s\le\frac{2}{\pi-2}\), this function is monotonic, and we can use it to sample from the implied density \(\pi_{mode}(t;s)=\big|\frac{d}{dt}f_{mode}^{-1}(t)\big|\). As seen in Figure 11, the scale parameter controls the degree to which either the midpoint (positive \(s\)) or the endpoints (negative \(s\)) are favored during sampling. This formulation also includes a uniform weighting \(\pi_{mode}(t;s=0)=\mathcal U(t)\) for \(s=0\), which has been used widely in previous works on Rectified Flows."
- "always vanishes at the endpoints":logit-normal 在 \(t=0\) 和 \(t=1\) 附近密度趋于 0,那两端几乎不被训练。作者担心这会有害,于是设计了一个两端密度始终为正的分布来对照。
- "\(f_{mode}(u;s)\)":做法是"均匀抽 \(u\),再用 \(f_{mode}\) 变换成 \(t\)"。检查端点:\(u=0\) 时 \(t=1\),\(u=1\) 时 \(t=0\)。\(s=0\) 时 \(t=1-u\),还是均匀分布。
- "\(-1\le s\le\frac{2}{\pi-2}\) … monotonic":只有单调时,变换才是一一对应,才能定义密度。推导见下框。§5.1 里 mode 的 \(s\) 取在 \(-1\) 到 \(1.75\) 之间,应该就是这个原因(推测,论文没明说)。
- "midpoint (positive \(s\)) or the endpoints (negative \(s\))":\(s>0\) 偏中间,\(s<0\) 偏两端。
推导:mode 的参数范围 \(-1\le s\le\frac{2}{\pi-2}\)
- 求导:\(f_{mode}'(u)=-1-s\big(-\tfrac\pi2\sin(\pi u)+1\big)=-(1+s)+\tfrac{s\pi}{2}\sin(\pi u)\)(用了 \(\frac{d}{du}\cos^2(\frac\pi2u)=-\frac\pi2\sin(\pi u)\))。
- 要单调递减,需要对所有 \(u\) 都有 \(f'\le0\)。\(\sin(\pi u)\) 在 0 到 1 之间变化,所以只要两个极端都满足。
- \(\sin=0\):\(-(1+s)\le0\),即 \(s\ge-1\)。
- \(\sin=1\):\(-(1+s)+\frac{s\pi}{2}\le0\),即 \(s(\frac\pi2-1)\le1\),\(s\le\frac{2}{\pi-2}\approx1.752\)。
"Finally, we also consider the cosine schedule from Section 3 in the RF setting. In particular, we are looking for a mapping \(f:u\mapsto f(u)=t,\ u\in[0,1]\), such that the log-snr matches that of the cosine schedule: \(2\log\frac{\cos(\frac\pi2u)}{\sin(\frac\pi2u)}=2\log\frac{1-f(u)}{f(u)}\). Solving for \(f\), we obtain for \(u\sim\mathcal U(u)\) \(t=f(u)=1-\frac{1}{\tan(\frac\pi2u)+1}\), (21) from which we obtain the density \(\pi_{CosMap}(t)=\big|\frac{d}{dt}f^{-1}(t)\big|=\frac{2}{\pi-2\pi t+2\pi t^2}\). (22)"
推导 Eq. 21、22
- 目标:RF 路径不变,但让"抽到的 \(\lambda\)"的分布和 cosine 路径均匀抽 \(t\) 时一样。
- 令两边 log-SNR 相等:\(\frac{1-t}{t}=\cot(\frac\pi2u)\),即 \(\frac1t=1+\cot\),\(t=\frac{1}{1+\cot}=\frac{\tan}{\tan+1}=1-\frac{1}{\tan(\frac\pi2u)+1}\)。这是 Eq. 21。
- 反解:\(\tan(\frac\pi2u)=\frac{t}{1-t}\),\(u=\frac2\pi\arctan\frac{t}{1-t}\)。
- 求导:\(\frac{du}{dt}=\frac2\pi\cdot\frac{1}{1+(\frac{t}{1-t})^2}\cdot\frac{1}{(1-t)^2}=\frac{2}{\pi\big((1-t)^2+t^2\big)}=\frac{2}{\pi-2\pi t+2\pi t^2}\)。这是 Eq. 22。
- Fig. 11(p.22)左边画 mode 在不同 \(s\) 下的密度,右边画 logit-normal 在不同 \((m,s)\) 下的密度,就是上面几句话描述的形状。
- 附录 B.4(p.21)只是复述:logit-normal 采样器超过了均匀的 RF、EDM 和 LDM-Linear,详见 5.1。
实验设置与 61 个变体
读完这段,你应该能说出 5.1 控制了什么、为什么不能比 loss、用什么指标,以及 61 个变体怎么数出来。
"We aim to understand which of the approaches for simulation-free training of normalizing flows as in Equation 1 is the most efficient. To enable comparisons across different approaches, we control for the optimization algorithm, the model architecture, the dataset and samplers. In addition, the losses of different approaches are incomparable and also do not necessarily correlate with the quality of output samples; hence we need evaluation metrics that allow for a comparison between approaches."
- "which of the approaches … is the most efficient":问题:§3 那么多路径和权重,哪个最好。
- "we control for the optimization algorithm, the model architecture, the dataset and samplers":控制变量:优化器、网络结构、数据、采样器全部相同,只换训练方式。具体数值在附录 B.3。论文没写 5.1 用的具体网络结构。
- "the losses of different approaches are incomparable":不同方法的权重 \(w_t\) 不同,loss 的数值尺度完全不同(比如 RF 的权重在高噪声端很大),直接比 loss 没意义。
- "do not necessarily correlate with the quality of output samples":而且 loss 低不等于生成的图好,所以必须看生成图的指标。
"We train models on ImageNet and CC12M, and evaluate both the training and the EMA weights of the models during training using validation losses, CLIP scores, and FID under different sampler settings (different guidance scales and sampling steps). We calculate the FID on CLIP features as proposed by (Sauer et al., 2021). All metrics are evaluated on the COCO-2014 validation split. Full details on the training and sampling hyperparameters are provided in Appendix B.3."
- "ImageNet and CC12M":附录 B.3:ImageNet 本来是分类数据,作者给每张图配了 "a photo of a 〈class name〉" 的标题,当作简单的文生图数据;CC12M 是约一千二百万对网上抓取的图文,更接近真实文生图。
- "training and the EMA weights":EMA 是参数的指数滑动平均(B.3:每 100 个 batch 更新一次,衰减 0.99),通常生成质量更稳。两种都评。
- "CLIP scores, and FID":CLIP score 衡量图和文字对不对得上(越高越好);FID 衡量生成图整体分布和真实图像不像(越低越好)。
- "FID on CLIP features":普通 FID 用 Inception 网络的特征,这里改用 CLIP 的图像特征。B.3:每种设置只生成 1000 张图。所以这里的 FID 数值(约 45 到 150)和其他论文里常见的个位数 FID 不可比。
- "different sampler settings (different guidance scales and sampling steps)":B.3:都用 Euler 法,6 种设置:50 步配 CFG 1.0、2.5、5.0,以及 CFG 5.0 配 5、10、25 步。
"… we train all models using a global batch size of 1024 using the AdamW optimizer with a learning rate of \(10^{-4}\) and 1000 linear warmup steps. We use mixed-precision training and keep a copy of the model weights which gets updated every 100 training batches with an exponential moving average (EMA) using a decay factor of 0.99. For unconditional diffusion guidance, we set the outputs of each of the three text encoders independently to zero with a probability of 46.4%, such that we roughly train an unconditional model in 10% of all steps."
- batch 1024、AdamW、学习率 \(10^{-4}\)、前 1000 步线性 warmup、混合精度。
- 每个文本编码器各自以 46.4% 置零,三个同时为零的概率 \(0.464^3\approx10\%\),用于 CFG。
- B.3 "Evaluation" 还有一句:loss 按 \(t\) 分层评估,"on eight equally spaced values in the time interval \([0,1]\)",因为不同 \(t\) 的 loss 差得太多。
"We train each of 61 different formulations on the two datasets. We include the following variants from Section 3: • Both \(\epsilon\)- and v-prediction loss with linear (eps/linear, v/linear) and cosine (eps/cos, v/cos) schedule. • RF loss with \(\pi_{mode}(t;s)\) (rf/mode(s)) with 7 values for \(s\) chosen uniformly between −1 and 1.75, and additionally for \(s=1.0\) and \(s=0\) which corresponds to uniform timestep sampling (rf/mode). • RF loss with \(\pi_{ln}(t;m,s)\) (rf/lognorm(m, s)) with 30 values for \((m,s)\) in the grid with \(m\) uniform between −1 and 1, and \(s\) uniform between 0.2 and 2.2. • RF loss with \(\pi_{CosMap}(t)\) (rf/cosmap). • EDM (edm(\(P_m,P_s\))) with 15 values for \(P_m\) chosen uniformly between −1.2 and 1.2 and \(P_s\) uniform between 0.6 and 1.8. Note that \(P_m,P_s=(-1.2,1.2)\) corresponds to the parameters in (Karras et al., 2022). • EDM with a schedule such that it matches the log-SNR weighting of rf (edm/rf) and one that matches the log-SNR weighting of v/cos (edm/cos)."
| 变体族 | 个数 | 说明 |
|---|---|---|
| eps/linear、v/linear、eps/cos、v/cos | 4 | 经典扩散:两种路径 × 两种网络输出 |
| rf/mode(s) | 9 | \(s\) 在 −1 到 1.75 之间取 7 个,再加 \(s=1.0\) 和 \(s=0\)(\(s=0\) 就是普通 rf) |
| rf/lognorm(m, s) | 30 | \(m\in[-1,1]\)、\(s\in[0.2,2.2]\) 的网格 |
| rf/cosmap | 1 | Eq. 21、22 |
| edm(P_m, P_s) | 15 | \(P_m\in[-1.2,1.2]\)、\(P_s\in[0.6,1.8]\);(−1.2, 1.2) 是 EDM 原论文的参数 |
| edm/rf、edm/cos | 2 | EDM 路径,但 log-SNR 权重调成和 rf、v/cos 一样 |
| 合计 | 61 |
- "edm/rf … edm/cos":这两个是很巧的对照:权重(在 \(\lambda\) 上的)和 rf、v/cos 相同,只有路径不同。如果它们和 rf、v/cos 表现差很多,说明路径本身有影响。Table 1 里 edm/rf 是 13.04,rf 是 5.67(精读 13)。
- 注意命名:论文里的 "rf" 单独出现时,都指 \(s=0\) 的均匀抽样,也就是普通 RF。
怎么排名,Table 1 怎么读
读完这段,你应该能复述排名的全部步骤,读懂 Table 1 的三列,并说出原文的两个结论和一个提醒。
"For each run, we select the step with minimal validation loss when evaluated with EMA weights and then collect CLIP scores and FID obtained with 6 different sampler settings both with and without EMA weights. For all 24 combinations of sampler settings, EMA weights, and dataset choice, we rank the different formulations using a non-dominated sorting algorithm. For this, we repeatedly compute the variants that are Pareto optimal according to CLIP and FID scores, assign those variants the current iteration index, remove those variants, and continue with the remaining ones until all variants get ranked. Finally, we average those ranks over the 24 different control settings."
- "select the step with minimal validation loss when evaluated with EMA weights":每个变体训练过程中存了很多 checkpoint,选 EMA 权重验证 loss 最低的那一步。注意:这里 loss 只在同一个变体内部比,所以没有"loss 不可比"的问题。
- "24 combinations":6 种采样设置 × 用不用 EMA(2)× 两个数据集(2)= 24。
- "Pareto optimal according to CLIP and FID":Pareto 最优 = 没有别的变体在两个指标上同时不比它差且至少一个更好。
- "assign those variants the current iteration index, remove those variants, and continue":第一轮的 Pareto 最优全部记名次 1,拿掉;剩下的再找 Pareto 最优,记名次 2……直到排完。这就是非支配排序,图 4 用 Table 2 的真实数字演示。
- "average those ranks over the 24 different control settings":每个变体在 24 种情况下各有一个名次,取平均。每种情况下的名次是整数(第几层,同层并列);对 24 种情况取平均后才出现小数。
"We present the results in Tab. 1, where we only show the two best-performing variants for those variants that were evaluated with different hyperparameters. We also show ranks where we restrict the averaging over sampler settings with 5 steps and with 50 steps." / Table 1: "Global ranking of variants. For this ranking, we apply non-dominated sorting averaged over EMA and non-EMA weights, two datasets and different sampling settings."
- "only show the two best-performing variants for those variants that were evaluated with different hyperparameters":原文说有超参数的族只列最好的两个,但实际的表并不完全这样:rf/lognorm 列了 4 个,edm 列了 3 个(多出来的是 EDM 原参数 (−1.20, 1.20) 作为参照),rf/mode 列了 (1.29)、(1.75) 两个,外加 \(s=0\) 的普通 rf。所以 Table 1 共 16 行,不是 61 行。eps/cos 没出现在表里,论文没说明原因。
- "restrict the averaging over sampler settings with 5 steps and with 50 steps":论文没说具体平均了哪些情况。"5 steps" 只可能是 CFG 5.0、5 步这一种设置(乘 EMA 与否、两个数据集,共 4 种情况)。"50 steps" 有三种 CFG,但从数值看,这一列 16 个数全是 0.25 的倍数(如果平均 12 种情况,应该是 1/12 的倍数),所以很可能也只平均了某一种 50 步设置的 4 种情况(推测)。作为对照,"all" 列的数是 1/24 的倍数(1.54 = 37/24),正好对应 24 种情况。
"We observe that rf/lognorm(0.00, 1.00) consistently achieves a good rank. It outperforms a rectified flow formulation with uniform timestep sampling (rf) and thus confirms our hypothesis that intermediate timesteps are more important. Among all the variants, only rectified flow formulations with modified timestep sampling perform better than the LDM-Linear (Rombach et al., 2022) formulation (eps/linear) used previously."
- "consistently achieves a good rank":rf/lognorm(0.00, 1.00) 三列分别是 1.54、1.25、1.50,全部靠前。"consistently" 是关键词:不是每列第一,但每列都好。
- "outperforms … rf and thus confirms our hypothesis":rf 是 5.67。唯一的区别是抽 \(t\) 的分布,所以这个对比直接支持"中间的 \(t\) 更重要"(§3.1)。
- "only rectified flow formulations with modified timestep sampling perform better than … eps/linear":eps/linear 是 2.88,排在它前面的五个全是 RF + 改过的抽样。普通 rf 和所有 EDM 变体都在它后面。
"We also observe that some variants perform well in some settings but worse in others, e.g. rf/lognorm(0.50, 0.60) is the best-performing variant with 50 sampling steps but much worse (average rank 8.5) with 5 sampling steps."
- rf/lognorm(0.50, 0.60):50 步列 1.00(每种情况都在第一层),5 步列 8.50。\(m=0.5\) 偏向高噪声端、\(s=0.6\) 很窄。这提醒我们:选训练方式不能只看一种采样设置,这也是作者用 24 种情况平均的原因。
两个指标的取舍;少步数时的优势
读完这段,你应该能读懂 Table 2 的两组、验证原文"第三名两次、第二名一次"的说法,并读懂 Fig. 3。
"We observe a similar behavior with respect to the two metrics in Tab. 2. The first group shows representative variants and their metrics on both datasets with 25 sampling steps. The next group shows the variants that achieve the best CLIP and FID scores. With the exception of rf/mode(1.75), these variants typically perform very well in one metric but relatively badly in the other. In contrast, we once again observe that rf/lognorm(0.00, 1.00) achieves good performance across metrics and datasets, where it obtains the third-best scores two out of four times and once the second-best performance." / Table 2: "Metrics for different variants. FID and CLIP scores of different variants with 25 sampling steps. We highlight the best, second best, and third best entries."
| Table 2(25 步) | ImageNet CLIP ↑ | ImageNet FID ↓ | CC12M CLIP ↑ | CC12M FID ↓ |
|---|---|---|---|---|
| rf | 0.247 | 49.70 | 0.217 | 94.90 |
| edm(−1.20, 1.20) | 0.236 | 63.12 | 0.200 | 116.60 |
| eps/linear | 0.245 | 48.42 | 0.222 | 90.34 |
| v/cos | 0.244 | 50.74 | 0.209 | 97.87 |
| v/linear | 0.246 | 51.68 | 0.217 | 100.76 |
| rf/lognorm(0.50, 0.60) | 0.256 | 80.41 | 0.233 | 120.84 |
| rf/mode(1.75) | 0.253 | 44.39 | 0.218 | 94.06 |
| rf/lognorm(1.00, 0.60) | 0.254 | 114.26 | 0.234 | 147.69 |
| rf/lognorm(−0.50, 1.00) | 0.248 | 45.64 | 0.219 | 89.70 |
| rf/lognorm(0.00, 1.00) | 0.250 | 45.78 | 0.224 | 89.91 |
颜色:绿 = 该列第一,蓝 = 第二,橙 = 第三(我按数字标的,和原文的说法一致)。
- "The first group shows representative variants":前 5 行:rf、EDM 原参数、三个经典扩散,作为参照。
- "The next group shows the variants that achieve the best CLIP and FID scores":后 5 行:在某个指标上拿过前三的 RF 变体。
- "perform very well in one metric but relatively badly in the other":比如 rf/lognorm(1.00, 0.60):CLIP 两个数据集第二、第一,但 FID 高达 114.26 和 147.69,是全表最差。这种偏向高噪声端的抽样,可能让模型更擅长整体构图和对上文字,但细节质量差(这是我的推测,论文没解释)。
- "With the exception of rf/mode(1.75)":它 ImageNet 上 FID 第一、CLIP 第三,两个指标都好(CC12M 上则不突出)。
- "third-best scores two out of four times and once the second-best":rf/lognorm(0.00, 1.00) 在四个格子里:ImageNet FID 第三、CC12M CLIP 第三、CC12M FID 第二。和原文吻合。
"Finally, we illustrate the qualitative behavior of different formulations in Figure 3, where we use different colors for different groups of formulations (edm, rf, eps and v). Rectified flow formulations generally perform well and, compared to other formulations, their performance degrades less when reducing the number of sampling steps." / Fig. 3: "Rectified flows are sample efficient. Rectified Flows perform better then other formulations when sampling fewer steps. For 25 and more steps, only rf/lognorm(0.00, 1.00) remains competitive to eps/linear."
- 怎么读 Fig. 3:横轴采样步数(5、10、25、50),纵轴 FID。粗线是图例里的六个代表:edm(−1.20, 1.20)、eps/linear、rf/lognorm(0.00, 1.00)、rf、v/cos、v/linear;细淡线(从图上看)是同组的其他变体,按组配色(edm 橙、rf 绿、eps 紫、v 粉)。
- "their performance degrades less when reducing the number of sampling steps":从右往左看(步数减少),绿色的 RF 线上升得最少;5 步时 RF 系列的 FID 明显低于其他组,eps/linear 和 EDM 涨得很高。这和"RF 路径更直,Euler 少走几步误差小"一致(精读 1)。
- "For 25 and more steps, only rf/lognorm(0.00, 1.00) remains competitive to eps/linear":步数多时 eps/linear 追了上来,只有 lognorm(0,1) 还能和它持平;rf 和 v 系列略差,EDM 明显差。所以 RF 的优势主要在少步数。
- 一个论文没讨论的细节:图上几乎所有曲线从 25 步到 50 步 FID 反而上升。论文没解释。图注也没说这张图是哪个数据集、哪个 CFG 设置。
"Having found a formulation in the previous section that allows rectified flow models to not only compete with established diffusion formulations such as LDM-Linear or EDM, but even outperforms them, we now turn to the application of our formulation to high-resolution text-to-image synthesis."
- 这句话是作者对 5.1 的总结,也是第二部分的开头:RF + logit-normal 不仅能和 LDM-Linear、EDM 竞争,还超过了它们。接下来进入网络结构和表示(第二部分)。
第一个贡献讲了什么、证据多强
合上论文,能用几句话讲清 §2、§3、§5.1 的逻辑链。
- §2 建立统一框架:用 ODE 生成;规定前向路径 \(z_t=a_tx_0+b_t\epsilon\);用条件速度构造边际速度;FM 算不出来,CFM 算得出来且等价;改写成噪声预测后,所有方法都是 \(\mathcal L_w\):一条路径 + 一条权重曲线。
- §3 把具体方法放进框架:RF 是直线路径,权重 \(\frac{t}{1-t}\);EDM、Cosine、LDM-Linear 各有自己的路径和权重。
- §3.1 提出新东西:中间的 \(t\) 最难;按 \(\pi(t)\) 抽 \(t\) 等价于乘 \(\pi(t)\) 的权重(Eq. 18);提出 logit-normal、mode、CosMap 三种分布。
- §5.1 验证:61 个变体、2 个数据集、6 种采样设置、EMA 与否,用非支配排序在 CLIP 和 FID 上排名。rf/lognorm(0.00, 1.00) 一直靠前;普通 rf 不如 eps/linear;只有 RF + 改过的抽样超过 eps/linear;少步数时 RF 系列优势明显。
最终自测:rf 和 rf/lognorm(0.00, 1.00) 的区别是什么?Table 1 的哪两个数说明这个区别有用?
路径、网络输出、损失完全一样,只有训练时抽 \(t\) 的分布不同:rf 均匀抽,lognorm(0,1) 先抽标准正态再过 sigmoid,多抽中间的 \(t\),等价于在 RF 权重上乘 \(\pi_{ln}(t)\)。Table 1 全局名次 rf 是 5.67,rf/lognorm(0.00, 1.00) 是 1.54。