LLM WIKI

Scaling Rectified Flow Transformers for High-Resolution Image Synthesis

Patrick Esser*、Sumith Kulal、Andreas Blattmann、Rahim Entezari、Jonas Müller、Harry Saini、Yam Levi、Dominik Lorenz、Axel Sauer、Frederic Boesel、Dustin Podell、Tim Dockhorn、Zion English、Kyle Lacey、Alex Goodwin、Yannik Marek、Robin Rombach*Stability AI* 同等贡献 · <first.last>@stability.ai
Figure 1原论文图表

我们的 8B Rectified Flow 模型生成的 high-resolution 样本,展示了它在文字排印、精确的 prompt following 与 spatial reasoning、细节刻画,以及跨多种风格生成高质量图像方面的能力。

摘要

Diffusion model 通过逆转数据逐渐走向噪声的前向路径,从噪声中生成数据,并已成为处理图像、视频等高维感知数据的强大生成建模技术。Rectified Flow 是一种较新的 Generative Model 表述,它用直线连接数据与噪声。尽管 Rectified Flow 具有更好的理论性质和概念上的简洁性,但它尚未被明确确立为标准实践。在本工作中,我们改进了用于训练 Rectified Flow 模型的现有噪声采样技术,使采样偏向于感知相关的尺度。通过一项大规模研究,我们证明,与已有的 diffusion 表述相比,该方法在 high-resolution Text-to-Image 任务上表现更优。此外,我们提出一种新的、基于 Transformer 的 Text-to-Image Architecture:它为两种 modality 使用彼此独立的权重,并允许信息在图像 token 与文本 token 之间双向流动,从而改善文本理解、文字排印和人类偏好评分。我们证明,该架构遵循可预测的 scaling 趋势,而且更低的 validation loss 与更好的 Text-to-Image 效果相关;这种改善由多种指标和人类评测共同衡量。我们最大的模型优于 state-of-the-art 模型;我们也将公开实验数据、代码和模型权重。

1. 引言

Diffusion model 从噪声中生成数据(Song et al., 2020)。它们通过训练来逆转数据走向随机噪声的前向路径;因此,结合神经网络的逼近与泛化能力,它们能够生成训练数据中不存在、但仍服从训练数据分布的新数据点(Sohl-Dickstein et al., 2015; Song & Ermon, 2020)。事实证明,这种生成建模技术对于图像等高维感知数据非常有效(Ho et al., 2020)。近年来,Diffusion model 已成为根据自然语言输入生成 high-resolution 图像和视频的事实标准方法,并展现出令人印象深刻的泛化能力(Saharia et al., 2022b; Ramesh et al., 2022; Rombach et al., 2022; Podell et al., 2023; Dai et al., 2023; Esser et al., 2023; Blattmann et al., 2023b; Betker et al., 2023; Blattmann et al., 2023a; Singer et al., 2022)。由于这类模型具有迭代性质,会带来相应的计算成本,而且推理时采样耗时很长,关于如何构造能让模型训练更高效和/或采样更快速的表述,相关研究正在增多(Karras et al., 2023; Liu et al., 2022)。

为数据到噪声指定一条前向路径虽然能实现高效训练,却也带来一个问题:应该选择哪一条路径?这种选择可能对采样产生重要影响。例如,如果某个前向过程未能从数据中移除全部噪声,就可能造成训练分布与测试分布不一致,并产生灰色图像样本等伪影(Lin et al., 2024)。更重要的是,前向过程的选择也会影响所学习的反向过程,从而影响采样效率。弯曲路径需要许多积分步才能模拟这一过程,而直线路径可以只用一步模拟,并且更不容易累积误差。由于每一步都对应一次神经网络求值,所以这会直接影响采样速度。

前向路径的一种特定选择是所谓的 Rectified Flow(Liu et al., 2022; Albergo & Vanden-Eijnden, 2022; Lipman et al., 2023),它用直线连接数据与噪声。虽然这类模型具有更好的理论性质,但尚未在实践中得到明确确立。到目前为止,一些小型和中型实验已从经验上展示了它的若干优势(Ma et al., 2024),不过这些实验大多局限于 class-conditional 模型。在本工作中,我们通过对 Rectified Flow 模型中的噪声尺度进行重新加权来改变这一局面,这与 noise-predictive diffusion model(Ho et al., 2020)的做法相似。通过一项大规模研究,我们将新表述与现有 diffusion 表述进行比较,并证明了它的优势。

我们表明,Text-to-Image 中广泛使用的做法——把固定的文本表示直接输入模型,例如通过 cross-attention(Vaswani et al., 2017; Rombach et al., 2022)——并不理想;为此,我们提出一种新架构,其中图像 token 与文本 token 都拥有可学习的 stream,从而允许信息在二者之间双向流动。我们将该架构与改进后的 Rectified Flow 表述结合,并研究其 scalability。我们证明,validation loss 呈现可预测的 scaling 趋势,而且更低的 validation loss 与更好的自动评测和人类评测结果高度相关。

我们最大的模型在 prompt 理解的定量评测(Ghosh et al., 2023)和人类偏好评分上,都超过了 SDXL(Podell et al., 2023)、SDXL-Turbo(Sauer et al., 2023)、Pixart-α\alpha(Chen et al., 2023)等 state-of-the-art 开放模型,以及 DALL-E 3(Betker et al., 2023)等闭源模型。

本工作的核心贡献如下:

(i)我们针对不同的 diffusion model 与 Rectified Flow 表述开展大规模、系统性的研究,以识别最佳设置。为此,我们为 Rectified Flow 模型引入新的 noise sampler,其性能优于此前已知的 sampler。

(ii)我们为 Text-to-Image 设计了一种新颖且可扩展的架构,使文本 token stream 与图像 token stream 能够在网络内部双向混合。与 UViT(Hoogeboom et al., 2023)和 DiT(Peebles & Xie, 2023)等已有 backbone 相比,我们展示了该架构的优势。

(iii)最后,我们对模型开展 scaling 研究,并证明它遵循可预测的 scaling 趋势。我们表明,更低的 validation loss 与更好的 Text-to-Image 性能高度相关;后者通过 T2I-CompBench(Huang et al., 2023)、GenEval(Ghosh et al., 2023)以及人类评分等指标进行评估。

我们将公开实验结果、代码和模型权重。

2. 无需模拟的 Flow 训练

我们考虑这样一类 Generative Model:它通过一个 ordinary differential equation(ODE)来定义从噪声分布 p1p_1 的样本 x1x_1 到数据分布 p0p_0 的样本 x0x_0 的映射:

dyt=vΘ(yt,t)dt.(1)d y_t = v_\Theta(y_t,t)\,dt . \tag{1}

其中,速度 vv 由神经网络的权重 Θ\Theta 参数化。Chen et al.(2018)的先前工作提出使用可微 ODE solver 直接求解 Equation (1)。然而,这一过程的计算代价很高,尤其是在用大型网络架构参数化 vΘ(yt,t)v_\Theta(y_t,t) 时。更高效的替代方案,是直接回归一个 Vector Field utu_t,使其生成一条连接 p0p_0p1p_1 的 Probability Path。为了构造这样的 utu_t,我们把 p0p_0p1=N(0,1)p_1=\mathcal{N}(0,1) 之间的一条 Probability Path ptp_t 所对应的前向过程定义为:

zt=atx0+btϵ,ϵN(0,I).(2)z_t = a_t x_0 + b_t \epsilon, \qquad \epsilon \sim \mathcal{N}(0,I). \tag{2}

a0=1a_0=1b0=0b_0=0a1=0a_1=0b1=1b_1=1 时,边缘分布为:

pt(zt)=EϵN(0,I)pt(ztϵ).(3)p_t(z_t) = \mathbb{E}_{\epsilon\sim\mathcal{N}(0,I)} p_t(z_t\mid\epsilon). \tag{3}

这些边缘分布与数据分布和噪声分布一致。

为表达 ztz_tx0x_0ϵ\epsilon 之间的关系,我们引入 ψt\psi_tutu_t

ψt(ϵ):x0atx0+btϵ,(4)\psi_t(\cdot\mid\epsilon):x_0\mapsto a_t x_0+b_t\epsilon, \tag{4}
ut(zϵ)ψt ⁣(ψt1(zϵ)ϵ).(5)u_t(z\mid\epsilon) \coloneqq \psi_t'\!\left(\psi_t^{-1}(z\mid\epsilon)\mid\epsilon\right). \tag{5}

由于 ztz_t 可以写成 ODE zt=ut(ztϵ)z_t'=u_t(z_t\mid\epsilon) 在初值 z0=x0z_0=x_0 下的解,因此 ut(ϵ)u_t(\cdot\mid\epsilon) 会生成 pt(ϵ)p_t(\cdot\mid\epsilon)

值得注意的是,我们可以利用 Conditional Vector Field ut(ϵ)u_t(\cdot\mid\epsilon) 构造一个生成 Marginal Probability Path ptp_t 的 Marginal Vector Field utu_t(Lipman et al., 2023;见 Appendix B.1):

ut(z)=EϵN(0,I)[ut(zϵ)pt(zϵ)pt(z)].(6)u_t(z) = \mathbb{E}_{\epsilon\sim\mathcal{N}(0,I)} \left[ u_t(z\mid\epsilon) \frac{p_t(z\mid\epsilon)}{p_t(z)} \right]. \tag{6}

如果直接使用 Flow Matching objective 回归 utu_t

LFM=Et,pt(z)vΘ(z,t)ut(z)22.(7)\mathcal{L}_{\mathrm{FM}} = \mathbb{E}_{t,p_t(z)} \left\lVert v_\Theta(z,t)-u_t(z)\right\rVert_2^2. \tag{7}

由于 Equation (6) 中存在边缘化,上述目标无法直接计算;而 Conditional Flow Matching(见 Appendix B.1)为:

LCFM=Et,pt(zϵ),p(ϵ)vΘ(z,t)ut(zϵ)22.(8)\mathcal{L}_{\mathrm{CFM}} = \mathbb{E}_{t,p_t(z\mid\epsilon),p(\epsilon)} \left\lVert v_\Theta(z,t)-u_t(z\mid\epsilon) \right\rVert_2^2. \tag{8}

使用 Conditional Vector Field ut(zϵ)u_t(z\mid\epsilon) 后,这就成为一个与原目标等价、但可以实际计算的目标。

为了把 loss 化为显式形式,我们将
ψt(x0ϵ)=atx0+btϵ\psi_t'(x_0\mid\epsilon)=a_t'x_0+b_t'\epsilon

ψt1(zϵ)=zbtϵat\psi_t^{-1}(z\mid\epsilon)=\frac{z-b_t\epsilon}{a_t}
代入 Equation (5):

zt=ut(ztϵ)=atatztϵbt(atatbtbt).(9)z_t' =u_t(z_t\mid\epsilon) = \frac{a_t'}{a_t}z_t - \epsilon b_t \left( \frac{a_t'}{a_t}-\frac{b_t'}{b_t} \right). \tag{9}

现在考虑 signal-to-noise ratio(SNR)
λtlogat2bt2\lambda_t\coloneqq\log\frac{a_t^2}{b_t^2}
利用
λt=2(atatbtbt)\lambda_t'=2\left(\frac{a_t'}{a_t}-\frac{b_t'}{b_t}\right)
我们可以把 Equation (9) 改写为:

ut(ztϵ)=atatztbt2λtϵ.(10)u_t(z_t\mid\epsilon) = \frac{a_t'}{a_t}z_t - \frac{b_t}{2}\lambda_t'\epsilon. \tag{10}

接下来,我们使用 Equation (10),把 Equation (8) 重新参数化为一个 noise-prediction objective:

LCFM=Et,pt(zϵ),p(ϵ)vΘ(z,t)atatz+bt2λtϵ22.(11)\mathcal{L}_{\mathrm{CFM}} = \mathbb{E}_{t,p_t(z\mid\epsilon),p(\epsilon)} \left\lVert v_\Theta(z,t) -\frac{a_t'}{a_t}z +\frac{b_t}{2}\lambda_t'\epsilon \right\rVert_2^2. \tag{11}
LCFM=Et,pt(zϵ),p(ϵ)(bt2λt)2ϵΘ(z,t)ϵ22.(12)\mathcal{L}_{\mathrm{CFM}} = \mathbb{E}_{t,p_t(z\mid\epsilon),p(\epsilon)} \left(-\frac{b_t}{2}\lambda_t'\right)^2 \left\lVert \epsilon_\Theta(z,t)-\epsilon \right\rVert_2^2. \tag{12}

其中我们定义
ϵΘ2λtbt(vΘatatz)\epsilon_\Theta\coloneqq\frac{-2}{\lambda_t'b_t}\left(v_\Theta-\frac{a_t'}{a_t}z\right)

需要注意的是,引入随时间变化的权重并不会改变上述目标的最优解。因此,我们可以推导出多种加权 loss:它们都能提供指向目标解的信号,却可能影响优化轨迹。为了在统一框架下分析包括经典 diffusion 表述在内的不同方法,我们可以把目标写成以下形式(沿用 Kingma & Gao, 2023):

Lw(x0)=12EtU(t),ϵN(0,I)[wtλtϵΘ(zt,t)ϵ2].\mathcal{L}_w(x_0) = -\frac{1}{2} \mathbb{E}_{t\sim\mathcal{U}(t),\,\epsilon\sim\mathcal{N}(0,I)} \left[ w_t\lambda_t' \left\lVert \epsilon_\Theta(z_t,t)-\epsilon \right\rVert^2 \right].

其中,wt=12λtbt2w_t=-\frac{1}{2}\lambda_t'b_t^2 对应于 LCFM\mathcal{L}_{\mathrm{CFM}}

3. Flow Trajectories

在本工作中,我们考虑上述形式体系的多种变体,下面对它们作简要介绍。

Rectified Flow. Rectified Flow(RF)(Liu et al., 2022; Albergo & Vanden-Eijnden, 2022; Lipman et al., 2023)把前向过程定义为数据分布与标准正态分布之间的直线路径,即:

zt=(1t)x0+tϵ.(13)z_t=(1-t)x_0+t\epsilon. \tag{13}

RF 使用 LCFM\mathcal{L}_{\mathrm{CFM}};此时它对应的权重为
wtRF=t1tw_t^{\mathrm{RF}}=\frac{t}{1-t}
网络输出直接参数化速度 vΘv_\Theta

EDM. EDM(Karras et al., 2022)采用如下形式的前向过程:

zt=x0+btϵ.(14)z_t=x_0+b_t\epsilon. \tag{14}

其中(Kingma & Gao, 2023),
bt=expFN1(tPm,Ps2)b_t=\exp F_{\mathcal{N}}^{-1}(t\mid P_m,P_s^2)
FN1F_{\mathcal{N}}^{-1} 是均值为 PmP_m、方差为 Ps2P_s^2 的正态分布的分位数函数。需要注意的是,这一选择会得到:

λtN ⁣(2Pm,(2Ps)2),tU(0,1).(15)\lambda_t\sim\mathcal{N}\!\left(-2P_m,(2P_s)^2\right), \qquad t\sim\mathcal{U}(0,1). \tag{15}

网络通过 F-prediction(Kingma & Gao, 2023; Karras et al., 2022)进行参数化,其 loss 可以写为使用下列权重的 LwtEDM\mathcal{L}_{w_t^{\mathrm{EDM}}}

wtEDM=N ⁣(λt2Pm,(2Ps)2)(eλt+0.52).(16)w_t^{\mathrm{EDM}} = \mathcal{N}\!\left(\lambda_t\mid-2P_m,(2P_s)^2\right) \left(e^{-\lambda_t}+0.5^2\right). \tag{16}

Cosine. Nichol & Dhariwal(2021)提出如下形式的前向过程:

zt=cos ⁣(π2t)x0+sin ⁣(π2t)ϵ.(17)z_t = \cos\!\left(\frac{\pi}{2}t\right)x_0 + \sin\!\left(\frac{\pi}{2}t\right)\epsilon. \tag{17}

当它与 ϵ\epsilon-parameterization 和相应 loss 结合时,对应的权重为
wt=sech(λt/2)w_t=\operatorname{sech}(\lambda_t/2)
当它与 v-prediction loss(Kingma & Gao, 2023)结合时,权重为
wt=eλt/2w_t=e^{-\lambda_t/2}

(LDM-)Linear. LDM(Rombach et al., 2022)使用 DDPM schedule(Ho et al., 2020)的一种修改形式。二者都是 variance-preserving schedule,即
bt=1at2b_t=\sqrt{1-a_t^2}
并根据 diffusion coefficient βt\beta_t,为离散 timestep t=0,,T1t=0,\ldots,T-1 定义
at=(s=0t(1βs))1/2a_t=\left(\prod_{s=0}^{t}(1-\beta_s)\right)^{1/2}
给定边界值 β0\beta_0βT1\beta_{T-1} 后,DDPM 使用
βt=β0+tT1(βT1β0)\beta_t=\beta_0+\frac{t}{T-1}(\beta_{T-1}-\beta_0)
而 LDM 使用
βt=(β0+tT1(βT1β0))2\beta_t=\left(\sqrt{\beta_0}+\frac{t}{T-1}(\sqrt{\beta_{T-1}}-\sqrt{\beta_0})\right)^2

3.1. 面向 RF 模型定制的 SNR sampler

RF loss 在 [0,1][0,1] 的所有 timestep 上均匀训练速度 vΘv_\Theta。然而,直观来看,由此得到的速度预测目标 ϵx0\epsilon-x_0[0,1][0,1] 的中部更难预测:因为当 t=0t=0 时,最优预测是 p1p_1 的均值;而当 t=1t=1 时,最优预测是 p0p_0 的均值。

一般而言,把 tt 上常用的均匀分布 U(t)\mathcal{U}(t) 改为密度为 π(t)\pi(t) 的分布,等价于使用权重如下的加权 loss Lwtπ\mathcal{L}_{w_t^\pi}

wtπ=t1tπ(t).(18)w_t^\pi=\frac{t}{1-t}\pi(t). \tag{18}

因此,我们希望通过更频繁地采样中间 timestep,为它们赋予更大的权重。下面介绍我们用于训练模型的 timestep 密度 π(t)\pi(t)

Logit-Normal 采样。 一种能给中间 timestep 更高权重的分布,是 logit-normal 分布(Atchison & Shen, 1980)。它的密度为:

πln(t;m,s)=1s2π1t(1t)exp ⁣((logit(t)m)22s2).(19)\pi_{\mathrm{ln}}(t;m,s) = \frac{1}{s\sqrt{2\pi}} \frac{1}{t(1-t)} \exp\!\left( -\frac{(\operatorname{logit}(t)-m)^2}{2s^2} \right). \tag{19}

其中
logit(t)=logt1t\operatorname{logit}(t)=\log\frac{t}{1-t}
mm 是位置参数,ss 是尺度参数。位置参数使我们能够让训练 timestep 偏向数据 p0p_0(负的 mm)或噪声 p1p_1(正的 mm)。如 Figure 11 所示,尺度参数控制分布的宽度。

在实践中,我们从正态分布 uN(u;m,s)u\sim\mathcal{N}(u;m,s) 中采样随机变量 uu,再通过标准 logistic 函数进行映射。

具有重尾的 Mode Sampling。 Logit-normal 密度在端点 0011 处总是趋于零。为了研究这是否会对性能造成不利影响,我们还采用一种在 [0,1][0,1] 上密度严格为正的 timestep 采样分布。对于尺度参数 ss,定义:

fmode(u;s)=1us(cos2 ⁣(π2u)1+u).(20)f_{\mathrm{mode}}(u;s) = 1-u-s\cdot \left( \cos^2\!\left(\frac{\pi}{2}u\right)-1+u \right). \tag{20}


1s2π2-1\le s\le\frac{2}{\pi-2}
时,该函数单调,因此我们可以用它从隐含密度
πmode(t;s)=ddtfmode1(t)\pi_{\mathrm{mode}}(t;s)=\left|\frac{d}{dt}f_{\mathrm{mode}}^{-1}(t)\right|
中采样。如 Figure 11 所示,尺度参数控制采样偏向中点(正的 ss)还是端点(负的 ss)的程度。

该表述也包含 uniform weighting:当 s=0s=0 时,
πmode(t;s=0)=U(t)\pi_{\mathrm{mode}}(t;s=0)=\mathcal{U}(t)
这一设置已被此前关于 Rectified Flow 的工作广泛采用(Liu et al., 2022; Ma et al., 2024)。

CosMap. 最后,我们还在 RF 设置下考虑 Section 3 中的 cosine schedule(Nichol & Dhariwal, 2021)。具体而言,我们希望找到一个映射
f:uf(u)=tf:u\mapsto f(u)=tu[0,1]u\in[0,1]
使其 log-SNR 与 cosine schedule 相匹配:
2logcos(π2u)sin(π2u)=2log1f(u)f(u)2\log\frac{\cos(\frac{\pi}{2}u)}{\sin(\frac{\pi}{2}u)} =2\log\frac{1-f(u)}{f(u)}
ff 求解后,当 uU(u)u\sim\mathcal{U}(u) 时可得:

t=f(u)=11tan(π2u)+1.(21)t=f(u) = 1-\frac{1}{\tan(\frac{\pi}{2}u)+1}. \tag{21}

由此得到密度:

πCosMap(t)=ddtf1(t)=2π2πt+2πt2.(22)\pi_{\mathrm{CosMap}}(t) = \left|\frac{d}{dt}f^{-1}(t)\right| = \frac{2}{\pi-2\pi t+2\pi t^2}. \tag{22}

4. Text-to-Image Architecture

为了根据文本条件采样图像,我们的模型必须同时考虑文本和图像两种 modality。我们使用 pretrained model 获得合适的表示,随后描述 diffusion backbone 的架构。Figure 2 给出了整体概览。

我们的总体设置沿用 LDM(Rombach et al., 2022),在 pretrained autoencoder 的 latent space 中训练 Text-to-Image 模型。与把图像编码成 latent representation 类似,我们也沿用先前方法(Saharia et al., 2022b; Balaji et al., 2022),使用预训练且冻结的文本模型对文本条件 cc 进行编码。更多细节见 Appendix B.2。

multimodal Diffusion Backbone。 我们的架构建立在 DiT(Peebles & Xie, 2023)架构之上。DiT 只考虑 class-conditional 图像生成,并使用 modulation 机制,以 diffusion process 的 timestep 和类别标签共同作为网络条件。类似地,我们把 timestep tt 的 embedding 和 cvecc_{\mathrm{vec}} 作为 modulation 机制的输入。然而,pooled text representation 只保留了文本输入的粗粒度信息(Podell et al., 2023),因此网络还需要 sequence representation cctxtc_{\mathrm{ctxt}} 中的信息。

我们构造一个由文本输入和图像输入的 embedding 组成的序列。具体而言,我们加入 positional encoding,并把 latent pixel representation
xRh×w×cx\in\mathbb{R}^{h\times w\times c}
2×22\times2 patch 展平为长度
12h12w\frac{1}{2}h\cdot\frac{1}{2}w
的 patch encoding sequence。随后,我们把该 patch encoding 与文本编码 cctxtc_{\mathrm{ctxt}} embedding 到相同维度。

Figure 2原论文图表

我们的模型架构。 (a)所有组件的概览。(b)一个 MM-DiT block。\odot 表示拼接,* 表示逐元素乘法。可以为 QQKK 加入 RMS-Norm,以稳定训练过程。放大查看效果最佳。

接着,我们拼接这两个序列。随后沿用 DiT,依次应用经 modulation 的 attention 和 MLP。

由于文本 embedding 与图像 embedding 在概念上差异很大,我们为两种 modality 分别使用两套独立权重。如 Figure 2b 所示,这等价于为每种 modality 各自设置一个独立的 Transformer,但在 attention 操作时把两种 modality 的序列合并起来;这样,两种表示既可以在各自的空间中工作,又能把另一种表示纳入考虑。

在 scaling 实验中,我们用模型深度 dd(即 attention block 的数量)来参数化模型规模:将 hidden size 设为 64d64d,在 MLP block 中扩展为 464d4\cdot64d 个 channel,并把 attention head 的数量设为 dd

5. 实验

5.1 改进 Rectified Flow

我们的目标是弄清楚:在式 (1) 所描述的 normalizing flow 无模拟训练方法中,哪一种最高效。为了能够比较不同方法,我们控制 optimization algorithm、模型架构、dataset 和 sampler 等变量。此外,不同方法的 loss 彼此不可直接比较,而且 loss 也未必与输出样本质量相关;因此,我们需要能够在方法之间进行比较的评价指标。

我们在 ImageNet (Russakovsky et al., 2014) 和 CC12M (Changpinyo et al., 2021) 上训练模型,并在训练过程中,使用 validation loss、CLIP score (Radford et al., 2021; Hessel et al., 2021) 和 FID (Heusel et al., 2017),在不同 sampler 设置(不同 guidance scale 与 sampling step 数)下评估模型的训练权重和 EMA 权重。我们按照 Sauer et al. (2021) 的方法在 CLIP feature 上计算 FID。所有指标均在 COCO-2014 validation split (Lin et al., 2014) 上评估。训练与采样 hyperparameter 的完整细节见 Appendix B.3。

5.1.1 结果

我们在两个 dataset 上分别训练了 61 种不同的 formulation。我们纳入了 Section 3 中的以下 variant:

  • 使用 linear schedule(eps/linearv/linear)和 cosine schedule(eps/cosv/cos)的 ϵ\epsilon-prediction loss 与 v-prediction loss。
  • 使用 πmode(t;s)\pi_{\text{mode}}(t;s) 的 RF loss(rf/mode(s)):ss 取在 1-11.751.75 之间均匀选出的 7 个值,另加 s=1.0s=1.0s=0s=0;其中 s=0s=0 对应 uniform timestep sampling(rf/mode)。
  • 使用 πln(t;m,s)\pi_{\text{ln}}(t;m,s) 的 RF loss(rf/lognorm(m,s)):在一个网格上取 30 组 (m,s)(m,s),其中 mm1-111 之间均匀取值,ss0.20.22.22.2 之间均匀取值。
  • 使用 πCosMap(t)\pi_{\text{CosMap}}(t) 的 RF loss(rf/cosmap)。
  • EDM(edm(P_m,P_s)):PmP_m1.2-1.21.21.2 之间均匀选取 15 个值,PsP_s0.60.61.81.8 之间均匀取值。注意,(Pm,Ps)=(1.2,1.2)(P_m,P_s)=(-1.2,1.2) 对应 (Karras et al., 2022) 中的参数。
  • 采用与 rf 的 log-SNR weighting 相匹配的 schedule(edm/rf)的 EDM,以及采用与 v/cos 的 log-SNR weighting 相匹配的 schedule(edm/cos)的 EDM。

对每次运行,我们先依据 EMA 权重下的 evaluation 选择 validation loss 最小的 step,然后收集在 6 种不同 sampler 设置下、分别使用和不使用 EMA 权重时得到的 CLIP score 与 FID。

针对 sampler 设置、EMA 权重与 dataset 选择构成的全部 24 种组合,我们使用 non-dominated sorting algorithm 对不同 formulation 进行排名。具体而言,我们反复找出依据 CLIP 和 FID score 达到 Pareto optimal 的 variant,将当前迭代索引赋给这些 variant,移除它们,再对剩余 variant 继续这一过程,直到所有 variant 都获得排名。最后,我们在 24 种不同的控制设置上对这些 rank 取平均。

Table 1. Variant 的全局排名。 该排名采用 non-dominated sorting,并在 EMA 与非 EMA 权重、两个 dataset 以及不同 sampling 设置上取平均。
variant全部设置上的平均 rank5 steps50 steps
rf/lognorm(0.00, 1.00)1.541.251.50
rf/lognorm(1.00, 0.60)2.083.502.00
rf/lognorm(0.50, 0.60)2.718.501.00
rf/mode(1.29)2.753.253.00
rf/lognorm(0.50, 1.00)2.831.502.50
eps/linear2.884.252.75
rf/mode(1.75)3.332.752.75
rf/cosmap4.133.754.00
edm(0.00, 0.60)5.6313.253.25
rf5.676.505.75
v/linear6.835.757.75
edm(0.60, 1.20)9.0013.009.00
v/cos9.1712.258.75
edm/cos11.0414.2511.25
edm/rf13.0415.2513.25
edm(-1.20, 1.20)15.5820.2515.00

结果见 Table 1。对于那些使用不同 hyperparameter 评估过的 variant,我们只展示其中表现最好的两个。我们还给出了只在 5-step sampler 设置和 50-step sampler 设置上取平均时的 rank。

我们观察到,rf/lognorm(0.00, 1.00) 始终取得较好的 rank。它优于采用 uniform timestep sampling 的 Rectified Flow formulation(rf),从而验证了我们的假设:中间 timestep 更重要。在全部 variant 中,只有采用修改后 timestep sampling 的 Rectified Flow formulation 优于此前使用的 LDM-Linear (Rombach et al., 2022) formulation(eps/linear)。

Table 2. 不同 variant 的指标。 下表给出不同 variant 在 25 个 sampling step 下的 FID 和 CLIP score。原表以粗体、下划线和斜体依次标出最佳、第二佳和第三佳结果;这里用“最佳/第二/第三”注记保留原始强调语义。
variantImageNet CLIP ↑ImageNet FID ↓CC12M CLIP ↑CC12M FID ↓
rf0.24749.700.21794.90
edm(-1.20, 1.20)0.23663.120.200116.60
eps/linear0.24548.420.22290.34(第三)
v/cos0.24450.740.20997.87
v/linear0.24651.680.217100.76
rf/lognorm(0.50, 0.60)0.256(最佳)80.410.233(第二)120.84
rf/mode(1.75)0.253(第三)44.39(最佳)0.21894.06
rf/lognorm(1.00, 0.60)0.254(第二)114.260.234(最佳)147.69
rf/lognorm(-0.50, 1.00)0.24845.64(第二)0.21989.70(最佳)
rf/lognorm(0.00, 1.00)0.25045.78(第三)0.224(第三)89.91(第二)

我们还观察到,一些 variant 在某些设置下表现很好,但在另一些设置下更差。例如,rf/lognorm(0.50, 0.60) 在 50 个 sampling step 时表现最佳,但在 5 个 sampling step 时要差得多(平均 rank 为 8.5)。对于 Table 2 中的两个指标,我们也观察到类似现象。第一组展示若干代表性 variant 在两个 dataset 上、采用 25 个 sampling step 时的指标;下一组展示取得最佳 CLIP 和 FID score 的 variant。除 rf/mode(1.75) 外,这些 variant 通常在某一个指标上非常好,但在另一个指标上相对较差。相比之下,我们再次观察到 rf/lognorm(0.00, 1.00) 在不同指标和 dataset 上都表现良好:四项 score 中有两项排名第三,一项排名第二。

最后,我们在 Figure 3 中展示不同 formulation 的定性行为,并用不同颜色区分 formulation 分组:edmrfepsv。Rectified Flow formulation 通常表现良好;与其他 formulation 相比,当 sampling step 数减少时,其性能下降得更少。

5.2 改进 modality-specific representation

上一节找到的 formulation 使 Rectified Flow 模型不仅能与 LDM-Linear (Rombach et al., 2022) 或 EDM (Karras et al., 2022) 等成熟 diffusion formulation 竞争,甚至还能胜过它们。接下来,我们将这一 formulation 应用于 high-resolution text-to-image synthesis。因此,我们算法的最终性能不仅取决于训练 formulation,还取决于 neural network 的 parameterization,以及所使用的图像与文本表示的质量。在以下各节中,我们会说明如何改进所有这些组件,然后在 Section 5.3 中扩展最终方法的规模。

Figure 3原论文图表

Rectified Flow 具有较高的采样效率。 当使用更少的 sampling step 时,Rectified Flow 的表现优于其他 formulation。当 step 数达到 25 或更多时,只有 rf/lognorm(0.00, 1.00) 仍能与 eps/linear 竞争。

5.2.1 改进 Autoencoder

Latent diffusion model 通过在 pretrained autoencoder 的 latent space 中运行而获得较高效率 (Rombach et al., 2022)。该 autoencoder 将输入 RGB 图像 XRH×W×3X\in\mathbb{R}^{H\times W\times3} 映射到更低维的空间 x=E(X)Rh×w×dx=E(X)\in\mathbb{R}^{h\times w\times d}。Autoencoder 的重建质量,为 latent diffusion 训练完成后能够达到的图像质量设定了上限。与 Dai et al. (2023) 类似,我们发现增加 latent channel 数 dd 能显著提升重建性能,见 Table 3。直观地说,预测具有更大 dd 的 latent 是一项更困难的任务,因此 capacity 更大的模型应能在更大的 dd 下表现得更好,最终获得更高的图像质量。我们在 Figure 10 中验证了这一假设:在 sample FID 方面,d=16d=16 的 autoencoder 呈现出更好的 scaling 性能。因此,本文其余部分均选择 d=16d=16

Table 3. 改进 Autoencoder。 不同 channel 配置的重建性能指标。所有模型的 downsampling factor 均为 f=8f=8。原表中 16-channel 一列的四项结果均以粗体标为最佳。
指标4 chn8 chn16 chn
FID ↓2.411.561.06
Perceptual Similarity ↓0.850.680.45
SSIM ↑0.750.790.86
PSNR ↑25.1226.4028.62

5.2.2 改进 Caption

Betker et al. (2023) 证明,合成生成的 caption 能显著改进 Training at Scale 的 text-to-image model。这是因为,大规模图像 dataset 附带的人工 caption 往往过于简单:它们过度关注图像主体,通常会省略背景、场景构图,以及在适用时对图中所显示文字的描述 (Betker et al., 2023)。我们沿用其方法,使用现成的 state-of-the-art vision-language model CogVLM (Wang et al., 2023) 为大规模图像 dataset 创建合成标注。由于合成 caption 可能使 text-to-image model 遗忘 VLM 知识语料中不存在的某些概念,我们采用 50% 原始 caption 与 50% 合成 caption 的比例。

为了评估使用这种 caption mixture 训练的效果,我们训练了两个 d=15d=15 的 MM-DiT 模型,共训练 250k step:一个只使用原始 caption,另一个使用 50/50 mixture。我们在 Table 4 中使用 GenEval benchmark (Ghosh et al., 2023) 评估训练后的模型。结果表明,加入合成 caption 进行训练的模型明显优于只使用原始 caption 的模型。因此,本文其余部分均使用 50/50 的合成/原始 caption mixture。

Table 4. 改进 Caption。 使用由 CogVLM (Wang et al., 2023) 生成的合成 caption 与原始 caption 各占 50% 的 mixture,可改善 text-to-image 性能;评估使用 GenEval benchmark (Ghosh et al., 2023)。
GenEval 项目原始 Caption:成功率 [%]50/50 Mixture:成功率 [%]
Color Attribution11.7524.75
Colors71.5468.09
Position6.5018.00
Counting33.4441.56
Single Object95.0093.75
Two Objects41.4152.53
Overall score43.2749.78

5.2.3 改进 Text-to-Image Backbone

本节比较现有的 Transformer-based diffusion backbone 与我们在 Section 4 中引入的新型 multimodal Transformer-based diffusion backbone——MM-DiT。MM-DiT 专门用不同的(两套)可训练模型权重处理不同 domain,这里即文本 token 与图像 token。更具体地说,我们沿用 Section 5.1 的实验设置,在 CC12M 上比较 DiT、CrossDiT(即不采用 sequence-wise concatenation,而是让 DiT 对文本 token 做 cross-attention (Chen et al., 2023))与 MM-DiT 的 text-to-image 性能。对于 MM-DiT,我们比较使用两套权重和三套权重的模型;后者分别处理 CLIP (Radford et al., 2021) 与 T5 (Raffel et al., 2019) token(参见 Section 4)。注意,DiT(如 Section 4 所述,将文本 token 与图像 token 连接起来)可以看作 MM-DiT 的一个特例:所有 modality 共享同一套权重。最后,我们还考虑 UViT (Hoogeboom et al., 2023) 架构,它是广泛使用的 UNet 与 Transformer variant 之间的一种 hybrid。

PDF PAGE 8原论文图表

未编号 high-resolution 样例板。 此页没有独立 caption;原图下方的 prompt 依次为:

1. “一座太空电梯,电影感科幻艺术。”
2. “一个夹着多汁牛肉饼和融化芝士的汉堡,放在一只看起来像王座的马桶上,立于王室大厅中央。”
3. “我家浴室地板上的一个洞,里面住着小 gremlin。”
4. “一个由汽车零件搭成的小办公室。”
5. “这幅梦幻数字艺术描绘了一只身处葱郁雨林、色彩鲜艳且具有万花筒般效果的鸟。”
6. “完全由分形图案描绘的人类生活。”
7. “一只着火的折纸猪,位于一间黑暗房间中央,地板上有一个五芒星图案。”
8. “一个穿着裤子和夹克的锈蚀旧机器人,在超市里滑雪。”
9. “一只微笑的卡通狗坐在桌边,手边有一只咖啡杯,房间正被火焰吞没。‘这没事,’狗这样安慰自己。”
10. “一幅奇思妙想的创意图像,描绘一种华夫饼与河马混合而成的杂交生物。这个富有想象力的生物有着河马标志性的庞大身躯,但纹理和外观像金黄酥脆的华夫饼。它的皮肤上可能分布着华夫格,表面带有糖浆般的光泽。场景设在一个超现实环境中,以诙谐方式把河马的自然水域栖息地与早餐桌元素结合起来,背景中可能出现巨大的餐具或盘子。图像应唤起一种嬉戏般的荒诞感与烹饪幻想。”

我们在 Figure 4 中分析这些架构的收敛行为:Vanilla DiT 的表现不如 UViT。Cross-attention DiT variant CrossDiT 优于 UViT,不过 UViT 在初始阶段似乎学得快得多。我们的 MM-DiT variant 显著优于 cross-attention variant 与 vanilla variant。使用三套参数而不是两套参数只带来很小的增益,却会增加参数量与 VRAM 使用量,因此本文其余部分选择前一种方案,也就是两套参数。

Figure 4原论文图表

模型架构的训练动态。 在 CC12M 上比较 DiT、CrossDiT、UViT 与 MM-DiT,重点考察 validation loss、CLIP score 和 FID。我们提出的 MM-DiT 在所有指标上均表现良好。

5.3 Training at Scale

在扩大规模之前,我们先过滤并预编码数据,以保证预训练的安全性与效率。至此,前文对 diffusion formulation、架构与数据的全部考量汇聚到最后一节:我们把模型扩展到 8B 参数。

5.3.1 Data Preprocessing

预训练缓解措施。 训练数据会显著影响 Generative Model 的能力。因此,数据过滤是限制不良能力的有效手段 (Nichol, 2022)。在开展 Training at Scale 之前,我们针对以下类别过滤数据:

1. 性内容: 使用 NSFW-detection model 过滤露骨内容。
2. 美学质量: 移除评分系统预测为低分的图像。
3. 复现训练样本(regurgitation): 使用基于 cluster 的 deduplication 方法,移除训练数据中在感知或语义层面重复的样本,见 Appendix E.2。

预计算图像与文本 Embedding。 我们的模型将多个预训练且冻结的 network 的输出作为输入,包括 autoencoder latent 与 text encoder representation。由于这些输出在训练期间保持不变,我们会针对整个 dataset 一次性预计算它们。Appendix E.1 对这一做法给出了详细讨论。

5.3.2 在 high-resolution 上 Finetune

Figure 5原论文图表

QK-normalization 的效果。 在计算 attention matrix 之前对 Q 与 K embedding 做归一化,可防止 attention logit 不稳定地增长(左图);这种增长会导致 attention entropy 坍缩(右图),此前已有 discriminative ViT 文献报告过这一现象 (Dehghani et al., 2023; Wortsman et al., 2023)。不同于这些先前工作,我们在网络最后几个 Transformer block 中观察到这种不稳定性。图中 maximum attention logit 与 attention entropy 均取一个 2B(d=24d=24)模型最后 5 个 block 的平均值。

QK-Normalization。 一般而言,我们先在尺寸为 2562256^2 pixel 的低分辨率图像上预训练所有模型,随后再用具有混合宽高比的更 high-resolution 数据 finetune(细节见下一段)。我们发现,转向 high-resolution 时,mixed-precision training 可能变得不稳定并导致 loss 发散。切换到 full-precision training 可以解决这一问题,但与 mixed-precision training 相比会带来约 2×2\times 的性能下降。Discriminative ViT 文献给出了一种更高效的替代方案:Dehghani et al. (2023) 观察到,大型 vision Transformer 的训练会因 attention entropy 不受控制地增长而发散。为避免这一点,他们建议在 attention operation 之前归一化 Q 与 K。我们采用该方法,在 MMDiT 架构的两个 stream 中都使用带可学习 scale 的 RMSNorm (Zhang & Sennrich, 2019),见 Figure 2。Figure 5 表明,额外的归一化能防止 attention logit 增长不稳定,这与 Dehghani et al. (2023) 和 Wortsman et al. (2023) 的发现一致;与 AdamW optimizer (Loshchilov & Hutter, 2017) 中的 ϵ=1015\epsilon=10^{-15} 结合后,它还能实现高效的 bf16-mixed precision training (Chen et al., 2019)。该技术也可以用于预训练阶段没有采用 qk-normalization 的模型:模型能很快适应额外的 normalization layer,并以更稳定的方式训练。最后需要指出,尽管此方法通常有助于稳定大型模型训练,但它并不是一种普适方案,仍可能需要依据具体训练设置作调整。

适用于不同宽高比的 Positional Encoding。 在固定 256×256256\times256 分辨率上训练后,我们希望:(i) 提 high-resolution;(ii) 支持具有灵活宽高比的 inference。由于我们使用二维 positional frequency embedding,因此必须根据分辨率调整这些 embedding。在多宽高比设置中,若像 Dosovitskiy et al. (2020) 那样直接插值 embedding,就不能正确反映边长。为此,我们组合使用扩展后的 position grid 与插值后的 position grid,再对其进行 frequency embedding。

对于像素数为 S2S^2 的目标分辨率,我们采用 bucketed sampling (NovelAI, 2022; Podell et al., 2023),使每个 batch 都由尺寸一致的 H×WH\times W 图像构成,其中 HWS2H\cdot W\approx S^2。在最大与最小训练宽高比下,分别得到训练过程中会遇到的最大宽度 WmaxW_{\text{max}} 与最大高度 HmaxH_{\text{max}}。令 hmax=Hmax/16h_{\text{max}}=H_{\text{max}}/16wmax=Wmax/16w_{\text{max}}=W_{\text{max}}/16s=S/16s=S/16,它们分别是在 latent space 中先经过 8 倍下采样、再经过 2 倍 patching 后对应的尺寸。基于这些值,我们构造一个竖直 position grid,其取值为

((phmaxs2)256S)p=0hmax1,\left(\left(p-\frac{h_{\text{max}}-s}{2}\right)\cdot\frac{256}{S}\right)_{p=0}^{h_{\text{max}}-1},

水平方向的 position grid 以相同方式构造。随后,我们在 embedding 之前,从所得的二维 positional grid 中做 center-crop。
Figure 6原论文图表

high-resolution 下的 timestep shifting。 右上:基于 Equation (23) 应用 shift 时,人类对图像质量的偏好评分。底部两行:一个 5122512^2 模型分别在 m/n=1.0\sqrt{m/n}=1.0(上)与 m/n=3.0\sqrt{m/n}=3.0(下)的条件下训练和采样。见 Section 5.3.2。

依赖分辨率的 timestep schedule shifting。 直观地说,分辨率越高,pixel 越多,因此需要更多噪声才能破坏其信号。设当前分辨率包含 n=HWn=H\cdot W 个 pixel。考虑一幅“常数”图像,即每个 pixel 的值都为 cc。前向过程产生

zt=(1t)c1+tϵ,z_t=(1-t)c\mathbbm{1}+t\epsilon,

其中 1\mathbbm{1}ϵ\epsilon 均属于 Rn\mathbb{R}^n。于是,ztz_t 给出了随机变量 Y=(1t)c+tηY=(1-t)c+t\etann 个观测,其中 c,ηRc,\eta\in\mathbb{R},且 η\eta 服从 standard normal distribution。因此,E(Y)=(1t)c\mathbb{E}(Y)=(1-t)cσ(Y)=t\sigma(Y)=t。我们可以通过 c=11tE(Y)c=\frac{1}{1-t}\mathbb{E}(Y) 恢复 cccc 与其样本估计

c^=11ti=1nzt,i\hat{c}=\frac{1}{1-t}\sum_{i=1}^{n}z_{t,i}

之间误差的 standard deviation 为

σ(t,n)=t1t1n,\sigma(t,n)=\frac{t}{1-t}\sqrt{\frac{1}{n}},

因为 YY 的样本均值 standard error 的 deviation 为 t/nt/\sqrt{n}。因此,如果已经知道图像 z0z_0 的所有 pixel 取相同值,那么 σ(t,n)\sigma(t,n) 就表示我们对 z0z_0 的不确定程度。例如可以立即看出:在任意给定时间 0<t<10<t<1,宽和高都翻倍会使不确定性减半。进一步地,我们可以把分辨率 nn 下的 timestep tnt_n 映射为分辨率 mm 下的 timestep tmt_m,使二者产生同样程度的不确定性;所用 Ansatz 为 σ(tn,n)=σ(tm,m)\sigma(t_n,n)=\sigma(t_m,m)。解出 tmt_m 得到:
tm=mntn1+(mn1)tn.(23)t_m=\frac{\sqrt{\frac{m}{n}}\,t_n}{1+\left(\sqrt{\frac{m}{n}}-1\right)t_n}. \tag{23}
Figure 7原论文图表

与当前闭源和开源 SOTA 生成图像模型的人类偏好评估。 在 PartiPrompts (Yu et al., 2022) 的视觉质量、prompt following 与 typography generation 三个类别上评估时,我们的 8B 模型相较当前 state-of-the-art text-to-image model 表现更好。

Figure 6 展示了这一 shifting function。需要注意,“常数图像”假设并不现实。为寻找 inference 时合适的 shift 值 α:=m/n\alpha\coloneq\sqrt{m/n},我们把不同 shift 应用于一个在 1024×10241024\times1024 分辨率上训练的模型的 sampling step,并开展人类偏好研究。Figure 6 的结果表明,样本在 shift 大于 1.51.5 时受到明显偏好,但更大的各个 shift 值之间差异较小。因此,在后续实验中,无论训练还是在 1024×10241024\times1024 分辨率采样,我们都采用 α=3.0\alpha=3.0。Figure 6 还给出了训练 8k step 后、有无这种 shift 的样本定性对比。最后,Equation (23) 意味着一个与 Hoogeboom et al. (2023) 类似的 lognm\log\frac{n}{m} log-SNR shift:

λtm=2log1tnmntn.(24)\lambda_{t_m}=2\log\frac{1-t_n}{\sqrt{\frac{m}{n}}\,t_n}. \tag{24}
λtm=λtn2logα=λtnlogmn.(25)\lambda_{t_m}=\lambda_{t_n}-2\log\alpha =\lambda_{t_n}-\log\frac{m}{n}\,. \tag{25}

完成分辨率 1024×10241024\times1024 下的 shifted training 后,我们再按照 Appendix C 的方法,使用 Direct Preference Optimization(DPO)对模型进行对齐。

5.3.3 结果

在 Figure 8 中,我们考察 Training at Scale MM-DiT 的效果。对于图像,我们开展一项大规模 scaling study:使用预编码数据(参见 Appendix E.1),以 batch size 4096,在 2562256^2 pixel 分辨率上训练不同参数规模的模型 500k step。我们使用 2×22\times2 patch (Peebles & Xie, 2023) 训练,并每 50k step 在 COCO dataset (Lin et al., 2014) 上报告 validation loss。具体而言,为降低 validation loss 信号中的噪声,我们在 t(0,1)t\in(0,1) 上等距采样 loss level,分别计算每个 level 的 validation loss,然后对除最后一个 level(t=1t=1)之外的所有 level 取平均。

类似地,我们对 MM-DiT 在视频上的 scaling 做了一项初步研究。为此,我们从预训练图像权重出发,并额外采用 2 倍 temporal patching。我们沿用 Blattmann et al. (2023b) 的方法:把 temporal axis 折叠到 batch axis,将数据输入 pretrained model。在每个 attention layer 中,我们重新排列视觉 stream 中的表示,并在 spatial attention operation 之后、最终 feedforward layer 之前,增加一个覆盖全部 spatio-temporal token 的 full attention。视频模型训练 140k step,batch size 为 512,训练视频包含 16 帧、每帧 2562256^2 pixel。我们每 5k step 在 Kinetics dataset (Carreira & Zisserman, 2018) 上报告 validation loss。需要注意,Figure 8 中报告的视频训练 FLOPs 只包括视频训练本身,不包括图像预训练的 FLOPs。

无论图像还是视频 domain,随着模型规模与 training step 增加,我们都观察到 validation loss 平滑下降。我们发现,validation loss 与综合 evaluation metric(CompBench (Huang et al., 2023)、GenEval (Ghosh et al., 2023))及人类偏好高度相关。这些结果支持把 validation loss 作为一种简单且通用的模型性能度量。无论图像模型还是视频模型,我们的结果都没有显示出饱和迹象。

Figure 12 展示了延长大型模型训练时间如何影响样本质量。Table 5 完整给出 GenEval 结果。应用 Section 5.3.2 中的方法并提高训练图像分辨率后,我们最大的模型在大多数类别上表现出色,并在总分上超过当前 prompt comprehension state of the art——DALL-E 3 (Betker et al., 2023)。

我们深度为 d=38d=38 的模型,在 PartiPrompts benchmark (Yu et al., 2022) 上针对视觉美学prompt following文字排版生成三类任务进行的人类偏好评估中,优于当前闭源 (Betker et al., 2023; Ideogram, 2024) 与开源 (Sauer et al., 2023; Playground, 2024; Chen et al., 2023; Pernias et al., 2023) 的 SOTA 生成图像模型,见 Figure 7。评估这些类别的人类偏好时,评分者会看到两个模型的成对输出,并回答以下问题:

- Prompt following: 哪幅图像更能体现上方所示文本,并且更忠实地遵循该文本?
- 视觉美学: 在给定 prompt 的情况下,哪幅图像质量更高、在美学上更悦目?
- 文字排版: 哪幅图像能更准确地显示/呈现上方描述中指定的文字?拼写越准确越好!忽略其他方面。

最后,Table 6 突出显示了一项很有意思的结果:更大的模型不仅表现更好,而且达到峰值性能所需的 step 也更少。

Table 5. GenEval 对比。 我们最大的模型(depth=38)在 GenEval (Ghosh et al., 2023) 上超过所有当前开源模型以及 DALL-E 3 (Betker et al., 2023)。原表以粗体、下划线和斜体依次标出最佳、第二佳和第三佳结果。DPO 见 Appendix C。
模型OverallObject: SingleObject: TwoCountingColorsPositionColor Attribution
minDALL-E0.230.730.110.120.370.020.01
SD v1.50.430.970.380.350.760.040.06
PixArt-alpha0.480.980.500.440.800.080.07
SD v2.10.500.980.510.440.85(第二)0.070.17
DALL-E 20.520.940.660.490.770.100.19
SDXL0.550.980.740.390.85(第二)0.150.23
SDXL Turbo0.551.00(最佳)0.720.490.800.100.18
IF-XL0.610.970.740.66(第三)0.810.130.35
DALL-E 30.670.960.87(第二)0.470.83(第三)0.43(最佳)0.45(第三)
Ours (depth=18), 5122512^20.580.970.720.520.780.160.34
Ours (depth=24), 5122512^20.620.980.740.630.670.34(第三)0.36
Ours (depth=30), 5122512^20.640.960.800.650.730.330.37
Ours (depth=38), 5122512^20.68(第三)0.980.840.66(第三)0.740.40(第二)0.43
Ours (depth=38), 5122512^2, w/DPO0.71(第二)0.980.89(第二)0.73(最佳)0.83(第三)0.34(第三)0.47(第二)
Ours (depth=38), 102421024^2, w/DPO0.74(最佳)0.99(第二)0.94(最佳)0.72(第二)0.89(最佳)0.330.60(最佳)
Table 6. 模型规模对采样效率的影响。 下表给出相对于固定 seed、使用 50 个 sampling step 得到的 CLIP score 的相对性能下降。更大的模型可以用更少的 step 采样;我们将其归因于更强的 robustness,以及模型对 Rectified Flow 直线路径目标拟合得更好,从而产生更短的 path length。Path length 的计算方法是在 50 个 step 上对 vθdt\lVert v_\theta\cdot dt\rVert 求和。
模型深度CLIP 相对下降:5/50 steps [%]10/50 steps [%]20/50 steps [%]path length
depth=154.300.860.21191.13
depth=303.590.700.24187.96
depth=382.710.140.08185.96

灵活的 Text Encoder。 使用多个 text encoder 的主要动机,是提升模型整体性能 (Balaji et al., 2022);这里我们进一步说明,这一选择还能提升基于 MM-DiT 的 Rectified Flow 在 inference 时的灵活性。如 Appendix B.3 所述,我们使用三个 text encoder 训练模型,每个 encoder 的独立 dropout rate 为 46.3%。因此,在 inference 时,我们可以任意选择三个 text encoder 的一个子集。这使得我们能够用模型性能换取更高的 memory efficiency;对于拥有 4.7B 参数、需要大量 VRAM 的 T5-XXL (Raffel et al., 2019),这一点尤其重要。

Figure 8原论文图表

Scaling 的定量影响。 我们在保持训练 hyperparameter 一致的条件下,分析模型规模对性能的影响。唯一例外是 depth=38:为防止发散,需要在 3×1053\times10^5 step 时调整 learning rate。上排:对于图像模型(第 1、2 列)和视频模型(第 3、4 列),validation loss 都随着模型规模和 training step 的增加而平滑下降。下排:validation loss 是整体模型性能的强预测指标。Validation loss 与多种整体图像评估指标之间呈显著相关,包括第 1 列的 GenEval (Ghosh et al., 2023)、第 2 列的人类偏好和第 3 列的 T2I-CompBench (Huang et al., 2023)。对于视频模型,我们也观察到 validation loss 与人类偏好之间的类似相关性,见第 4 列。

Figure 9原论文图表

T5 的影响。 我们观察到,对于复杂 prompt——例如包含大量细节或较长待拼写文本的 prompt(第 2、3 行)——T5 很重要。然而,对于大多数 prompt,在 inference 时移除 T5 仍能取得有竞争力的性能。

图内两列标题与 prompt 译文:

- 列标题:全部 text encoder不使用 T5 (Raffel et al., 2019)。
- Prompt 1:“一个汉堡肉饼,带有下层面包、生菜和番茄。上面用芥末写着 ‘COFFEE’。”
- Prompt 2:“一只猴子举着一块牌子,牌子上写着 ‘Scaling transformer models is awesome!’”
- Prompt 3:“一只顽皮的雪貂带着戏谑的笑容,把自己挤进一个大玻璃罐;周围是五颜六色的糖果。罐子放在温馨厨房的一张木桌上,暖阳从附近的窗户洒入。”

有意思的是,只使用两个基于 CLIP 的 text encoder 处理 text prompt,并将 T5 embedding 替换为零时,性能下降有限。Figure 9 给出了定性可视化。只有在复杂 prompt 涉及极为详细的场景描述或大量待写文字时,我们才发现同时使用三个 text encoder 会带来显著的性能增益。Figure 7 的人类偏好评估结果(Ours w/o T5)也验证了这些观察。移除 T5 不影响美学质量评分(win rate 为 50%),对 prompt adherence 只有很小影响(win rate 为 46%),但它对生成书面文字能力的贡献更显著(win rate 为 38%)。

6. 结论

本文对用于 text-to-image synthesis 的 Rectified Flow 模型进行了 scaling analysis。我们为 Rectified Flow 训练提出了一种新的 timestep sampling 方法;对于 latent diffusion model,它优于以往的 diffusion training formulation,同时保留了 Rectified Flow 在 few-step sampling 场景中的有利性质。我们还展示了基于 Transformer 的 MM-DiT 架构的优势,该架构显式考虑了 text-to-image 任务的 multimodal 特性。最后,我们把这一组合扩展到 8B 参数和 5×10225\times10^{22} training FLOPs,并证明 validation loss 的改善既与现有 text-to-image benchmark 相关,也与人类偏好评估相关。凭借这些 generative modeling 改进和可扩展的 multimodal 架构,我们取得了能够与 state-of-the-art 闭源模型竞争的性能。Scaling 趋势没有显示出饱和迹象,这使我们有理由乐观地认为,未来仍能继续提升模型性能。

更广泛影响

本文工作的目标是推动整个 machine learning 领域,尤其是 image synthesis 领域的发展。我们的工作可能产生许多社会影响,但我们认为其中没有哪一项必须在此特别强调。关于 diffusion model 一般性影响的广泛讨论,我们建议感兴趣的读者参阅 (Po et al., 2023)。

参考文献

  1. Ideogram v1.0 announcement, 2024. URL https://about.ideogram.ai/1.0.
  2. Playground v2.5 announcement, 2024. URL https://blog.playgroundai.com/playground-v2-5/.
  3. Albergo, M. S. and Vanden-Eijnden, E. Building normalizing flows with stochastic interpolants, 2022.
  4. Atchison, J. and Shen, S. M. Logistic-normal distributions: Some properties and uses. Biometrika, 67(2):261–272, 1980.
  5. autofaiss. autofaiss, 2023. URL https://github.com/criteo/autofaiss.
  6. Balaji, Y., Nah, S., Huang, X., Vahdat, A., Song, J., Zhang, Q., Kreis, K., Aittala, M., Aila, T., Laine, S., Catanzaro, B., Karras, T., and Liu, M.-Y. ediff-i: Text-to-image diffusion models with an ensemble of expert denoisers, 2022.
  7. Betker, J., Goh, G., Jing, L., Brooks, T., Wang, J., Li, L., Ouyang, L., Zhuang, J., Lee, J., Guo, Y., et al. Improving image generation with better captions. Computer Science. https://cdn. openai. com/papers/dall-e-3. pdf, 2(3), 2023.
  8. Blattmann, A., Dockhorn, T., Kulal, S., Mendelevitch, D., Kilian, M., Lorenz, D., Levi, Y., English, Z., Voleti, V., Letts, A., et al. Stable video diffusion: Scaling latent video diffusion models to large datasets. arXiv preprint arXiv:2311.15127, 2023a.
  9. Blattmann, A., Rombach, R., Ling, H., Dockhorn, T., Kim, S. W., Fidler, S., and Kreis, K. Align your latents: High-resolution video synthesis with latent diffusion models, 2023b.
  10. Brooks, T., Holynski, A., and Efros, A. A. Instructpix2pix: Learning to follow image editing instructions. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 18392–18402, 2023.
  11. Carlini, N., Hayes, J., Nasr, M., Jagielski, M., Sehwag, V., Tramer, F., Balle, B., Ippolito, D., and Wallace, E. Extracting training data from diffusion models. In 32nd USENIX Security Symposium (USENIX Security 23), pp.\ 5253–5270, 2023.
  12. Carreira, J. and Zisserman, A. Quo vadis, action recognition? a new model and the kinetics dataset, 2018.
  13. Changpinyo, S., Sharma, P. K., Ding, N., and Soricut, R. Conceptual 12m: Pushing web-scale image-text pre-training to recognize long-tail visual concepts. 2021 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pp. 3557–3567, 2021. URL https://api.semanticscholar.org/CorpusID:231951742.
  14. Chen, D., Chou, C., Xu, Y., and Hseu, J. Bfloat16: The secret to high performance on cloud tpus, 2019. URL https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus?hl=en.
  15. Chen, J., Yu, J., Ge, C., Yao, L., Xie, E., Wu, Y., Wang, Z., Kwok, J., Luo, P., Lu, H., and Li, Z. Pixart-a: Fast training of diffusion transformer for photorealistic text-to-image synthesis, 2023.
  16. Chen, T. Q., Rubanova, Y., Bettencourt, J., and Duvenaud, D. K. Neural ordinary differential equations. In Neural Information Processing Systems, 2018. URL https://api.semanticscholar.org/CorpusID:49310446.
  17. Cherti, M., Beaumont, R., Wightman, R., Wortsman, M., Ilharco, G., Gordon, C., Schuhmann, C., Schmidt, L., and Jitsev, J. Reproducible scaling laws for contrastive language-image learning. In 2023 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR). IEEE, 2023. 10.1109/cvpr52729.2023.00276. URL http://dx.doi.org/10.1109/CVPR52729.2023.00276.
  18. Dai, X., Hou, J., Ma, C.-Y., Tsai, S., Wang, J., Wang, R., Zhang, P., Vandenhende, S., Wang, X., Dubey, A., Yu, M., Kadian, A., Radenovic, F., Mahajan, D., Li, K., Zhao, Y., Petrovic, V., Singh, M. K., Motwani, S., Wen, Y., Song, Y., Sumbaly, R., Ramanathan, V., He, Z., Vajda, P., and Parikh, D. Emu: Enhancing image generation models using photogenic needles in a haystack, 2023.
  19. Dao, Q., Phung, H., Nguyen, B., and Tran, A. Flow matching in latent space, 2023.
  20. Dehghani, M., Djolonga, J., Mustafa, B., Padlewski, P., Heek, J., Gilmer, J., Steiner, A., Caron, M., Geirhos, R., Alabdulmohsin, I., Jenatton, R., Beyer, L., Tschannen, M., Arnab, A., Wang, X., Riquelme, C., Minderer, M., Puigcerver, J., Evci, U., Kumar, M., van Steenkiste, S., Elsayed, G. F., Mahendran, A., Yu, F., Oliver, A., Huot, F., Bastings, J., Collier, M. P., Gritsenko, A., Birodkar, V., Vasconcelos, C., Tay, Y., Mensink, T., Kolesnikov, A., Pavetić, F., Tran, D., Kipf, T., Lučić, M., Zhai, X., Keysers, D., Harmsen, J., and Houlsby, N. Scaling vision transformers to 22 billion parameters, 2023.
  21. Dhariwal, P. and Nichol, A. Diffusion models beat gans on image synthesis, 2021.
  22. Dockhorn, T., Vahdat, A., and Kreis, K. Score-based generative modeling with critically-damped langevin diffusion. arXiv preprint arXiv:2112.07068, 2021.
  23. Dockhorn, T., Vahdat, A., and Kreis, K. Genie: Higher-order denoising diffusion solvers, 2022.
  24. Dosovitskiy, A., Beyer, L., Kolesnikov, A., Weissenborn, D., Zhai, X., Unterthiner, T., Dehghani, M., Minderer, M., Heigold, G., Gelly, S., et al. An image is worth 16x16 words: Transformers for image recognition at scale. ICLR, 2020.
  25. Esser, P., Chiu, J., Atighehchian, P., Granskog, J., and Germanidis, A. Structure and content-guided video synthesis with diffusion models, 2023.
  26. Euler, L. Institutionum calculi integralis. Number Bd. 1 in Institutionum calculi integralis. imp. Acad. imp. Sa\`ent., 1768. URL https://books.google.de/books?id=Vg8OAAAAQAAJ.
  27. Fischer, J. S., Gui, M., Ma, P., Stracke, N., Baumann, S. A., and Ommer, B. Boosting latent diffusion with flow matching. arXiv preprint arXiv:2312.07360, 2023.
  28. Ghosh, D., Hajishirzi, H., and Schmidt, L. Geneval: An object-focused framework for evaluating text-to-image alignment. arXiv preprint arXiv:2310.11513, 2023.
  29. Gupta, A., Yu, L., Sohn, K., Gu, X., Hahn, M., Fei-Fei, L., Essa, I., Jiang, L., and Lezama, J. Photorealistic video generation with diffusion models, 2023.
  30. Hessel, J., Holtzman, A., Forbes, M., Le Bras, R., and Choi, Y. Clipscore: A reference-free evaluation metric for image captioning. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing. Association for Computational Linguistics, 2021. 10.18653/v1/2021.emnlp-main.595. URL http://dx.doi.org/10.18653/v1/2021.emnlp-main.595.
  31. Heusel, M., Ramsauer, H., Unterthiner, T., Nessler, B., and Hochreiter, S. Gans trained by a two time-scale update rule converge to a local nash equilibrium, 2017.
  32. Ho, J. and Salimans, T. Classifier-free diffusion guidance, 2022.
  33. Ho, J., Jain, A., and Abbeel, P. Denoising diffusion probabilistic models, 2020.
  34. Ho, J., Chan, W., Saharia, C., Whang, J., Gao, R., Gritsenko, A., Kingma, D. P., Poole, B., Norouzi, M., Fleet, D. J., and Salimans, T. Imagen video: High definition video generation with diffusion models, 2022.
  35. Hoogeboom, E., Heek, J., and Salimans, T. Simple diffusion: End-to-end diffusion for high resolution images, 2023.
  36. Huang, K., Sun, K., Xie, E., Li, Z., and Liu, X. T2i-compbench: A comprehensive benchmark for open-world compositional text-to-image generation. arXiv preprint arXiv:2307.06350, 2023.
  37. Hyv\"arinen, A. Estimation of non-normalized statistical models by score matching. J. Mach. Learn. Res., 6:695–709, 2005. URL https://api.semanticscholar.org/CorpusID:1152227.
  38. Kaplan, J., McCandlish, S., Henighan, T., Brown, T. B., Chess, B., Child, R., Gray, S., Radford, A., Wu, J., and Amodei, D. Scaling laws for neural language models, 2020.
  39. Karras, T., Aittala, M., Aila, T., and Laine, S. Elucidating the design space of diffusion-based generative models. ArXiv, abs/2206.00364, 2022. URL https://api.semanticscholar.org/CorpusID:249240415.
  40. Karras, T., Aittala, M., Lehtinen, J., Hellsten, J., Aila, T., and Laine, S. Analyzing and improving the training dynamics of diffusion models. arXiv preprint arXiv:2312.02696, 2023.
  41. Kingma, D. P. and Gao, R. Understanding diffusion objectives as the elbo with simple data augmentation. In Thirty-seventh Conference on Neural Information Processing Systems, 2023.
  42. Lee, K., Ippolito, D., Nystrom, A., Zhang, C., Eck, D., Callison-Burch, C., and Carlini, N. Deduplicating training data makes language models better. arXiv preprint arXiv:2107.06499, 2021.
  43. Lee, S., Kim, B., and Ye, J. C. Minimizing trajectory curvature of ode-based generative models, 2023.
  44. Lin, S., Liu, B., Li, J., and Yang, X. Common diffusion noise schedules and sample steps are flawed. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision, pp. 5404–5411, 2024.
  45. Lin, T.-Y., Maire, M., Belongie, S., Hays, J., Perona, P., Ramanan, D., Dollár, P., and Zitnick, C. L. Microsoft COCO: Common Objects in Context, pp. 740–755. Springer International Publishing, 2014. ISBN 9783319106021. 10.1007/978-3-319-10602-1_48. URL http://dx.doi.org/10.1007/978-3-319-10602-1_48.
  46. Lipman, Y., Chen, R. T. Q., Ben-Hamu, H., Nickel, M., and Le, M. Flow matching for generative modeling. In The Eleventh International Conference on Learning Representations, 2023. URL https://openreview.net/forum?id=PqvMRDCJT9t.
  47. Liu, X., Gong, C., and Liu, Q. Flow straight and fast: Learning to generate and transfer data with rectified flow, 2022.
  48. Liu, X., Zhang, X., Ma, J., Peng, J., and Liu, Q. Instaflow: One step is enough for high-quality diffusion-based text-to-image generation, 2023.
  49. Loshchilov, I. and Hutter, F. Fixing weight decay regularization in adam. ArXiv, abs/1711.05101, 2017. URL https://api.semanticscholar.org/CorpusID:3312944.
  50. Lu, C., Zhou, Y., Bao, F., Chen, J., Li, C., and Zhu, J. Dpm-solver++: Fast solver for guided sampling of diffusion probabilistic models, 2023.
  51. Ma, N., Goldstein, M., Albergo, M. S., Boffi, N. M., Vanden-Eijnden, E., and Xie, S. Sit: Exploring flow and diffusion-based generative models with scalable interpolant transformers, 2024.
  52. Nichol, A. Dall-e 2 pre-training mitigations. https://openai.com/research/dall-e-2-pre-training-mitigations, 2022.
  53. Nichol, A. and Dhariwal, P. Improved denoising diffusion probabilistic models, 2021.
  54. NovelAI. Novelai improvements on stable diffusion, 2022. URL https://blog.novelai.net/novelai-improvements-on-stable-diffusion-e10d38db82ac.
  55. Peebles, W. and Xie, S. Scalable diffusion models with transformers. In 2023 IEEE/CVF International Conference on Computer Vision (ICCV). IEEE, 2023. 10.1109/iccv51070.2023.00387. URL http://dx.doi.org/10.1109/ICCV51070.2023.00387.
  56. Pernias, P., Rampas, D., Richter, M. L., Pal, C. J., and Aubreville, M. Wuerstchen: An efficient architecture for large-scale text-to-image diffusion models, 2023.
  57. Pizzi, E., Roy, S. D., Ravindra, S. N., Goyal, P., and Douze, M. A self-supervised descriptor for image copy detection. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 14532–14542, 2022.
  58. Po, R., Yifan, W., Golyanik, V., Aberman, K., Barron, J. T., Bermano, A. H., Chan, E. R., Dekel, T., Holynski, A., Kanazawa, A., et al. State of the art on diffusion models for visual computing. arXiv preprint arXiv:2310.07204, 2023.
  59. Podell, D., English, Z., Lacey, K., Blattmann, A., Dockhorn, T., Müller, J., Penna, J., and Rombach, R. Sdxl: Improving latent diffusion models for high-resolution image synthesis, 2023.
  60. Pooladian, A.-A., Ben-Hamu, H., Domingo-Enrich, C., Amos, B., Lipman, Y., and Chen, R. T. Q. Multisample flow matching: Straightening flows with minibatch couplings, 2023.
  61. Radford, A., Kim, J. W., Hallacy, C., Ramesh, A., Goh, G., Agarwal, S., Sastry, G., Askell, A., Mishkin, P., Clark, J., Krueger, G., and Sutskever, I. Learning transferable visual models from natural language supervision, 2021.
  62. Rafailov, R., Sharma, A., Mitchell, E., Ermon, S., Manning, C. D., and Finn, C. Direct Preference Optimization: Your Language Model is Secretly a Reward Model. arXiv:2305.18290, 2023.
  63. Raffel, C., Shazeer, N., Roberts, A., Lee, K., Narang, S., Matena, M., Zhou, Y., Li, W., and Liu, P. J. Exploring the limits of transfer learning with a unified text-to-text transformer, 2019.
  64. Ramesh, A., Dhariwal, P., Nichol, A., Chu, C., and Chen, M. Hierarchical text-conditional image generation with clip latents, 2022.
  65. Rombach, R., Blattmann, A., Lorenz, D., Esser, P., and Ommer, B. High-resolution image synthesis with latent diffusion models. In 2022 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR). IEEE, 2022. 10.1109/cvpr52688.2022.01042. URL http://dx.doi.org/10.1109/CVPR52688.2022.01042.
  66. Ronneberger, O., Fischer, P., and Brox, T. U-Net: Convolutional Networks for Biomedical Image Segmentation, pp. 234–241. Springer International Publishing, 2015. ISBN 9783319245744. 10.1007/978-3-319-24574-4_28. URL http://dx.doi.org/10.1007/978-3-319-24574-4_28.
  67. Russakovsky, O., Deng, J., Su, H., Krause, J., Satheesh, S., Ma, S., Huang, Z., Karpathy, A., Khosla, A., Bernstein, M. S., Berg, A. C., and Fei-Fei, L. Imagenet large scale visual recognition challenge. International Journal of Computer Vision, 115:211 – 252, 2014. URL https://api.semanticscholar.org/CorpusID:2930547.
  68. Saharia, C., Chan, W., Chang, H., Lee, C., Ho, J., Salimans, T., Fleet, D., and Norouzi, M. Palette: Image-to-image diffusion models. In ACM SIGGRAPH 2022 Conference Proceedings, pp. 1–10, 2022a.
  69. Saharia, C., Chan, W., Saxena, S., Li, L., Whang, J., Denton, E., Ghasemipour, S. K. S., Ayan, B. K., Mahdavi, S. S., Lopes, R. G., Salimans, T., Ho, J., Fleet, D. J., and Norouzi, M. Photorealistic text-to-image diffusion models with deep language understanding, 2022b.
  70. Saharia, C., Ho, J., Chan, W., Salimans, T., Fleet, D. J., and Norouzi, M. Image super-resolution via iterative refinement. IEEE Transactions on Pattern Analysis and Machine Intelligence, 45(4):4713–4726, 2022c.
  71. Sauer, A., Chitta, K., M\"uller, J., and Geiger, A. Projected gans converge faster. Advances in Neural Information Processing Systems, 2021.
  72. Sauer, A., Lorenz, D., Blattmann, A., and Rombach, R. Adversarial diffusion distillation. arXiv preprint arXiv:2311.17042, 2023.
  73. Sheynin, S., Polyak, A., Singer, U., Kirstain, Y., Zohar, A., Ashual, O., Parikh, D., and Taigman, Y. Emu edit: Precise image editing via recognition and generation tasks. arXiv preprint arXiv:2311.10089, 2023.
  74. Singer, U., Polyak, A., Hayes, T., Yin, X., An, J., Zhang, S., Hu, Q., Yang, H., Ashual, O., Gafni, O., Parikh, D., Gupta, S., and Taigman, Y. Make-a-video: Text-to-video generation without text-video data, 2022.
  75. Sohl-Dickstein, J. N., Weiss, E. A., Maheswaranathan, N., and Ganguli, S. Deep unsupervised learning using nonequilibrium thermodynamics. ArXiv, abs/1503.03585, 2015. URL https://api.semanticscholar.org/CorpusID:14888175.
  76. Somepalli, G., Singla, V., Goldblum, M., Geiping, J., and Goldstein, T. Diffusion art or digital forgery? investigating data replication in diffusion models. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 6048–6058, 2023a.
  77. Somepalli, G., Singla, V., Goldblum, M., Geiping, J., and Goldstein, T. Understanding and mitigating copying in diffusion models. arXiv preprint arXiv:2305.20086, 2023b.
  78. Song, J., Meng, C., and Ermon, S. Denoising diffusion implicit models, 2022.
  79. Song, Y. and Ermon, S. Generative modeling by estimating gradients of the data distribution, 2020.
  80. Song, Y., Sohl-Dickstein, J. N., Kingma, D. P., Kumar, A., Ermon, S., and Poole, B. Score-based generative modeling through stochastic differential equations. ArXiv, abs/2011.13456, 2020. URL https://api.semanticscholar.org/CorpusID:227209335.
  81. Tong, A., Malkin, N., Huguet, G., Zhang, Y., Rector-Brooks, J., Fatras, K., Wolf, G., and Bengio, Y. Improving and generalizing flow-based generative models with minibatch optimal transport, 2023.
  82. Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, L., and Polosukhin, I. Attention is all you need, 2017.
  83. Villani, C. Optimal transport: Old and new. 2008. URL https://api.semanticscholar.org/CorpusID:118347220.
  84. Vincent, P. A connection between score matching and denoising autoencoders. Neural Computation, 23:1661–1674, 2011. URL https://api.semanticscholar.org/CorpusID:5560643.
  85. Wallace, B., Dang, M., Rafailov, R., Zhou, L., Lou, A., Purushwalkam, S., Ermon, S., Xiong, C., Joty, S., and Naik, N. Diffusion Model Alignment Using Direct Preference Optimization. arXiv:2311.12908, 2023.
  86. Wang, W., Lv, Q., Yu, W., Hong, W., Qi, J., Wang, Y., Ji, J., Yang, Z., Zhao, L., Song, X., et al. Cogvlm: Visual expert for pretrained language models. arXiv preprint arXiv:2311.03079, 2023.
  87. Wortsman, M., Liu, P. J., Xiao, L., Everett, K., Alemi, A., Adlam, B., Co-Reyes, J. D., Gur, I., Kumar, A., Novak, R., Pennington, J., Sohl-dickstein, J., Xu, K., Lee, J., Gilmer, J., and Kornblith, S. Small-scale proxies for large-scale transformer training instabilities, 2023.
  88. Yu, J., Xu, Y., Koh, J. Y., Luong, T., Baid, G., Wang, Z., Vasudevan, V., Ku, A., Yang, Y., Ayan, B. K., et al. Scaling Autoregressive Models for Content-Rich Text-to-Image Generation. arXiv:2206.10789, 2022.
  89. Zhai, X., Kolesnikov, A., Houlsby, N., and Beyer, L. Scaling vision transformers. In CVPR, pp. 12104–12113, 2022.
  90. Zhang, B. and Sennrich, R. Root mean square layer normalization, 2019.

补充材料

A. 背景

Diffusion Models。 Diffusion Models(Sohl-Dickstein et al., 2015;Song et al., 2020;Ho et al., 2020)通过逼近某个随机前向过程的逆 ODE 来生成数据;该前向过程会把数据逐渐变成噪声。它们已经成为图像(Dhariwal & Nichol, 2021;Ramesh et al., 2022;Saharia et al., 2022b;Rombach et al., 2022;Balaji et al., 2022)与视频(Singer et al., 2022;Ho et al., 2022;Esser et al., 2023;Blattmann et al., 2023b;Gupta et al., 2023)生成建模的标准方法。由于这些模型既可以从负对数似然的变分下界(Sohl-Dickstein et al., 2015)推导,也可以从 score matching(Hyvärinen, 2005;Vincent, 2011;Song & Ermon, 2020)推导,因此,前向与逆向过程的不同表述(Song et al., 2020;Dockhorn et al., 2021)、不同模型参数化(Ho et al., 2020;Ho & Salimans, 2022;Karras et al., 2022)、不同 loss weighting(Ho et al., 2020;Karras et al., 2022)以及不同 ODE solver(Song et al., 2022;Lu et al., 2023;Dockhorn et al., 2022),共同产生了大量不同的训练目标与采样流程。近期,Kingma & Gao(2023)和 Karras et al.(2022)的奠基性工作提出了统一表述,并为训练(Karras et al., 2022;Kingma & Gao, 2023)与推理(Karras et al., 2022)引入了新的理论与实践洞见。然而,即使经过这些改进,常见 ODE 的轨迹仍可能包含相当显著的曲率(Karras et al., 2022;Liu et al., 2022),这要求更多 solver steps,因而使快速推理变得困难。为解决这一问题,我们采用 Rectified Flow 模型,其表述允许学习笔直的 ODE 轨迹。

Rectified Flow Models。 Liu et al.(2022)、Albergo & Vanden-Eijnden(2022)以及 Lipman et al.(2023)通过 ordinary differential equation(ODE)在两个分布之间构造 transport map,以此实现生成建模。该方法与 continuous normalizing flow(CNF;Chen et al., 2018)以及 Diffusion Models 都有紧密联系。相较于 CNF,Rectified Flow 和 Stochastic Interpolant 的优势在于训练期间无须模拟 ODE。相较于 Diffusion Models,它们所得 ODE 的模拟速度可以快于与 Diffusion Models 相关的 probability flow ODE(Song et al., 2020)。不过,它们并不会直接得到 optimal transport 解,已有多项工作试图进一步降低轨迹曲率(Lee et al., 2023;Tong et al., 2023;Pooladian et al., 2023)。Dao et al.(2023)与 Ma et al.(2024)证明了 Rectified Flow 表述用于 class-conditional 图像合成的可行性;Fischer et al.(2023)将其用于 latent-space 上采样;Liu et al.(2023)则把 Liu et al.(2022)的 reflow 流程用于蒸馏预训练 text-to-image 模型(Rombach et al., 2022)。本文关注的是:将 Rectified Flow 作为一种只需较少采样步数的 text-to-image 合成基础。我们广泛比较了不同表述与 loss weighting,并提出一种性能更好的新 timestep schedule 来训练 Rectified Flow。

Scaling Diffusion Models。 Transformer 架构(Vaswani et al., 2017)在 NLP(Kaplan et al., 2020)和计算机视觉任务(Dosovitskiy et al., 2020;Zhai et al., 2022)中的 scaling 性质早已广为人知。对于 Diffusion Models,U-Net 架构(Ronneberger et al., 2015)一直占据主导地位(Ho et al., 2020;Rombach et al., 2022;Balaji et al., 2022)。尽管近期已有一些工作探索 diffusion Transformer backbone(Peebles & Xie, 2023;Chen et al., 2023;Ma et al., 2024),text-to-image Diffusion Models 的 scaling laws 仍未得到研究。

PDF PAGE 18原论文图表

第 18 页无编号样例图版,按页面从左到右、从上到下列出全部 12 个 prompt:

1. “一幅细致的钢笔墨线画:一位快乐的猪屠夫正在自己的店里卖肉。”
2. “一艘形状像椒盐卷饼的巨型外星飞船。”
3. “一只手拿啤酒、戴着滑雪护目镜、正在热情演唱滑稽歌曲的袋鼠。”
4. “整个宇宙装在一个瓶子里;瓶子放在 Walmart 的货架上,正在促销。”
5. “一个芝士汉堡在夜间的 vibe wave 上冲浪。”
6. “Johannes Vermeer 笔下戴珍珠耳环的沼泽食人魔。”
7. “一辆由蔬菜制成的汽车。”
8. “宇宙热寂,线稿风格。”
9. “盘子里有一只由奶酪制成的螃蟹。”
10. “反乌托邦场景:成千上万的工人采摘樱桃,并把它们送入一台以蒸汽驱动、如摩天大楼般巨大的机器;机器侧面写着 ‘SD3 Paper’。”
11. “一只半透明的猪,里面还有一只更小的猪。”
12. “电影剧照:一个腿很长、长着可爱大眼睛、拟人化的芝士汉堡穿着运动鞋,在一间装饰稀疏的客厅沙发上放松。”

PDF PAGE 19原论文图表

第 19 页无编号样例图版,按页面从左到右、从上到下列出全部 8 个 prompt:

1. “一幅细致的钢笔墨线画:一艘庞大而复杂的外星飞船,悬在荒郊一座农场上空。”
2. “一张照片:一只穿西装、戴礼帽的熊站在森林中央的河里,手持标牌,上面写着 ‘I cant bear it’。”
3. “傍晚,一座由寿司构成的可爱城市坐落在木桌上;移轴航拍照片。”
4. “高反差暗色渲染:一棵迷幻的生命之树照亮神秘洞穴中的尘埃。”
5. “一个拟人化的分形人物,站在一家分形主题餐厅的柜台后面。”
6. “一幅美丽的油画:下午,一艘蒸汽船行驶在河上;河岸有一栋大型砖砌建筑,楼顶标牌写着 ‘SD3’。”
7. “一个拟人化的粉红甜甜圈,留着胡子、戴牛仔帽,站在森林中的一座原木小屋旁;车道上停着一辆 1970 年代的老式橙色卡车。”
8. “夜晚,一只狐狸坐在凌乱房间里的电脑前;屏幕上是一个 3D 建模程序,显示着斑马的线框渲染图。”

B. 关于 Flow Matching

B.1 Flow 的免仿真训练细节

沿用 Lipman et al.(2023)的论证。为了说明 ut(z)u_t(z) 会生成 ptp_t,我们注意到 continuity equation 给出了如下充要条件(Villani, 2008):

ddtpt(x)+[pt(x)vt(x)]=0vt 生成概率密度路径 pt.(26)\frac{\mathrm{d}}{\mathrm{d}t}p_t(x)+\nabla\cdot\left[p_t(x)v_t(x)\right]=0 \quad\Longleftrightarrow\quad v_t\ \text{生成概率密度路径}\ p_t. \tag{26}

因此,只需证明:

[ut(z)pt(z)]=[EϵN(0,I)ut(zϵ)pt(zϵ)pt(z)pt(z)].(27)-\nabla\cdot\left[u_t(z)p_t(z)\right] =-\nabla\cdot\left[ \mathbb{E}_{\epsilon\sim\mathcal{N}(0,I)} u_t(z\mid\epsilon)\frac{p_t(z\mid\epsilon)}{p_t(z)}p_t(z) \right]. \tag{27}
=EϵN(0,I)[(ut(zϵ)pt(zϵ))].(28)=\mathbb{E}_{\epsilon\sim\mathcal{N}(0,I)} \left[-\nabla\cdot\left(u_t(z\mid\epsilon)p_t(z\mid\epsilon)\right)\right]. \tag{28}
=EϵN(0,I)ddtpt(zϵ)=ddtpt(z).(29)=\mathbb{E}_{\epsilon\sim\mathcal{N}(0,I)} \frac{\mathrm{d}}{\mathrm{d}t}p_t(z\mid\epsilon) =\frac{\mathrm{d}}{\mathrm{d}t}p_t(z). \tag{29}

在从式 (28) 到式 (29) 的过程中,我们对 ut(zϵ)u_t(z\mid\epsilon) 使用了式 (26) 的 continuity equation,因为 ut(zϵ)u_t(z\mid\epsilon) 会生成 pt(zϵ)p_t(z\mid\epsilon);在式 (27) 中,我们使用了式 (6) 的定义。

目标函数 LFMLCFM\mathcal{L}_{\mathrm{FM}}\leftrightharpoons\mathcal{L}_{\mathrm{CFM}} 的等价性(Lipman et al., 2023)可由下式得到:

LFM(Θ)=Et,pt(z)vΘ(z,t)ut(z)22.(30)\mathcal{L}_{\mathrm{FM}}(\Theta) =\mathbb{E}_{t,p_t(z)}\left\|v_\Theta(z,t)-u_t(z)\right\|_2^2. \tag{30}
=Et,pt(z)vΘ(z,t)222Et,pt(z)vΘ(z,t)ut(z)+c.(31)=\mathbb{E}_{t,p_t(z)}\left\|v_\Theta(z,t)\right\|_2^2 -2\mathbb{E}_{t,p_t(z)}\left\langle v_\Theta(z,t)\mid u_t(z)\right\rangle+c. \tag{31}
=Et,pt(z)vΘ(z,t)222Et,pt(zϵ),p(ϵ)vΘ(z,t)ut(zϵ)+c.(32)=\mathbb{E}_{t,p_t(z)}\left\|v_\Theta(z,t)\right\|_2^2 -2\mathbb{E}_{t,p_t(z\mid\epsilon),p(\epsilon)} \left\langle v_\Theta(z,t)\mid u_t(z\mid\epsilon)\right\rangle+c. \tag{32}
=Et,pt(zϵ),p(ϵ)vΘ(z,t)ut(zϵ)22+c=LCFM(Θ)+c.(33)=\mathbb{E}_{t,p_t(z\mid\epsilon),p(\epsilon)} \left\|v_\Theta(z,t)-u_t(z\mid\epsilon)\right\|_2^2+c' =\mathcal{L}_{\mathrm{CFM}}(\Theta)+c'. \tag{33}

其中 cccc' 都不依赖于 Θ\Theta;从式 (31) 到式 (32) 的关系来自:

Ept(zϵ),p(ϵ)vΘ(z,t)ut(zϵ)= ⁣dz ⁣dϵpt(zϵ)p(ϵ)vΘ(z,t)ut(zϵ).(34)\begin{aligned} &\mathbb{E}_{p_t(z\mid\epsilon),p(\epsilon)} \left\langle v_\Theta(z,t)\mid u_t(z\mid\epsilon)\right\rangle\\ &\qquad=\int\!\mathrm{d}z\int\!\mathrm{d}\epsilon\, p_t(z\mid\epsilon)p(\epsilon) \left\langle v_\Theta(z,t)\mid u_t(z\mid\epsilon)\right\rangle. \end{aligned} \tag{34}
= ⁣dzpt(z)vΘ(z,t)| ⁣dϵpt(zϵ)pt(z)p(ϵ)ut(zϵ).(35)=\int\!\mathrm{d}z\,p_t(z) \left\langle v_\Theta(z,t)\,\middle|\, \int\!\mathrm{d}\epsilon\, \frac{p_t(z\mid\epsilon)}{p_t(z)}p(\epsilon)u_t(z\mid\epsilon) \right\rangle. \tag{35}
= ⁣dzpt(z)vΘ(z,t)ut(z)=Ept(z)vΘ(z,t)ut(z).(36)=\int\!\mathrm{d}z\,p_t(z) \left\langle v_\Theta(z,t)\mid u_t(z)\right\rangle =\mathbb{E}_{p_t(z)} \left\langle v_\Theta(z,t)\mid u_t(z)\right\rangle. \tag{36}

在式 (35) 中,我们乘上了 pt(z)/pt(z)p_t(z)/p_t(z);从式 (35) 到式 (36) 则使用了式 (6) 的定义。

B.2 图像与文本表示的细节

Latent 图像表示。 我们沿用 LDM(Rombach et al., 2022),使用 pretrained autoencoder,把 RGB 图像 XRH×W×3X\in\mathbb{R}^{H\times W\times3} 表示到更小的 latent space 中:x=E(X)Rh×w×dx=E(X)\in\mathbb{R}^{h\times w\times d}。我们使用 88 倍空间下采样,因此 h=H/8h=H/8w=W/8w=W/8,并在第 5.2.1 节实验不同的 dd。我们始终在 latent space 中应用式 (2) 的前向过程;当通过式 (1) 采样得到表示 xx 时,再使用 decoder DD 将其解码回 pixel space:X=D(x)X=D(x)。按照 Rombach et al.(2022),我们用 latent 的均值和标准差对其归一化;这些统计量在训练数据的一个子集上全局计算得到。Figure 10 展示了不同 dd 下的 Generative Model 训练如何随模型容量变化,相关讨论见第 5.2.1 节。

文本表示。 类似于把图像编码成 latent 表示,我们也沿用既有方法(Saharia et al., 2022b;Balaji et al., 2022),使用预训练且冻结的文本模型编码文本条件 cc。具体来说,所有实验都使用 CLIP 模型(Radford et al., 2021)与一个 encoder-decoder 文本模型的组合。我们分别用 Radford et al.(2021)的 CLIP L/14 和 Cherti et al.(2023)的 OpenCLIP bigG/14 的 text encoder 编码 cc。把二者维度分别为 76876812801280 的 pooled outputs 拼接起来,得到 vector conditioning cvecR2048c_{\text{vec}}\in\mathbb{R}^{2048}。我们还沿 channel 维拼接倒数第二层的 hidden representations,得到 CLIP context conditioning cctxtCLIPR77×2048c_{\text{ctxt}}^{\text{CLIP}}\in\mathbb{R}^{77\times2048}。接着,我们还用 T5-v1.1-XXL 模型(Raffel et al., 2019)的 encoder 编码 cc,取其最终 hidden representation:cctxtT5R77×4096c_{\text{ctxt}}^{\text{T5}}\in\mathbb{R}^{77\times4096}。最后,沿 channel 轴把 cctxtCLIPc_{\text{ctxt}}^{\text{CLIP}} 用零填充到 40964096 维,以匹配 T5 表示,再沿 sequence 轴与 cctxtT5c_{\text{ctxt}}^{\text{T5}} 拼接,得到最终 context representation cctxtR154×4096c_{\text{ctxt}}\in\mathbb{R}^{154\times4096}。这两种 caption 表示 cvecc_{\text{vec}}cctxtc_{\text{ctxt}} 的使用方式不同,详见第 4 节。

Figure 10原论文图表

在不同 autoencoder 的 latent space(4、8、16 个 latent channels)上,以不同规模的 flow models(用深度参数化)完成训练后的 FID 分数,见第 5.2.1 节。正如预期,在 16-channel autoencoder 空间上训练的 flow model 需要更大的模型容量才能达到相近性能。当深度 d=22d=22 时,8-channel 与 16-channel 的差距已可忽略。由于我们的最终目标是扩展到大得多的模型规模,因此选择 16-channel 模型。

B.3 第 5.1 节实验的预备设置

Datasets。 由于缺少标准的 text-to-image benchmark,我们使用两个 datasets。ImageNet(Russakovsky et al., 2014)被广泛使用;我们为其中图像添加形如 “a photo of a <class name>” 的 caption,把它转成适用于 text-to-image 模型的数据集,其中 <class name> 从该图像 class label 所提供的名称中随机选择。作为更贴近真实 text-to-image 场景的数据集,我们使用 CC12M(Changpinyo et al., 2021)训练。

Optimization。 在该实验中,所有模型均使用 global batch size 10241024,采用 AdamW optimizer(Loshchilov & Hutter, 2017),learning rate 为 10410^{-4},并进行 10001000 个 linear warmup steps。我们使用 mixed-precision training,并保留一份模型权重副本;每经过 100100 个 training batches,就以 decay factor 0.990.99 的 exponential moving average(EMA)更新这份副本。对于 unconditional diffusion guidance(Ho & Salimans, 2022),我们分别以 46.4%46.4\% 的概率把三个 text encoders 中每一个的输出置零,使所有训练 steps 中约有 10%10\% 在训练 unconditional model。

Evaluation。 如第 5.1 节所述,我们使用 CLIP scores、FID 与 validation losses,在 COCO-2014 validation split(Lin et al., 2014)上定期评估模型。由于不同 timesteps 的 loss 值在量级与方差上差异很大,我们在时间区间 [0,1][0,1] 上取八个等间距的值进行分层评估。

为了分析不同方法在不同 sampler settings 下的表现,我们为每个 sampler 生成 10001000 个样本;各 sampler 的 guidance scale 与 sampling steps 数量不同。我们使用 CLIP L/14(Radford et al., 2021)计算这些样本的 CLIP scores,并计算这些样本与 validation set 图像之间、基于 CLIP L/14 image features 的 FID。采样时,我们始终使用式 (1) 的 Euler discretization(Euler, 1768),共使用六种设置:5050 steps,classifier-free-guidance scales 分别为 1.01.02.52.55.05.0;以及 5510102525 steps,classifier-free-guidance scale 固定为 5.05.0

B.4 改进 Rectified Flow 模型的 SNR Samplers

如第 2 节所述,我们为训练 Rectified Flow 模型所用的 timesteps 引入新的密度 π(t)\pi(t)。Figure 11 可视化了第 3.1 节提出的 logit-normal samplermode sampler 的分布。值得注意的是,如第 5.1 节所示,logit-normal sampler 优于经典的均匀 Rectified Flow 表述(Liu et al., 2022),也优于 EDM(Karras et al., 2022)与 LDM-Linear(Rombach et al., 2022)等已有 diffusion baselines。

Figure 11原论文图表

为使训练 timesteps 的采样产生偏置,我们所探索的 mode 分布(左)与 logit-normal 分布(右)。

图中四个 PartiPrompts,按从左到右的顺序:

1. “一只穿着正装、戴礼帽、手持拐杖的浣熊。浣熊拿着一个垃圾袋。抽象立体主义风格的油画。”
2. “一碗看起来像由橡皮泥做成的怪物的汤。”
3. “两杯咖啡,其中一杯的 latte art 是心形;另一杯的 latte art 是星星。”
4. “一只微笑的树懒穿着皮夹克、戴牛仔帽、穿苏格兰短裙并系蝴蝶结。树懒拿着一根 quarterstaff 和一本大书。它站在草地上,前方几英尺处是一辆画满鲜花、闪闪发亮的大众面包车。使用从下方向上拍摄的广角镜头。”

Figure 12原论文图表

Scaling 的定性效果。 这些示例展示了增加 training steps(从左到右:50k50\text{k}200k200\text{k}350k350\text{k}500k500\text{k})和增大模型规模(从上到下:depth=15,30,38\mathrm{depth}=15,30,38)对 PartiPrompts 结果的影响,突出训练时长与模型复杂度的作用。

C. Direct Preference Optimization

列标题 prompt 保留原文,并可附中文:

- “a peaceful lakeside landscape with migrating herd of sauropods”(宁静的湖畔景观,一群迁徙的蜥脚类恐龙)
- “a book with the words ‘Don't Panic!’, written on it”(一本封面写着 “Don't Panic!” 的书)

行标签:2B base2B w/ DPO8B base8B w/ DPO

Figure 13原论文图表

Base models 与 DPO-finetuned models 的对比。DPO finetuning 通常会得到审美上更讨喜、拼写也更准确的样本。

Direct Preference Optimization(DPO;Rafailov et al., 2023)是一种使用偏好数据对 LLM 进行 finetune 的技术。最近,该方法已被改造用于 text-to-image Diffusion Models 的偏好 finetuning(Wallace et al., 2023)。本节验证我们的模型同样适用于 preference optimization。具体来说,我们把 Wallace et al.(2023)提出的方法应用到参数量为 2B 和 8B 的 base model。按照常见做法,我们并不 finetune 整个模型,而是为所有 linear layers 引入可学习的 Low-Rank Adaptation(LoRA)矩阵,其 rank 为 128128。对于 2B 和 8B base model,我们分别对这些新增参数 finetune 4k4\text{k}2k2\text{k} iterations。随后,我们从 PartiPrompts 集合(Yu et al., 2022)中选取 128128 条 captions 的子集进行 human preference study,每个 prompt 与 comparison 大约由三名投票者评估。Figure 14 表明,base models 可以有效地针对 human preference 调整;Figure 13 则给出了各 base model 与 DPO-finetuned model 的样本。

D. 针对 instruction-based image editing 的 Finetuning

训练 instruction-based image editing 与一般 image-to-image Diffusion Models 的常见做法是:在将输入送入 U-Net 之前,沿 channel 维把输入图像的 latents 与 diffusion target 的 noised latents 拼接起来(Brooks et al., 2023;Sheynin et al., 2023;Saharia et al., 2022a,c)。我们采用同样的方法,在 patching 之前沿 channels 拼接输入与 target,并证明该方法同样适用于本文提出的架构。我们在一个由多种 image-to-image editing tasks 构成的数据集上 finetune 2B base model:其中既包含分布类似 InstructPix2Pix dataset(Brooks et al., 2023)的任务,也包含类似 Emu Edit 与 Palette(Sheynin et al., 2023;Saharia et al., 2022a)的 inpainting、segmentation、colorization、deblurring 和 ControlNet tasks。如 Figure 15 所示,所得 2B Edit model 能够操纵给定图像中的文字,尽管训练数据并未包含任何文字操纵任务。我们在相同数据上训练基于 SDXL(Podell et al., 2023)的 editing model 时,未能复现类似结果。

Figure 14原论文图表

Base models 与 DPO-finetuned models 之间的 human preference evaluation。无论是 prompt following 还是整体质量,人类评估者都更偏好 DPO-finetuned models。

E. 大规模 Text-to-Image 训练的 Data Preprocessing

E.1 预计算图像与文本 Embeddings

我们的模型把多个预训练且冻结的网络输出作为输入,包括 autoencoder latents 与 text encoder representations。由于这些输出在训练过程中保持不变,我们对整个 dataset 只预计算一次。这样做有两个主要优点:其一,训练时无须把 encoders 放在 GPU 上,从而降低显存需求;其二,训练时可以跳过前向编码过程,因此从第一个 epoch 之后开始能够节省时间与总计算量,见 Table 7。

Table 7. 冻结输入网络预编码的关键数据。 Mem 表示把模型加载到 GPU 所需的显存;FP [ms] 表示 per-device batch size 为 3232 时,每个样本前向传播所需的时间;Storage 表示保存单个样本所需的空间;Delta [%] 表示把该网络加入 2B MMDiT 模型的训练 loop 后,一个 training step 增加的时长比例(基线为 568ms/it568\,\mathrm{ms/it})。
ModelMem [GB]FP [ms]Storage [kB]Delta [%]
VAE (Enc)0.142.4565.513.8
CLIP-L0.490.45121.32.6
CLIP-G2.782.77202.215.6
T519.0517.46630.798.3

这种方法也有两个缺点。第一,无法在每个 epoch 中为每个样本执行随机 augmentation;因此,在预计算 image latents 时,我们使用正方形 center crop。为了在更 high-resolution 上 finetune 模型,我们预先指定若干 aspect-ratio buckets,先把图像 resize 并 crop 到最接近的 bucket,再按该 aspect ratio 预计算。第二,text encoders 的 dense output 尤其庞大,会带来额外存储成本与更长的训练加载时间(参见 Table 7)。我们以 half precision 保存语言模型的 embeddings;实践中并未观察到性能下降。

E.2 防止 image memorization

在生成图像模型的语境下,对训练样本的 memorization 会引发多种问题(Somepalli et al., 2023a;Carlini et al., 2023;Somepalli et al., 2023b)。为避免训练出的模型逐字逐像地复制图像,我们仔细扫描训练 dataset 中的重复样本并将其移除。

列标签:InputOutput 1Output 2。四条 editing instruction 依次为:

1. “改为写 ‘go small go home’。”
2. “黑板上写着 ‘GO BIG OR GO UNET’。”
3. “把这个词改成 ‘UNOT’。”
4. “让标牌写成 ‘MMDIT rules’。”

Figure 15原论文图表

使用 2B Edit model 进行 zero-shot 文字操纵与插入。

deduplication 细节。 按照 Carlini et al.(2023)与 Somepalli et al.(2023a)所述方法,我们选择 SSCD(Pizzi et al., 2022)作为 deduplication 流程的 backbone。SSCD 是用于大规模检测近重复图像的 state-of-the-art 技术,它能生成高质量 image embeddings,可用于 clustering 及其他 downstream tasks。我们还按照 Nichol(2022)的方法确定 cluster 数量 NN;实验中使用 N=16,000N=16{,}000

我们使用 autofaiss(2023)进行 clustering。autofaiss 是一个简化 Faiss(Facebook AI Similarity Search)大规模 clustering 使用流程的库。具体而言,我们利用 FAISS index factory 的功能,按预定义的 centroid 数量训练自定义 index。该方法能够高效、准确地聚类 image embeddings 这类高维数据。

Algorithm 1 详述了我们的 deduplication 方法。我们还通过实验考察不同 SSCD threshold 会移除多少数据,结果见 Figure 16b。根据这些结果,我们为最终运行选择了四个 thresholds,见 Figure 16a。

Algorithm 1:在一个 cluster 中查找重复 items

输入(Require)
  • vecs\mathtt{vecs} —— 单个 cluster 中的向量列表;
  • items\mathtt{items} —— 与 vecs\mathtt{vecs} 对应的 item ID 列表;
  • index\mathtt{index} —— 用于 cluster 内 similarity search 的 FAISS index;
  • thresh\mathtt{thresh} —— 判定重复项的 threshold。
输出dups\mathtt{dups} —— 重复 item IDs 的集合。
  1. dupsnew set()\mathtt{dups}\gets\operatorname{new\ set}()
  2. i0i\gets0length(vecs)1\operatorname{length}(\mathtt{vecs})-1 循环:
  3. qsvecs[i]\mathtt{qs}\gets\mathtt{vecs}[i]。// 当前向量
  4. qiditems[i]\mathtt{qid}\gets\mathtt{items}[i]。// 当前 item ID
  5. lims,D,Iindex.range_search(qs,thresh)\mathtt{lims},D,I\gets\mathtt{index}.\operatorname{range\_search}(\mathtt{qs},\mathtt{thresh})
  6. qiddups\mathtt{qid}\in\mathtt{dups}
  7. 继续下一次循环。
  8. 结束条件判断。
  9. startlims[0]\mathtt{start}\gets\mathtt{lims}[0]
  10. endlims[1]\mathtt{end}\gets\mathtt{lims}[1]
  11. duplicate_indicesI[start:end]\mathtt{duplicate\_indices}\gets I[\mathtt{start}:\mathtt{end}]
  12. duplicate_idsnew list()\mathtt{duplicate\_ids}\gets\operatorname{new\ list}()
  13. duplicate_indices\mathtt{duplicate\_indices} 中每个 jj 循环:
  14. items[j]qid\mathtt{items}[j]\ne\mathtt{qid}
  15. duplicate_ids.append(items[j])\mathtt{duplicate\_ids}.\operatorname{append}(\mathtt{items}[j])
  16. 结束条件判断。
  17. 结束内层循环。
  18. dups.update(duplicate_ids)\mathtt{dups}.\operatorname{update}(\mathtt{duplicate\_ids})
  19. 结束外层循环。
  20. 返回 dups\mathtt{dups}。// 最终的重复 ID 集合

E.3 评估 deduplication 工作的有效性

Carlini et al.(2023)设计了一种两阶段数据 extraction attack:先用标准方法生成图像,再把 membership-inference score 超过某些判定标准的图像标记出来。Carlini et al.(2023)把搜索偏向训练数据中的重复样本,因为这类样本被记忆的概率比非重复样本高出多个数量级(Somepalli et al., 2023a,a;Lee et al., 2021)。

为了评估基于 SSCD 的 deduplication 效果,我们沿用 Carlini et al.(2023),从专门为该目的训练的小模型中提取被记忆的样本,并比较 deduplication 前后的情况。该流程主要包含两个步骤:1)以标准采样方式和已知 prompts,用 Diffusion Model 生成大量样本;2)执行 membership inference,把模型的新生成结果与模型记忆的训练样本分开。Algorithm 2 给出了依据 Carlini et al.(2023)寻找 memorized samples 的步骤。需要注意的是,我们把这套技术运行两次:一次用于只移除完全重复项的 SD-2.1 model,作为 baseline;另一次用于具有 SD-2.1 架构、但在训练前同时使用 SSCD(Pizzi et al., 2022)移除了完全重复与近重复项的模型。

我们基于 threshold 0.50.5 的 SSCD(Pizzi et al., 2022),从训练 dataset 中选出重复程度最高的 350,000350{,}000 个样本,并针对每个文本 prompt 生成 500500 张候选图像,以提高发现 memorization 的概率。其直觉是:对于 Diffusion Models,给定两个不同的随机初始 seeds r1,r2r_1,r_2Gen(p;r1)dGen(p;r2)\operatorname{Gen}(p;r_1)\approx_d\operatorname{Gen}(p;r_2) 以高概率成立。反过来,如果在某种距离度量 ddGen(p;r1)dGen(p;r2)\operatorname{Gen}(p;r_1)\approx_d\operatorname{Gen}(p;r_2),这些生成样本很可能就是被记忆的样本。为了计算两张图像之间的距离 dd,我们采用修改后的 Euclidean 2\ell_2 distance。具体来说,我们发现很多生成结果会被 2\ell_2 distance 错误地判为相似,例如它们都具有灰色背景。因此,我们改为把每张图像划分成 1616 个互不重叠的 128×128128\times128 tiles,再在两张图像的任意 tile pair 之间计算 2\ell_2 distance,并取其中的最大值。

Figure 17 比较了在使用 threshold 0.50.5 的 SSCD 移除近重复样本之前与之后,memorized samples 的数量。Carlini et al.(2023)把 clique size 为 1010 的图像标记为 memorized samples;本文还探索了不同的 clique sizes。对于所有 clique thresholds,SSCD 都能显著减少 memorized samples 的数量。具体来说,当 clique size 为 1010 时,在按 SSCD =0.5=0.5 截断后的 deduplication 训练样本上训练 SD models,可把潜在 memorized examples 减少到原来的 1/51/5

Figure 16原论文图表

在不同 filtering thresholds 下,对训练 datasets 执行 deduplication 的结果。

- (a) 在整个 dataset 上执行 SSCD deduplication 的最终结果。
- (b)10001000 个随机 clusters 上使用不同 thresholds 执行 SSCD deduplication 的结果。

Algorithm 2:检测生成图像中的 Memorization

输入(Require):prompts 集合 PP;每个 prompt 的生成次数 NN;similarity threshold ϵ=0.15\epsilon=0.15;memorization threshold TT
保证(Ensure):在生成样本中检测被记忆的图像。
  1. DD 初始化为重复程度最高的样本集合。
  2. 对每个 prompt pPp\in P
  3. i=1i=1NN
  4. 使用随机 seed rir_i 生成图像 Gen(p;ri)\operatorname{Gen}(p;r_i)
  5. 结束内层循环。
  6. 结束外层循环。
  7. 对每一对生成图像 xi,xjx_i,x_j
  8. 若距离 d(xi,xj)<ϵd(x_i,x_j)<\epsilon
  9. 在图 GG 中连接 xix_ixjx_j
  10. 结束条件判断。
  11. 结束循环。
  12. GG 中每个节点:
  13. 查找包含该节点的最大 clique。
  14. 若 clique 的大小 T\ge T
  15. 把该 clique 中的图像标记为 memorized。
  16. 结束条件判断。
  17. 结束循环。
Figure 17原论文图表

基于 SSCD 的 deduplication 可防止 memorization。 为评估基于 SSCD 的 deduplication 效果,我们从专门为该目的训练的小模型中提取 memorized samples,并比较 deduplication 前后的情况。图中比较了使用 threshold 0.50.5 的 SSCD 移除近重复样本前后,memorized samples 的数量。Carlini et al.(2023)把 clique size 为 1010 的图像标记为 memorized samples;本文也探索了不同的 clique sizes。对于所有 clique thresholds,SSCD 都能显著减少 memorized samples 的数量。具体来说,当 clique size 为 1010 时,在按 SSCD =0.5=0.5 截断后的 deduplication 训练样本上训练的模型,可把潜在 memorized examples 减少到原来的 1/51/5

LLM WIKI · CONTEXT READER

AI 论文解读

DeepSeek V4 Flash

Enter 发送 · Shift + Enter 换行 · Esc 关闭