SD3 论文精读 · 第三部分 · 5.3 节、附录 C、E、第 6 节

精读 SD3:训练到 8B

前两部分定下了配方:RF + logit-normal 抽 \(t\)(5.1),16 通道潜变量、50/50 caption、MM-DiT(5.2)。5.3 节把这个配方放大:先处理数据,再从 256² 微调到 1024²(途中解决了训练发散、长宽比、噪声不够三个问题),然后画 scaling 曲线、和别的模型比。这一页按原文顺序逐段精读,每段先给原文位置和关键原句,再逐句解读。

建议的读法:左边开着论文 PDF(或本站的 中英对照版),右边开着这一页,读一段对一段。

论文阅读地图

这部分要读的全部原文位置

按论文顺序排列,页码按 arXiv 2403.03206v1 的 PDF。

论文位置讲了什么本页
§5.3 引言 + §5.3.1 "Pre-Training Mitigations"(p.9)训练前过滤:色情内容、低美学分、重复图精读 1
附录 E.2、E.3 + Algorithm 1、2 + Fig. 16、17(p.24 到 26)SSCD 去重,16000 个聚类;去重后记忆样本减少约 5 倍精读 1
§5.3.1 "Precomputing Image and Text Embeddings" + 附录 E.1 + Table 7(p.9、p.24)冻结网络的输出预先算好存起来;省显存和时间的代价精读 2
§5.3.2 "QK-Normalization" + Fig. 5(p.9)1024² 微调时混合精度训练发散;对 Q、K 做 RMSNorm 解决精读 3
§5.3.2 "Positional Encodings for Varying Aspect Ratios"(p.9 到 10)分桶;扩展加插值的位置网格;中心裁剪精读 4
§5.3.2 "Resolution-dependent shifting" + Eq. 23 到 25 + Fig. 6(p.10)高分辨率要更多噪声;常数图论证;人类偏好选 \(\alpha=3\)精读 5
§5.3.2 末句 + 附录 C + Fig. 13、14(p.11、p.23 到 24)DPO 偏好微调,LoRA rank 128精读 6
§5.3.3 第 1、3 段 + Fig. 8 + Fig. 12(p.11 到 12、p.22)不同大小的模型训 500k 步;验证 loss 平滑下降、和各种评测高度相关精读 7
§5.3.3 第 4 段 + Table 5(p.11)GenEval 全表;8B + DPO + 1024² 超过 DALL-E 3精读 8
§5.3.3 第 6 段 + Table 6(p.11)大模型少步数掉得更少;路径长度精读 9
§5.3.3 人类评测段 + Fig. 7;"Flexible Text Encoders" + Fig. 9(p.10 到 12)人类偏好评测;推理时去掉 T5精读 10
§5.3.3 第 2 段(视频)+ 第 6 节(p.11、p.12)视频的初步 scaling;结论精读 11
两个常见的读错:第一,位置编码那段和 timestep shift 那段都在 5.3.2(Finetuning on High Resolutions)里,不在 5.3.1。第二,PDF 第 9 页上 5.3.2 排在右栏,和左栏的 5.3、5.3.1 并排,容易先读到它。按小节编号读:5.3 → 5.3.1 → 5.3.2 → 5.3.3。
整个训练流程(从 5.3 各处拼出来):数据过滤去重 → 预先算好潜变量和文本编码 → 在 256×256 上预训练(scaling 实验:500k 步,batch 4096)→ 加 QK-norm、分桶的多长宽比、timestep shift,微调到更高分辨率(最终 1024×1024,\(\alpha=3\))→ DPO 偏好微调。论文没有给 8B 最终模型每个阶段的总步数。
精读 1 · §5.3 引言 + §5.3.1 第 1 段 + 附录 E.2、E.3

训练前先过滤数据

读完这段,你应该能说出三类过滤各针对什么,以及去重怎么做、效果怎么验证。

原文 · §5.3 引言(p.9)

"Before scaling up, we filter and preencode our data to ensure safe and efficient pretraining. Then, all previous considerations of diffusion formulations, architectures, and data culminate in the last section, where we scale our models up to 8B parameters."

  1. "filter and preencode":5.3.1 的两件事:过滤(为了安全),预编码(为了效率,精读 2)。
  2. "all previous considerations … culminate":前面 5.1(训练方式)、5.2(结构和数据)的结论汇总,在 5.3.3 放大到 8B。
原文 · §5.3.1 "Pre-Training Mitigations"(p.9)

"Training data significantly impacts a generative model's abilities. Consequently, data filtering is effective at constraining undesirable capabilities … (i) Sexual content: We use NSFW-detection models … (ii) Aesthetics: We remove images for which our rating systems predict a low score. (iii) Regurgitation: We use a cluster-based deduplication method to remove perceptual and semantic duplicates …; see Appendix E.2."

  1. "constraining undesirable capabilities":模型学不到训练集里没有的东西,所以想让它不会画某类内容,最直接的是训练前就把这类图删掉。
  2. "(i) Sexual content":用 NSFW 检测模型删掉露骨内容。
  3. "(ii) Aesthetics":用美学打分模型删掉低分图。这一条主要为了画质,不只是安全。论文没说用的哪个打分模型和阈值。
  4. "(iii) Regurgitation":regurgitation 是"原样吐出训练图"。一张图在训练集里重复越多次,越容易被模型背下来。所以要删掉"看起来几乎一样"(perceptual)和"内容一样"(semantic)的重复图。
原文 · 附录 E.2 "Details on Deduplication"(p.25)

"… we opt for SSCD (Pizzi et al., 2022) as the backbone for the deduplication process. … We also decided to follow Nichol (2022) to decide on a number of clusters N. For our experiments, we use N = 16,000."

  1. "SSCD":一个专门做"近似重复图检测"的图像特征模型。两张图的 SSCD 特征越相似,越可能是同一张图的变体(裁剪、调色、加水印)。
  2. "number of clusters N = 16,000":几亿张图两两比较太贵,所以先把特征聚成 16000 个簇,只在每个簇内部比较(Algorithm 1:簇内用 FAISS 做半径搜索,相似度超过阈值的算重复)。
  3. 附录 E.3 的验证:按 Carlini et al. (2023) 的方法,专门训小模型,用最常重复的 35 万条 caption 各生成 500 张图,找"几乎一样"的生成结果(视为背下来的)。原文结论:"when the clique size is 10, trained SD models on the deduplicated training samples cut off at SSCD = 0.5 show a 5× reduction in potentially memorized examples"。
证据强度:去重效果是在 SD2.1 结构的小模型上验证的(E.3),不是在 SD3 本身上。过滤用的 NSFW 模型、美学阈值、最终删掉多少数据,论文都没有公开。
自测:为什么去重能减少"背图"?

一张图在训练集里出现很多次,模型在它身上被反复训练,最容易把它整张记住。删掉重复之后每张图只出现一次左右,模型更倾向学到一般规律而不是具体某张图。E.3 用小模型验证了记忆样本减少约 5 倍。

精读 2 · §5.3.1 第 2 段 + 附录 E.1 + Table 7

预先算好:冻结网络只跑一次

读完这段,你应该能读懂 Table 7 每一列,并说出预编码的两个好处和两个代价。

原文 · §5.3.1 "Precomputing Image and Text Embeddings"(p.9)

"Our model uses the output of multiple pretrained, frozen networks as inputs (autoencoder latents and text encoder representations). Since these outputs are constant during training, we precompute them once for the entire dataset."

  1. "pretrained, frozen networks":第二部分讲过:自编码器的编码器 \(E\)、CLIP-L、OpenCLIP bigG、T5-XXL 都是冻结的。
  2. "these outputs are constant during training":同一张图、同一句话,冻结网络每次输出完全一样。每个 epoch 都重算一遍是浪费。
原文 · 附录 E.1(p.24)

"This comes with two main advantages: (i) The encoders do not need to be available on the GPU during training, lowering the required memory. (ii) The forward encoding pass is skipped during training, saving time … This approach has two disadvantages: First, random augmentation for each sample every epoch is not possible … Second, the dense output of the text encoders is particularly large, creating additional storage cost and longer loading times …"

  1. "(i) … lowering the required memory":T5-XXL 光加载就要 19 GB 显存(Table 7),预编码后训练时根本不用加载它。
  2. "(ii) … saving time":每一步省掉编码的前向计算。
  3. "random augmentation … is not possible":存下来的是固定的潜变量,没法每个 epoch 随机裁剪、翻转。所以预编码时统一做中心裁剪;微调高分辨率时先把图裁到最近的长宽比桶再编码(精读 4)。
  4. "dense output of the text encoders is particularly large":T5 每个样本要存 77×4096 个数,Table 7 里每个样本 630.7 kB,是潜变量的约 10 倍。论文用半精度存文本编码,"as we do not observe a deterioration in performance"。
图 1 · Table 7:勾选哪些编码器在训练时"现算",看代价
数字来自 Table 7:Mem 是加载到 GPU 的显存,FP 是 batch 32 时每个样本的前向时间,Storage 是预编码后每个样本的存储,Delta 是把它放进训练循环后 2B 模型(568 ms/步)每步慢多少。把几项加起来是我的近似,论文没有给组合起来的数。
Table 7Mem [GB]FP [ms]Storage [kB]Delta [%]
VAE(编码器)0.142.4565.513.8
CLIP-L0.490.45121.32.6
CLIP-G2.782.77202.215.6
T519.0517.46630.798.3

怎么读:T5 一项就让每一步慢 98.3%,几乎翻倍。四项全在循环里现算,按相加的粗算要慢一倍多。所以对 8B 的大规模训练,预编码是必须的。

自测:预编码之后,还能做"随机水平翻转"这种数据增强吗?

不能在训练时做,因为存下来的是固定的潜变量。要么预编码时就存两份(原图和翻转图),要么放弃。论文的做法是放弃随机增强,统一中心裁剪。

精读 3 · §5.3.2 "QK-Normalization" + Fig. 5

QK-norm:高分辨率训练为什么会炸

读完这段,你应该能说清"attention logit 增长"是什么、为什么会让训练发散,以及 RMSNorm 怎么挡住它。

原文 · §5.3.2 第 1 段(p.9)

"In general, we pretrain all of our models on low-resolution images of size 256² pixels. Next, we finetune our models on higher resolutions with mixed aspect ratios … We find that, when moving to high resolutions, mixed precision training can become unstable and the loss diverges. This can be remedied by switching to full precision training … but comes with a ∼ 2× performance drop compared to mixed-precision training."

  1. "pretrain … 256² … finetune … higher resolutions":先低分辨率后高分辨率,因为 256² 只有 256 个图片 token,1024² 有 4096 个(第二部分精读 5),先在便宜的设置上学会大部分东西。
  2. "mixed precision training":大部分计算用 16 位浮点数(这里是 bf16),比 32 位快约一倍、省显存。bf16 的数值范围很大,但只有约 3 位十进制有效数字,很粗。
  3. "the loss diverges":loss 突然变成 NaN(不是数),训练直接废掉。
  4. "∼ 2× performance drop":这里 performance 指训练速度。换全精度能解决,但慢一倍,不划算。
原文 · §5.3.2 第 1 段(续)

"… Dehghani et al. (2023) observe that the training of large vision transformer models diverges because the attention entropy grows uncontrollably. To avoid this, Dehghani et al. (2023) propose to normalize Q and K before the attention operation. We follow this approach and use RMSNorm … with learnable scale in both streams of our MMDiT architecture …"

  1. "attention entropy grows uncontrollably":这句的说法和 Fig. 5 图注相反:Dehghani et al. 的发现和 Fig. 5 都是 attention logit 失控增长、attention 熵塌缩(变小),正文这里大概是笔误。Fig. 5 图注写得对:"prevents the attention-logit growth instability (left), which causes the attention entropy to collapse (right)"。
  2. "normalize Q and K before the attention operation":attention logit 就是 \(q\cdot k/\sqrt{d_k}\)。训练中 Q、K 的长度可能越变越大,logit 跟着平方级变大,softmax 就变成几乎只有一个 1、其余全 0(熵塌缩)。这时梯度几乎为零或者极不稳定,bf16 的粗精度更放大问题。把 Q、K 先归一化,长度就固定住了,logit 有上界。
  3. "RMSNorm … with learnable scale":RMSNorm 把向量除以它的均方根,再乘一个可学习的缩放。和 LayerNorm 比只是不减均值。可学习的缩放让网络仍能调节注意力的"尖锐程度",只是不能无限增长。
  4. "in both streams":文字流和图片流各自的 Q、K 都加。这就是 Fig. 2b 里四个虚线的 "Opt. RMS-Norm"。
图 2 · 拖动"Q、K 的长度",看 softmax 怎么塌缩,QK-norm 怎么挡住

一个 query 对 12 个 key 的注意力(玩具数字)。长度倍数模拟训练中 Q、K 越变越长。没有 QK-norm 时,logit 正比于倍数的平方,softmax 很快变成"只看一个",熵掉到 0 附近,就是 Fig. 5 右图的熵塌缩。勾上 QK-norm 后,Q、K 先归一化再乘一个固定的可学习缩放(这里取 2.5),长度怎么变 logit 都不变。
原文 · §5.3.2 第 1 段(末)+ Fig. 5 图注

"… enables efficient training at bf16-mixed precision when combined with ϵ = 10⁻¹⁵ in the AdamW optimizer. This technique can also be applied on pretrained models that have not used qk-normalization during pretraining … it is not a universal recipe …" / Fig. 5: "In contrast with these previous works, we observe this instability in the last transformer blocks of our networks. Maximum attention logits and attention entropies are shown averaged over the last 5 blocks of a 2B (d=24) model."

  1. "ϵ = 10⁻¹⁵ in the AdamW optimizer":AdamW 更新时分母里加的那个防止除零的小数(又一个 \(\epsilon\),和噪声、调制参数都无关)。默认通常是 \(10^{-8}\),改小是配合 QK-norm 的另一个稳定性设置,论文没解释原因。
  2. "applied on pretrained models that have not used qk-normalization":256² 预训练时可以没有 QK-norm,微调时再加,模型很快适应。
  3. "not a universal recipe":作者自己提醒:换个训练设置可能要调整。
  4. Fig. 5:横轴训练步数(到 10k),左图纵轴是最大 attention logit(对数轴),右图是 attention 熵。没有 QK-norm(黄线):logit 一路涨到 \(10^3\) 量级,熵往下掉,大约 6k 步时出现 NaN。有 QK-norm(紫线):logit 和熵都平稳。这是 2B 模型最后 5 个块的平均。
自测:为什么说"熵塌缩"是坏事?

熵塌缩意味着每个 token 只注意一个 token,softmax 输出接近 one-hot。这时 softmax 的梯度几乎为零(饱和),而 logit 本身又很大,一点扰动就会让输出剧烈跳动,低精度下容易溢出成 NaN。网络也失去了"综合多个 token 信息"的能力。

精读 4 · §5.3.2 "Positional Encodings for Varying Aspect Ratios"

不同长宽比:位置网格怎么扩展和插值

读完这段,你应该能看懂那个位置公式,并说清"扩展"和"插值"各解决什么。

原文 · §5.3.2 第 2 段(p.9 到 10)

"After training on a fixed 256 × 256 resolution we aim to (i) increase the resolution and … (ii) enable inference with flexible aspect ratios. Since we use 2d positional frequency embeddings we have to adapt them based on the resolution. In the multi-aspect ratio setting, a direct interpolation of the embeddings as in (Dosovitskiy et al., 2020) would not reflect the side lengths correctly. Instead we use a combination of extended and interpolated position grids which are subsequently frequency embedded."

  1. "2d positional frequency embeddings":每个图片 token 有一个坐标(行,列)。先算出坐标数值,再用一组不同频率的 sin/cos 把它变成向量(和时间步的正弦编码同一个思路)。关键在于:编码的是坐标数值,所以可以给它任意实数坐标。
  2. "a direct interpolation … would not reflect the side lengths correctly":ViT 的老办法是把训练时 16×16 的位置编码直接拉伸到新尺寸。但如果新图是 1:2 的长条,拉伸后横竖两个方向的"单位长度"就不一样了,网络会以为图被压扁了。
  3. "extended and interpolated position grids":插值:分辨率变高时,同样的画面范围里塞进更多 token,坐标间距变小(比如 0, 0.25, 0.5, …)。扩展:图变宽时,横向坐标超出训练时的范围继续往外延伸,而不是把整排压缩到原范围里。
原文 · §5.3.2 第 3 段(p.10)

"For a target resolution of S² pixels, we use bucketed sampling … such that each batch consists of images of a homogeneous size H × W, where H · W ≈ S². … Let \(h_{max}=H_{max}/16\), \(w_{max}=W_{max}/16\) and \(s=S/16\) be the corresponding sizes in latent space (a factor 8) after patching (a factor 2). Based on these values, we construct a vertical position grid with the values \(\big((p-\frac{h_{max}-s}{2})\cdot\frac{256}{S}\big)_{p=0}^{h_{max}-1}\) and correspondingly for the horizontal positions. We then center-crop from the resulting positional 2d grid before embedding it."

  1. "bucketed sampling … H · W ≈ S²":预先定好一组长宽比"桶",每个桶的像素总数都约等于 \(S^2\)(所以 token 数差不多,计算量差不多)。每个 batch 只从一个桶里取图,batch 内尺寸一致,才能拼成一个张量。
  2. "/16 … (a factor 8) after patching (a factor 2)":像素到 token 网格要除以 16:自编码器下采样 8,再 2×2 切块。\(S=1024\) 时 \(s=64\)。
  3. "\((p-\frac{h_{max}-s}{2})\cdot\frac{256}{S}\)":拆开看:\(p\) 是第几行(0 到 \(h_{max}-1\))。减去 \(\frac{h_{max}-s}{2}\) 是让中间那 \(s\) 行的坐标从 0 开始,也就是把正方形部分对齐到原点。乘 \(\frac{256}{S}\) 是缩放:\(S=256\) 时乘 1,坐标就是 0 到 15,和预训练完全一样;\(S=1024\) 时乘 1/4,正方形部分的坐标还是 0 到 15.75,只是间距变成 0.25(这就是插值)。比正方形长出来的部分,坐标小于 0 或大于 15(这就是扩展)。
  4. "center-crop":先按最极端的长宽比造一个最大的网格,具体每张图用的时候,从中间裁出它实际的 \(h\times w\)。
图 3 · 按原文公式算出的位置坐标(每个点是一个 token 的坐标)

灰色方框是预训练(256²)时的坐标范围 0 到 15。蓝点是当前设置下每个 token 的坐标。拖到长宽比 1:1、S=256,蓝点和灰框正好重合;换成 S=1024,点变密但仍在灰框里(插值);拉成长条,点在长边方向伸出灰框(扩展),短边方向仍居中。网格里每隔几个才画一个点,避免糊成一片。长宽比范围设成 1:2 到 2:1 是我假设的,论文没写桶的具体范围。
自测:\(S=1024\)、正方形图,第 0 行和第 63 行的纵坐标各是多少?

网格按最极端的长宽比造,有 \(h_{max}\) 行。正方形图从中间裁出 64 行,也就是 \(p\) 从 \(\frac{h_{max}-64}{2}\) 开始。代入公式,裁出的第一行坐标是 \(0\),最后一行是 \(63\times\frac{256}{1024}=15.75\)。和预训练的 0 到 15 范围几乎一样,只是更密。

精读 5 · §5.3.2 "Resolution-dependent shifting" + Eq. 23 到 25 + Fig. 6

高分辨率需要更多噪声:timestep shift

读完这段,你应该能自己推出 Eq. 23,说清 \(\alpha\) 是什么、为什么最后选 3,以及它和第一部分 log-SNR 的关系。

原文 · §5.3.2 第 4 段(p.10)

"Intuitively, since higher resolutions have more pixels, we need more noise to destroy their signal. Assume we are working in a resolution with n = H · W pixels. Now, consider a "constant" image, i.e. one where every pixel has the value c. The forward process produces \(z_t=(1-t)c\mathbb 1+t\epsilon\) …"

  1. "we need more noise to destroy their signal":直觉:同样 \(t=0.5\),一张 64×64 的图和一张 1024×1024 的图被加了同样强度的噪声。但大图里相邻像素高度相关,把周围几个像素平均一下,噪声就被平均掉了,画面的大轮廓还清清楚楚。也就是说同一个 \(t\) 对大图"不够吵"。下面的图 4 可以直接看到这个现象。
  2. "consider a 'constant' image":为了能算出公式,取一个极端简化:整张图每个像素都是同一个数 \(c\)。加噪后得到 \(n\) 个像素,每个都是 \((1-t)c+t\eta_i\),\(\eta_i\) 是独立的标准正态噪声。
图 4 · 同样的 \(t\),大图平均一下就"露馅"了

左:32×32 的小图加噪 \(z_t=(1-t)x+t\epsilon\)。中:128×128 的大图(同一个画面,像素多 16 倍)用同样的 \(t\) 加噪。右:把中间的大图每 4×4 像素平均成 32×32。右边明显比左边清楚:平均 16 个独立噪声,噪声标准差变成 1/4。这就是"同一个 \(t\) 对大图不够吵"。
原文 · §5.3.2 第 4 段(续)

"Thus, \(z_t\) provides n observations of the random variable \(Y=(1-t)c+t\eta\) … \(E(Y)=(1-t)c\) and \(\sigma(Y)=t\). We can therefore recover c via \(c=\frac{1}{1-t}E(Y)\), and the error between c and its sample estimate \(\hat c=\frac{1}{1-t}\sum_{i=1}^n z_{t,i}\) has a standard deviation of \(\sigma(t,n)=\frac{t}{1-t}\sqrt{\frac1n}\) …"

  1. "n observations of … Y":每个像素都是同一个随机变量 \(Y\) 的一次独立观测,均值 \((1-t)c\),标准差 \(t\)。
  2. "\(\hat c=\frac{1}{1-t}\sum z_{t,i}\)":用 \(n\) 个像素的平均值去估计 \(c\)。原文这里少写了 \(\frac1n\),应该是 \(\frac{1}{1-t}\cdot\frac1n\sum_i z_{t,i}\),否则不是平均。
  3. "\(\sigma(t,n)=\frac{t}{1-t}\sqrt{\frac1n}\)":\(n\) 个独立观测的平均,标准差是单个的 \(1/\sqrt n\):\(t/\sqrt n\);再除以 \(1-t\)。所以 \(\sigma(t,n)\) 衡量"在时间 \(t\)、分辨率 \(n\) 下,我对原图还有多不确定"。原文举例:宽高都翻倍,\(n\) 变 4 倍,不确定性减半。
原文 · §5.3.2 第 4 段(末)+ Eq. 23

"… we can now map a timestep \(t_n\) at resolution n to a timestep \(t_m\) at resolution m that results in the same degree of uncertainty via the ansatz \(\sigma(t_n,n)=\sigma(t_m,m)\). Solving for \(t_m\) gives"

\[ t_m=\frac{\sqrt{\frac mn}\,t_n}{1+\big(\sqrt{\frac mn}-1\big)t_n}\qquad(23) \]
  1. 自己推一遍:\(\frac{t_m}{1-t_m}\sqrt{\frac1m}=\frac{t_n}{1-t_n}\sqrt{\frac1n}\),两边乘 \(\sqrt m\):\(\frac{t_m}{1-t_m}=\alpha\frac{t_n}{1-t_n}\),其中 \(\alpha=\sqrt{m/n}\)。设右边为 \(r\),则 \(t_m=\frac{r}{1+r}=\frac{\alpha t_n}{(1-t_n)+\alpha t_n}=\frac{\alpha t_n}{1+(\alpha-1)t_n}\)。就是 Eq. 23。
  2. 意思:在低分辨率 \(n\) 下学好的 \(t_n\),换到高分辨率 \(m\) 时应该用更大的 \(t_m\)(更吵)才能达到同样的不确定性。\(\alpha>1\) 时曲线整体往上弯,端点 0 和 1 不变。
  3. 怎么用:训练时照常抽 \(t_n\)(logit-normal),再用 Eq. 23 映射成 \(t_m\) 去加噪;采样时,均匀的时间步也用 Eq. 23 映射,结果是在高噪声区域多走几步。
图 5 · Eq. 23 的曲线(对应 Fig. 6 左上)和 log-SNR 的平移

左:横轴 \(t_n\),纵轴 \(t_m\),灰线是论文画的 \(\alpha=1,1.5,2,3,4,6\),蓝线是当前 \(\alpha\)。右:RF 路径下 log-SNR \(\lambda_t=2\log\frac{1-t}{t}\)(第一部分第 8 课)随 \(t\) 的曲线,shift 之后整条曲线往下平移 \(2\log\alpha\),这就是 Eq. 24、25。
原文 · §5.3.2 第 5 段(p.10)

"Note that the assumption of constant images is not realistic. To find good values for the shift value \(\alpha:=\sqrt{\frac mn}\) during inference, we apply them to the sampling steps of a model trained at resolution 1024 × 1024 and run a human preference study. The results in Figure 6 show a strong preference for samples with shifts greater than 1.5 but less drastic differences among the higher shift values. In our subsequent experiments, we thus use a shift value of α = 3.0 both during training and sampling at resolution 1024 × 1024."

  1. "the assumption of constant images is not realistic":真实图片不是常数图,像素之间的相关性介于"完全相同"和"完全独立"之间。所以理论值 \(\sqrt{m/n}\)(从 256² 到 1024² 是 \(\sqrt{16}=4\))只是一个参考,实际要靠实验定。
  2. "human preference study":Fig. 6 右上是 Elo 分数的柱状图(Elo 是从两两比较算出的排名分)。按柱子高低:\(\alpha=3.0\) 和 \(6.0\) 最高,其次 2.0、4.0,\(\alpha=1.5\) 和 1.0(不 shift)明显低一截。
  3. "less drastic differences among the higher shift values":只要 shift 够大(超过 1.5),具体选几差别不大。
  4. "α = 3.0 both during training and sampling":最终选择。注意这个偏好实验是在采样时改 shift,训练时也用同样的 3.0。Fig. 6 下面两行:一个 512² 模型分别用 \(\alpha=1\)(上)和 \(\alpha=3\)(下)训练 8k 步并采样的结果,是论文给的定性对比。
原文 · §5.3.2 第 5 段(末)+ Eq. 24、25

"Finally, note that Equation 23 implies a log-SNR shift of \(\log\frac nm\) similar to (Hoogeboom et al., 2023):"

\[ \lambda_{t_m}=2\log\frac{1-t_n}{\sqrt{\frac mn}\,t_n}\qquad(24)\qquad\quad =\lambda_{t_n}-2\log\alpha=\lambda_{t_n}-\log\frac mn\qquad(25) \]
  1. 第一部分讲过 RF 的 \(\lambda_t=\log\frac{a_t^2}{b_t^2}=2\log\frac{1-t}{t}\),越大越清晰。把 \(\frac{t_m}{1-t_m}=\alpha\frac{t_n}{1-t_n}\) 代进去,就得到 Eq. 24、25:整条 log-SNR 曲线往下平移 \(\log\frac mn\)。
  2. 和第一部分的联系:logit-normal 抽 \(t\) 等价于在 \(\lambda\) 上放一个钟形的权重。shift 相当于把这个钟形整体挪向更低的 SNR(更吵)一侧。Hoogeboom et al. (2023) 的 simple diffusion 也有同样的结论。
自测:\(\alpha=3\) 时,\(t_n=0.5\) 映射到多少?这意味着什么?

\(t_m=\frac{3\times0.5}{1+2\times0.5}=0.75\)。低分辨率下"一半信号一半噪声"的状态,在 1024² 下要加到 \(t=0.75\) 才算等价的吵。log-SNR 从 0 降到 \(-2\log3\approx-2.2\)。

精读 6 · §5.3.2 末句 + 附录 C + Fig. 13、14

DPO:最后按人类偏好微调

读完这段,你应该能说清 DPO 在 SD3 里怎么用、改了哪些参数、效果在哪里看。

原文 · §5.3.2 末句(p.11)

"After the shifted training at resolution 1024×1024, we align the model using Direct Preference Optimization (DPO) as described in Appendix C."

原文 · 附录 C(p.23)

"… we apply the method introduced in Wallace et al. (2023) to our 2B and 8B parameter base model. Rather than finetuning the entire model, we introduce learnable Low-Rank Adaptation (LoRA) matrices (of rank 128) for all linear layers as is common practice. We finetune these new parameters for 4k and 2k iteration for the 2B and 8B base model, respectively. We then evaluate the resulting model in a human preference study using a subset of 128 captions from the Partiprompts set (roughly three voter per prompt and comparison)."

  1. DPO 是什么:原本是给大语言模型用的:有一批"同一个提示下,人更喜欢 A 不喜欢 B"的数据,直接调模型,让它生成 A 的概率相对 B 变大,不需要单独训练奖励模型。Wallace et al. (2023) 的 Diffusion-DPO 把它改到扩散模型上。论文没说偏好数据从哪来。
  2. "LoRA matrices (of rank 128) for all linear layers":不改原模型的参数,而是给每个线性层旁边加一对小矩阵(秩 128),只训练这些小矩阵。参数少、成本低、不容易把原模型改坏。
  3. "4k and 2k iteration":训练很短,2B 训 4000 步,8B 只训 2000 步。
  4. "128 captions … roughly three voter per prompt":评测规模不大:128 个提示,每个提示每组对比约 3 个人投票。Fig. 14 显示人在 prompt following 和整体质量上都更偏好 DPO 后的模型;Fig. 13 的例子里 DPO 后的图更好看、拼写更准。
在结果里哪里能看到 DPO:Table 5 里 depth=38 在 512² 下,不加 DPO 总分 0.68,加 DPO 0.71;再到 1024² 加 DPO 是 0.74(精读 8)。所以最终的 8B 模型 = RF 预训练 + 1024² shift 微调 + DPO。
自测:为什么用 LoRA 而不是直接微调全部 8B 参数?

偏好数据量小、训练步数少,全量微调容易过拟合或把原模型能力改坏,显存也大得多。LoRA 只训练很少的新参数,原模型保持不变,是常见做法(原文 "as is common practice")。

精读 7 · §5.3.3 第 1、3 段 + Fig. 8 + Fig. 12

scaling 实验:模型越大,loss 越低,图越好

读完这段,你应该能读懂 Fig. 8 的八个小图,并说清"验证 loss 是好的代理指标"这句话的证据。

原文 · §5.3.3 第 1 段(p.11)

"For images, we conduct a large scaling study and train models with different numbers of parameters for 500k steps on 256² pixels resolution using preencoded data, c.f. Appendix E.1, with a batch size of 4096. We train on 2 × 2 patches, and report validation losses on the CoCo dataset every 50k steps. In particular, to reduce noise in the validation loss signal, we sample loss levels equidistant in t ∈ (0, 1) and compute validation loss for each level separately. We then average the loss across all but the last (t = 1) levels."

  1. "different numbers of parameters":用第二部分的深度 \(d\) 控制:Fig. 8 里图像模型是 depth 15、18、21、30、38。
  2. "500k steps on 256² … batch size of 4096":这是 scaling 实验的设置,都在 256² 上(便宜)。和 5.1 的 batch 1024 比大了 4 倍。
  3. "sample loss levels equidistant in t":随机抽 \(t\) 算出来的验证 loss 波动很大(不同 \(t\) 的 loss 本来就差很多,第一部分第 7 课)。所以固定几个等间距的 \(t\),每个分别算,再平均,曲线更平滑。
  4. "all but the last (t = 1) levels":\(t=1\) 时输入是纯噪声,loss 基本降不下去,只会加噪声,所以不算。
原文 · §5.3.3 第 3 段(p.11)

"For both the image and video domains, we observe a smooth decrease in the validation loss when increasing model size and training steps. We find the validation loss to be highly correlated to comprehensive evaluation metrics (CompBench, GenEval) and to human preference. These results support the validation loss as a simple and general measure of model performance. Our results do not show saturation neither for image not for video models."

图 6 · 怎么读 Fig. 8:上排是 scaling 曲线,下排是相关性

这是示意图,曲线形状是我画的,不是论文数据,只为了说明怎么读。下排列出的相关系数 \(r\) 是论文 Fig. 8 里标的真实数字。
  1. 上排第 1、2 列(图像):纵轴验证 loss。第 1 列横轴训练步数,每条线一个深度,越深的线越低,而且都还在往下走。第 2 列横轴是训练 FLOPs(总计算量,对数轴),这才是公平的比较:大模型每步更贵。看"同样的计算量下哪个深度最低"。
  2. 上排第 3、4 列:视频模型(depth 18、24、30),同样的读法(精读 11)。
  3. 下排:每个点是某个深度在某个训练步的 checkpoint,横轴是评测分数,纵轴是验证 loss。相关系数:GenEval \(r=-0.920\),人类偏好 Elo \(r=-0.982\),T2I-CompBench \(r=-0.898\),视频人类偏好 \(r=-0.908\)。负号是因为 loss 越低分越高。\(|r|\) 越接近 1 越线性相关。
  4. 图注里的细节:"An exception is depth=38, where learning rate adjustments at \(3\times10^5\) steps were necessary to prevent divergence"。最大的模型训练到一半要调学习率防止发散,所以它的曲线不是完全同等条件。
  5. 为什么这件事重要:第一部分说过,不同训练方式的 loss 不能横比。但同一个训练方式下,loss 和人类偏好几乎是一条直线(\(r=-0.982\))。所以训练大模型时可以只盯验证 loss,不用每次都做昂贵的人类评测。
证据强度:"没有饱和"是指在训练到的范围内曲线还在下降,不代表无限下去都成立。论文没有拟合 scaling law 的公式(比如幂律指数),只是画了曲线。相关性是在同一个模型族内部算的,换一种训练方式或结构不一定成立。Fig. 12(p.22)给了定性的例子:训练越久、模型越大,图越好。
自测:为什么第 2 列要用 FLOPs 而不是步数做横轴?

同样一步,depth=38 的计算量是 depth=15 的十几倍。用步数做横轴,大模型当然占便宜。用 FLOPs 做横轴,比较的是"花同样的算力,哪个模型 loss 更低",这才能说明放大模型是划算的。

精读 8 · §5.3.3 第 4 段 + Table 5

GenEval:8B 在提示理解上超过 DALL-E 3

读完这段,你应该能读懂 Table 5 的每一列,并指出哪些列 SD3 赢、哪些没赢。

原文 · §5.3.3 第 4 段(p.11)

"Tab. 5 shows the results of GenEval in full. When applying the methods presented in Section 5.3.2 and increasing training image resolution, our biggest model excels in most categories and outperforms DALLE 3, the current state of the art in prompt comprehension, in overall score."

  1. "GenEval":自动评测:给定"两个物体""三个苹果""红色的杯子在蓝色的书左边"这类提示,用目标检测模型判断生成的图是否满足。数字是成功的比例(0 到 1)。
  2. "applying the methods presented in Section 5.3.2 and increasing training image resolution":表的最后一行(depth=38,1024²,加 DPO)用到了 5.3.2 的全部方法。
  3. "excels in most categories":不是所有列都第一,见下表。
图 7 · Table 5 的 Overall 列(点按钮切换要看的列)
数字全部来自 Table 5。灰色是其他模型,蓝色是 SD3 的各个版本(512² 下的四个深度、加 DPO、1024² 加 DPO),粉色是 DALL-E 3。
Table 5(节选)OverallSingleTwoCountColorsPositionColor Attr.
SDXL0.550.980.740.390.850.150.23
IF-XL0.610.970.740.660.810.130.35
DALL-E 30.670.960.870.470.830.430.45
Ours d=38, 512²0.680.980.840.660.740.400.43
Ours d=38, 512² w/DPO0.710.980.890.730.830.340.47
Ours d=38, 1024² w/DPO0.740.990.940.720.890.330.60
  1. 赢的:Overall 0.74 vs DALL-E 3 的 0.67;Two Objects、Colors、Color Attribution(0.60 vs 0.45)都是第一。
  2. 没赢的:Position(位置关系)DALL-E 3 是 0.43,SD3 最好的一行是 depth=38 无 DPO 的 0.40,加 DPO 和上 1024 后反而降到 0.34、0.33。Counting 最高的是 512² w/DPO 的 0.73,1024² 那行是 0.72。
  3. 深度的趋势:512² 下 depth 18、24、30、38 的 Overall 是 0.58、0.62、0.64、0.68,越大越好,和 Fig. 8 一致。
注意可比性:其他模型的数字是从各自论文或 GenEval 原文抄来的,生成设置不完全一样。SD3 的数字是作者自己跑的。DALL-E 3 是闭源的,DPO 和分辨率也是混在一起的改动。
自测:从 512² w/DPO 到 1024² w/DPO,哪些列变好、哪些变差?

变好:Overall 0.71 → 0.74,Single 0.98 → 0.99,Two 0.89 → 0.94,Colors 0.83 → 0.89,Color Attribution 0.47 → 0.60。变差:Counting 0.73 → 0.72,Position 0.34 → 0.33(都很小)。

精读 9 · §5.3.3 第 6 段 + Table 6

大模型用更少的步数

读完这段,你应该能读懂 Table 6,并把"路径长度"和第一部分的"路越直越好走"联系起来。

原文 · §5.3.3 第 6 段(p.11)

"Lastly, Table 6 highlights an intriguing result: not only do bigger models perform better, they also require fewer steps to reach their peak performance."

原文 · Table 6 图注(p.11)

"The table shows the relative performance decrease relative to CLIP scores evaluated using 50 sampling steps at a fixed seed. Larger models can be sampled using fewer steps, which we attribute to increased robustness and better fitting the straight-path objective of rectified flow models, resulting in shorter path lengths. Path length is calculated by summing up \(\lVert v_\theta\cdot dt\rVert\) over 50 steps."

  1. "relative performance decrease relative to CLIP scores … using 50 sampling steps":以 50 步的 CLIP score 为基准,用 5、10、20 步采样时 CLIP score 掉了百分之几。越小越好。
  2. "better fitting the straight-path objective":第一部分第 2 课:路越直,Euler 法少走几步误差越小。RF 的训练目标是直线路径,但网络学到的是"平均速度",实际轨迹会弯。作者的解释是大模型拟合得更好,轨迹更直。
  3. "Path length … summing up \(\lVert v_\theta\cdot dt\rVert\) over 50 steps":把 50 步每步走过的距离加起来。两点之间直线最短,所以路径越短说明越直(在起点终点差不多的前提下)。
图 8 · Table 6:少步数时 CLIP score 掉了多少(%)
三组柱子分别是 5/50、10/50、20/50 步,每组里三根是 depth 15、30、38。数字全部来自 Table 6。
Table 65/50 步10/50 步20/50 步路径长度
depth=154.300.860.21191.13
depth=303.590.700.24187.96
depth=382.710.140.08185.96
  1. 最醒目的:10 步时,depth=38 只掉 0.14%,depth=15 掉 0.86%。也就是 8B 模型用 10 步几乎和 50 步一样好。
  2. 不完全单调:20 步时 depth=30(0.24)比 depth=15(0.21)掉得还多一点。
  3. 路径长度:191.13 → 187.96 → 185.96,只差约 3%。方向和解释一致,但差距不大。
证据强度:"固定一个随机种子",指标只有 CLIP score 一种,三个模型。"大模型更直"是作者的解释("we attribute to"),路径长度的差距也小,算是支持性的观察,不是严格证明。
自测:为什么路径短能说明路径直?有什么前提?

起点(噪声)和终点(生成的图)之间直线最短,弯路一定更长。前提是不同模型的起点终点距离差不多,比较才公平。同一个种子、同一批提示下,起点相同,终点都是合理的图,这个前提大致成立。

精读 10 · §5.3.3 人类评测段 + Fig. 7 + "Flexible Text Encoders" + Fig. 9

人类评测,以及推理时去掉 T5

读完这段,你应该能读懂 Fig. 7 的 win rate,并说清去掉 T5 损失了什么。

原文 · §5.3.3 人类评测段(p.11)

"Our d = 38 model outperforms current proprietary … and open … SOTA generative image models in human preference evaluation on the Parti-prompts benchmark in the categories visual aesthetics, prompt following and typography generation, c.f. Figure 7. For evaluating human preference in these categories, raters were shown pairwise outputs from two models, and asked to answer the following questions: …"

  1. "pairwise outputs from two models":每次给评分者看同一提示下 SD3 和另一个模型的两张图,选更好的。Fig. 7 的纵轴是 SD3 的胜率(Winrate),50% 的虚线表示打平。
  2. "visual aesthetics, prompt following and typography":三个问题:哪张更好看;哪张更符合文字;哪张把要求的文字写得更准("More accurate spelling is preferred! Ignore other aspects.")。
  3. 读 Fig. 7:横轴是对手:PixArt-α、SDXL、SDXL-Turbo、Stable Cascade、Playground-V2.5、MJ-V6、Ideogram-V1.0、DALLE-3、Ours w/o T5。大部分柱子在 50% 以上,排版(黄色)通常赢得最多;和 Ideogram、DALL-E 3 这类强模型差距小,按图读 Ideogram 的视觉美感一项大约在 50% 附近。(具体高度是我从图上读的,论文没给表。)
原文 · §5.3.3 "Flexible Text Encoders"(p.11 到 12)

"While the main motivation for using multiple text-encoders is boosting the overall model performance, we now show that this choice additionally increases the flexibility … we train our model with three text encoders, with an individual drop-out rate of 46.3%. Hence, at inference time, we can use an arbitrary subset of all three text encoders. This offers means for trading off model performance for improved memory efficiency, which is particularly relevant for the 4.7B parameters of T5-XXL that require significant amounts of VRAM."

  1. "individual drop-out rate of 46.3%":第二部分讲过:每个编码器的输出训练时以约 46% 的概率被单独置零(附录 B.3 写的是 46.4%)。所以模型见过"只有 CLIP 没有 T5"的输入,推理时去掉 T5(用零代替)不会出分布。
  2. "4.7B parameters of T5-XXL":T5 编码器本身比 2B 的 MM-DiT 还大,加载要 19 GB 显存(Table 7)。
原文 · "Flexible Text Encoders"(续)

"… we observe limited performance drops when using only the two CLIP-based text-encoders for the text prompts and replacing the T5 embeddings by zeros. … Only for complex prompts involving either highly detailed descriptions of a scene or larger amounts of written text do we find significant performance gains when using all three text-encoders. … Removing T5 has no effect on aesthetic quality ratings (50% win rate), and only a small impact on prompt adherence (46% win rate), whereas its contribution to the capabilities of generating written text are more significant (38% win rate)."

图 9 · 推理时选用哪些文本编码器(显存来自 Table 7,胜率来自正文)
只有"全选"和"去掉 T5"两种组合论文给了人类评测结果。去掉 T5 时三个胜率是 w/o T5 版本对全编码器版本:美感 50%(没差别)、提示遵循 46%、排版 38%。其他组合论文没评测。
  1. 怎么理解:两个 CLIP 已经够描述"画什么、什么风格"。T5 的价值在长而细的描述和要写出来的字,这正是第二部分说的 T5 更懂语言、CLIP 更懂画面。Fig. 9 的三个例子:前两行是复杂描述和长文字,去掉 T5 明显变差;第三行简单提示几乎一样。
  2. Fig. 7 里的 "Ours w/o T5":这一栏是全编码器 SD3 对 w/o T5 的胜率,所以是 50%、54%、62% 左右,正好是正文 50%、46%、38% 的反面。
自测:如果训练时没有对每个编码器单独做 dropout,推理时还能直接去掉 T5 吗?

效果会很差。模型从没见过"T5 那部分全是 0"的输入,这对它是分布外的情况。正是因为训练时约 46% 的步里 T5 被置零,去掉 T5 才是模型熟悉的输入。

精读 11 · §5.3.3 第 2 段(视频)+ 第 6 节

视频的初步 scaling 和全文结论

读完这段,你应该能说清视频实验怎么做的、结论的三句话各对应哪一部分的证据。

原文 · §5.3.3 第 2 段(p.11)

"Similarly, we conduct a preliminary scaling study of our MM-DiT on videos. To this end we start from the pretrained image weights and additionally use a 2x temporal patching. … In each attention layer we rearrange the representation in the visual stream and add a full attention over all spatiotemporal tokens after the spatial attention operation before the final feedforward layer. Our video models are trained for 140k steps with a batch size of 512 on videos comprising 16 frames with 256² pixels. We report validation losses on the Kinetics dataset every 5k steps. Note that our reported FLOPs for video training in Figure 8 are only FLOPs from video training …"

  1. "start from the pretrained image weights":从图像模型接着训,不是从头训视频。
  2. "2x temporal patching":除了空间 2×2,时间上相邻 2 帧也打包进一个 token,16 帧变成 8 个时间位置。
  3. "add a full attention over all spatiotemporal tokens after the spatial attention":原来的注意力只在一帧内部做(空间),在它后面、MLP 之前,加一层跨所有帧所有位置的注意力,让不同帧之间交换信息。
  4. "only FLOPs from video training":Fig. 8 第 4 列的横轴不含图像预训练的算力,所以看起来视频模型用的算力少,其实前面还有图像预训练。
  5. 结论和图像一样:loss 随模型大小和步数平滑下降、没饱和,和人类偏好相关(\(r=-0.908\))。论文称之为 "preliminary",只用了 depth 18、24、30 三个大小。
原文 · 第 6 节 Conclusion(p.12)

"In this work, we presented a scaling analysis of rectified flow models for text-to-image synthesis. We proposed a novel timestep sampling for rectified flow training … We also demonstrated the advantages of our transformer-based MM-DiT architecture … Finally, we performed a scaling study of this combination up to a model size of 8B parameters and \(5\times10^{22}\) training FLOPs. … The scaling trend shows no signs of saturation …"

结论里的话证据在哪本系列
"a novel timestep sampling for rectified flow training"§3.1 Eq. 18 到 22;§5.1 Table 1、Fig. 3第一部分
"advantages of our transformer-based MM-DiT architecture"§4 Fig. 2;§5.2.3 Fig. 4第二部分
"scaling study … 8B parameters and \(5\times10^{22}\) training FLOPs"§5.3.3 Fig. 8本页精读 7
"validation loss improvements correlate with … benchmarks as well as human preference"Fig. 8 下排本页精读 7
"competitive with state-of-the-art proprietary models"Table 5、Fig. 7本页精读 8、10
"no signs of saturation"Fig. 8 上排(在训练到的范围内)本页精读 7
全文的证据强度,一起记住:5.1 和 5.2 的比较都是小规模、单次运行;8B 直接沿用小规模选出的配方,没有在大规模上重新比较;QK-norm、shift 的 \(\alpha\)、DPO 是工程上的稳定和调优手段;和闭源模型的比较依赖人类评测和别人报告的数字。这些不影响论文的主要贡献,但讲的时候要分清"实验证明了"和"作者选择了"。
最终自测:用三句话讲清 5.3 做了什么。

先过滤去重数据、预先算好潜变量和文本编码,在 256² 上训练 depth 15 到 38 的模型,发现验证 loss 随大小和算力平滑下降、没饱和,而且和 GenEval、人类偏好高度相关。微调到 1024² 时用 QK-norm 防止 bf16 训练发散,用扩展加插值的位置网格支持多长宽比,用 Eq. 23 的 timestep shift(\(\alpha=3\))补足高分辨率需要的噪声,最后再用 DPO 对齐人类偏好。最终 8B 模型在 GenEval 总分和人类评测上达到或超过 DALL-E 3 等模型,大模型还能用更少的采样步数,训练时的编码器 dropout 也让推理时可以去掉 T5 省显存。