第 1 章 · Module 1: 直觉与生成模型基础

为什么需要扩散?AR 和 Diffusion 的对比

从我们熟悉的 ChatGPT 出发,看为什么还要另一种生成范式。


1. 为什么需要扩散?AR 和 Diffusion 的对比

主源:Vizuara《Diffusion Language Models from Scratch》Lecture 1 / Lecture 5 / Lecture 6(讲师 Dr. Raj Dandekar,YouTube 入口);副源:Vizuara 同系列 Lecture 7-11(ARM 架构与训练循环深拆);CMU 10-799 S26 Lecture 1(讲师 Kelly Hu)。这一章不教任何具体公式,它的任务是把一个反直觉的研究问题种到你心里——"图像 / 视频已经投降给 diffusion,为什么文本还死守 autoregressive?"——并交代清楚答这个问题需要先扎实理解的 ARM 骨架。

📌 TL;DR

这章是整本教材的"题眼"。 Dr. Raj 在 Lecture 5 把 Andrej Karpathy 的一个公开困惑搬到了讲台上:今天几乎所有顶级图像生成器(Stable Diffusion / Midjourney / SORA)都跑 diffusion,而几乎所有顶级文本生成器(GPT / Claude / Gemini)都跑 autoregressive。同一种"概率分布学习"的任务,为什么模态决定了范式?是不是我们脑子里有一个偏见?

本章把这一对范式摆在一起:

  • Autoregressive (AR):把联合概率拆成 $p(x_1,\dots,x_T)=\prod_t p(x_t\mid x_{a fancy way to understand a very simple concept"——朴素到不像研究范式,但工程上无敌。
  • Diffusion:把整段文本视作 high-dim token space 里的一个向量,从全噪声出发,所有位置同时一步步精修。"为什么图像可以这么做,文本不行?"——本教材剩下的 20 章都在回答这个问题。

讲师还给了一个反复出现的口号——"diffusion LM = ARM × 80% + 3 个新概念"。所以你不可能跳过 AR 直接学 diffusion LM。本章先把这两条路线的形状讲清楚,并铺出"三阶段 LLM 架构(input / processor / output)"作为之后所有章节复用的骨架。

一、本章的「题眼」:Karpathy 反复追问的那个反直觉问题

这一章的标题是"为什么需要扩散",但讲师 Dr. Raj Dandekar 在 Vizuara《Diffusion Language Models from Scratch》Lecture 5 一开头就把问题问得更刺:明明 diffusion 已经赢下了图像、视频、音频,为什么文本还在用 50 年代就有思想雏形的 autoregressive?

讲师原话(chunk #53, Lecture 5):「It seems like a natural question that why can't diffusion models — why should they only be used for images? Is there some bias in our mind? This is exactly what Andrej Karpathy also talks about. He says that most of the image generation tools actually use diffusion and not auto-regression. ... It's only text which has been left behind. So it is a bit of a mystery to me and many others that why for some reason text prefers auto-generation but image, video prefer diffusion. Why should this be? These are the kind of counterintuitive questions which researchers should ask.」

把这句话拆开看,里面塞了三件事:

  1. 事实判断:图像 / 视频领域几乎全是 diffusion,文本几乎全是 AR。这不是一个理论选择,是工业级别的偏好分歧。
  2. 研究态度:讲师直接引用 Karpathy 的研究方法论——好研究往往始于一个看起来"反直觉"的问题。如果你能问出"为什么 X 模态用 A 范式,Y 模态用 B 范式?是不是我们脑子里有偏见?"——你就开始向一个有意义的 rabbit hole 进发。
  3. 项目方向:Vizuara 这门课、以及本教材的整个 Module 6(离散与语言扩散),就是顺着这个问题往下挖。本章只是入口。
🧭 请把这个问题写在你笔记的扉页——"Why has language stuck with AR while images / video surrendered to diffusion?" 后面 20 章的所有公式、所有 ablation 数字,都是在为这个问题积累答案。读完整本教材,你应该能用三句话回答它。

1.1 Cornell MDLM 把"反直觉"变成了正式研究问题

Dr. Raj 在 Lecture 5 顺便点了一篇 2024 年的"风向标论文":Cornell 的 MDLM(Sahoo et al., "Simple and Effective Masked Diffusion Language Models")。他们在论文 intro 里直接写出了和讲师同样的困惑——"why should images and video generation models have all the fun?"——并把这个困惑变成了一篇正式的研究论文。

🟡 教材外补充: MDLM 之后,2024-2026 年这条路线快速堆叠:SEDD(Lou et al. 2024,score entropy discrete diffusion)、LLaDA(Nie et al. 2025,8B 规模首次接近同尺寸 LLaMA)、Mercury(Inception Labs 2025,商业 API)。但这些都建立在一个共同的基础——"diffusion LM = 80% ARM + 3 个新概念"——所以本教材的写作顺序是:先把 ARM 那 80% 讲透,再在第 19-21 章拆那 3 个新概念。

二、Karpathy 的研究方法论锚点:"from scratch"

讲师在 Lecture 1(chunk #5)介绍这门课时,先把自己的研究态度摊出来:

「When I started thinking about diffusion language models, I thought it was very difficult — the initial phase took a very long amount of time to really understand what's going on. But the final implementation, building it fully from scratch and comparing it with auto-regressive models, was fairly straightforward and simple.」

这呼应 Karpathy 那条几乎所有从业者都引用过的箴言:

"Whenever you learn something from scratch, you understand the gaps in your knowledge."

所以这本教材(以及 Vizuara 这门课)的方法不是"看完一篇综述论文然后总结",而是把 ARM 和 diffusion LM 都从零写一遍 PyTorch 代码,每一行都讲一遍。讲师在 Lecture 11(chunk #155)就预告:

「Before moving on to the diffusion model architecture and assembling it from scratch, I actually want to show you that we can build a small language model based on the traditional ARM architecture fully from scratch.」(基于 TinyStories 数据集)

这个 ethos 决定了本章的写法——我们不会停在"AR 是什么 / Diffusion 是什么"的高层概念,而是把"AR 模型的三阶段架构"这把钥匙提前递到你手里,因为后面 20 章每一章都要拿这把钥匙开一扇门。

三、Autoregressive Models(ARM):被取了花哨名字的朴素思想

讲师在 Lecture 6(chunk #63)走到白板前,先做了一个"祛魅"操作——他要让你不要被术语吓到:

「Auto-regressive models — they're also called as ARMs now — but they're just a fancy way to understand a very simple concept. The way language models work is as follows: they are trained for something which is called as a next token prediction task. ... When a language model is trained, they are always trained to predict one token at a time.」

把这段话翻译成形式化语言。给一段文本 $x = (x_1, x_2, \ldots, x_T)$($x_t$ 是第 $t$ 个 token),AR 模型直接套用概率论的链式法则:

$$p(x_1, x_2, \ldots, x_T) \;=\; \prod_{t=1}^{T} p(x_t \mid x_1, x_2, \ldots, x_{t-1})$$
Why:这一步用的是恒等式,没有任何近似。任何联合概率都可以这样分解;这个分解唯一假设的是"前缀已知 → 下一个的条件分布存在",对离散 token 总是成立。

每一项 $p(x_t \mid x_{给定前面这 $t-1$ 个 token,下一个 token 是词表里哪个?" 训练时用交叉熵 loss 监督每个位置;推理时从前往后一次只采一个。

3.1 把"once upon a time"的例子写完整

讲师反复用同一个 prompt 示意(chunk #63):

「During inference time, if I give a prompt that 'once upon a time' and I want the language model to continue...」

它会做什么?答案是它绝不可能一次性"喷"出整段续写。它的工作循环是这样的:

  1. 看 `once upon a time` → 生 token 1(比如 `there`);
  2. 看 `once upon a time there` → 生 token 2(比如 `was`);
  3. 看 `once upon a time there was` → 生 token 3(比如 `a`);
  4. ……一直到模型决定吐 ``(结束符)为止。

注意三个关键性质:

  • 顺序刚性:必须从左到右;第 $t$ 步的输入永远是"前面 $t-1$ 个 token + prompt"。
  • 单向条件:模型只学过"前文 → 下一 token",没学过"后文 → 前一 token"——这是后面要讲的 reversal curse 的根。
  • 已生不可改:一旦 token 1 是 `there`,后续所有步都建立在它之上;它不会被回头修正。

四、ARM 架构:input → processor → output 三阶段骨架

讲师 Lecture 8(chunk #87)拉出本教材后面会反复复用的三阶段骨架:

「The LLM architecture as a whole is divided into three stages. The first stage is the input stage. The second stage is the processor stage and the third stage is the output stage.」

这个划分极重要——讲师 Lecture 7(chunk #73)紧接着告诉你为什么:

「It turns out that for diffusion language models, their architecture is 80% similar to traditional language models with the addition of these three concepts. So you can think of a diffusion language model as these key characteristics plus 80% of an ARM architecture.」

换句话说,下一个十几章的 diffusion LM 章节,复用的就是这套 ARM 骨架。我们花一节把它的形状画清楚。

4.1 输入阶段(input stage)

讲师 Lecture 8(chunk #87)说得很直白:

「Machine learning models, language models — they can't understand text. So we need to somehow convert this text into numerical format. That's where the first stage of the LLM architecture actually begins.」

输入阶段做三件事:

  1. Tokenize(分词):把 "once upon a time a little" 切成 token id(比如 `[2470, 1746, 257, 640, 257, 1310]`)。
  2. Token embedding:把每个 id 通过 lookup table 变成一个 768 维向量(GPT-2 small 的 hidden size)。
  3. Positional embedding:再加一个表示"第几个 token"的向量。两者相加得到 input embedding。

讲师在 Lecture 9(chunk #106)特别强调,此时的向量是"哑的"——它只知道自己是"bright",不知道句子里其他 token 在做什么。这就是接下来 attention 要解决的问题。

4.2 处理阶段(processor stage):Transformer block 堆栈

处理阶段是 ARM 的"心脏"。它由 $N$ 个相同结构的 Transformer block 堆叠而成。讲师 Lecture 11(chunk #131-#132)说:

「We don't have one transformer block but we have multiple such transformer blocks which are stacked together. ... there might be 12, 24, or even 96.」

每个 block 内部,讲师 Lecture 9-10 把它拆成 6 个零件——这 6 个零件在后面的 diffusion LM 章节里会原样复用,所以现在记一下:

子模块作用讲师给的口语化解释(chunk)
Layer Norm(前)每个向量减均值除标准差"mean of zero, variance of one"(#128)
Multi-Head Attentiontoken 间互看,把 input vector 变成 context vector"context vector is much richer than the input vector"(#106)
Dropout随机置零部分元素"team project metaphor:懒散的队友被赶走,剩下的人必须 pick up the slack"(#125)
Residual / Shortcut把 block 的输入直接加到输出"alternative path for gradient → 防止 vanishing gradient"(#126-#127)
Layer Norm(后)+ FFN4× 扩张 + 收缩的两层 MLP,配 GELU 激活"expansion and contraction block"(#128-#129)
Dropout + Residual同前"layer norm / dropout / residual 在 transformer 里反复出现"(#130)

讲师 Lecture 11(chunk #131)专门点出一个研究品味的观察:

「All of these are not new ideas. They were existing in deep learning for a long time. But this transformer block which stacks all of it together is pretty new.」

讲师在 Lecture 10(chunk #125)还给了一个特别朴素但好记的"小组项目"比喻来解释 Dropout:

「I always think of it like a group project. If there are four team members, there are always those two people who don't do anything. How do you prevent this? Well, if one of the persons who is doing all the work suddenly is sick and is not able to work, the other person has to pick up the slack. That's a similar concept of dropout. If there are some lazy neurons, suddenly if the neighboring neurons are switched off during one dropout forward pass, this neuron has no other option but to pick up the slack and learn weights that improve the generalization performance.」

这个比喻不只是好玩——它准确地说明了 dropout 的因果链:随机置零 → 强迫每个神经元都得"独立可用" → 减少对邻居的过拟合依赖 → 提升 generalization。本教材后面讲 classifier-free guidance 时还会回到"随机扔掉条件信号"这个思想——本质上是 dropout 的另一种用法。

而 Residual / Shortcut Connection 的存在意义,讲师 Lecture 10(chunk #126-127)也有清晰交代:

「If multiple gradients directly multiply with each other by the time we back-propagate and reach towards the initial layers, the gradient might vanish, learning stagnates. To prevent this we give an alternative path for the gradient to flow, and this prevents the vanishing gradient problem and makes sure learning does not stagnate.」

把这两个零件的"为什么"绑在一起记忆:Dropout 防过拟合,Residual 防梯度消失——这是从 2015 年 ResNet 时代沉淀下来的两大"标配",到 2017 年 Transformer 把它们焊在每个 block 里。Diffusion 时代依然原样保留。

4.2.1 FFN:4× 扩张 + GELU 激活

处理阶段最容易被低估的子模块是 attention 后面那一段前馈神经网络(Feed-Forward Network, FFN)。讲师 Lecture 10(chunk #128-#129)描述得很具体:

「We have a feed-forward neural network. That's essentially an expansion and a contraction block. The inputs are with dimension 768, we have a hidden layer whose dimensions are four times the input dimension, and then we contract it back to the output layer. The output layer has the same dimensions as the input which is 768. The activation generally preferred is GELU. The way it differs from ReLU is that ReLU's negative entries are fully zero. GELU's negative entries are not fully zero — it's something smoother. This has proven to be a bit better experimentally compared to ReLU when training language models.」

把这一段拆解开看:FFN 把 token 表征从 768 维拉到 3072 维做非线性变换,再压回 768。这一"拉宽 → 压窄"的 bottleneck 设计被认为是事实存储发生的地方——后续机制可解释性研究(如 Anthropic 2024 的 Sparse Auto-Encoder 工作)就主要在 FFN 的中间 3072 维上做特征分解。这条线本教材不展开,但你应该知道:attention 负责"token 之间互看",FFN 负责"每个 token 内部做计算"——分工明确。

💡 讲师埋下的伏笔:你会在 Module 2-3 看到,diffusion 模型的"去噪 U-Net" / "DiT"(Diffusion Transformer)里这 6 个零件几乎原样存在——只不过 attention 不再 mask 未来、loss 不再是分类、并且会多一个"时间步 embedding"的额外注入通道。把这 6 个零件刻进脑子,后面 80% 的工作就完成了。

4.3 维度守恒:768 一路保到底

讲师 Lecture 10(chunk #126)反复强调一个"工程师品味":

「We started with an embedding size of 768. ... layer normalization preserves it. The attention block preserves it. Dropout preserves it. ... The output of the transformer block has the same dimensions as the input.」

这种"hidden size 全程不变"的设计极重要——它让 Transformer block 可以无限堆叠而不需要重新对齐维度,也让残差连接的相加始终合法。这是 ARM 能 scale 到 96 层、几百 B 参数的工程基础。

4.4 输出阶段(output stage):投到 vocabulary

讲师 Lecture 10(chunk #134-#136)画完最后一块:

「Once we come out of the transformer block, we reach the final layer which is the output layer. ... we apply layer normalization, and then there's the output head. This is very important and we need to understand this also if we want to understand diffusion language models, because this thing also changes.」

output head 做的事是:把每个 token 的 768 维向量线性投影到 vocab_size 维(通常 50,000–100,000),得到每个词的 logit;softmax 之后就是一个 vocabulary 上的概率分布。训练时拿真实下一个 token 的 id 算交叉熵,推理时按这个分布采样下一个 token。

⚠️ 讲师特别提醒:这个 output head 在 diffusion LM 里会被改造。Diffusion LM 不预测"下一个 token",而是预测"每个被 MASK 的位置原本是什么 token"——形状一样、语义不同。这是 80% / 20% 分界线的一个具体位置。

4.5 训练循环:从 TinyStories 一步步喂数据

讲师 Lecture 11(chunk #155)给了 ARM "from scratch" 训练流水线的完整步骤,本教材后续章节都会按这个范式走:

「If you look at the pipeline now, it's as follows: (1) we get the TinyStories data. (2) we tokenize it. (3) we create input and output pairs. (4) we pass the input sequences through this architecture. (5) we get the output. (6) we find the loss between the predictions and the targets. (7) we update the parameters. Then we get a new batch and this loop continues. That's pre-training of language models.」

讲师 Lecture 10(chunk #135-#136)专门示范了"一个序列里其实有多个训练样本"这个工程细节——用 "every effort moves you" 这 4 个 token 举例:

  • input 1 = `every`,target 1 = `effort`
  • input 2 = `every effort`,target 2 = `moves`
  • input 3 = `every effort moves`,target 3 = `you`
  • input 4 = `every effort moves you`,target 4 = `forward`(假设)

所以一个长度 $L$ 的训练序列在 AR 模式下产生 $L$ 个监督样本,且所有 $L$ 个监督的前向计算可以在一次 Transformer pass 里并行算完——这就是 teacher forcing 的工程价值。对照 diffusion 训练,你会看到 diffusion 一次只能用一个 $t$(一个 noise level),监督样本利用效率结构性不同。

🛠️ 讲师对学习态度的强调(chunk #5,呼应 Karpathy 那条箴言):「我会展示我自己是怎么学的,包括我直接跟 Gemini 对话的过程。从零开始学某件事,你会知道自己的知识缺口在哪里——这是真正搞懂的方式。」请你跟着这本教材的每一章都动手写一段代码或推一遍公式。看视频 / 看 PDF 是被动接收,"复现"才是真正的理解检验。

五、AR 的工程优势:为什么文本死守它

到这里你可能要问:既然图像、视频都跑了,文本死守 AR 是不是单纯的惯性?讲师没明说,但答案在源码细节里——AR 在 语言这个特定模态上有几个独特工程优势:

  1. 训练并行 + 推理 KV-cache:训练时用 causal mask,所有位置的 next-token loss 一次前向就算完(teacher forcing)。推理时 KV cache 让每步只算新 token 的 query 和 attention,已生成 token 的 key/value 复用——这让 AR 推理的每步成本是 $O(L)$ 而不是 $O(L^2)$。换成 diffusion,每步必须把所有位置的 attention 重算一遍,KV cache 这套加速无法直接套用。
  2. 文本天然是离散有序序列:和图像不同,文本的 token 顺序是语义本身的一部分——「猫追老鼠」和「老鼠追猫」不一样。AR 的"左→右"假设刚好贴合阅读 / 书写习惯,也贴合人类自然语言生成的物理过程(说话时一个词接一个词)。
  3. scaling law 验证完毕:从 GPT-1 到 GPT-4,AR + Transformer 已经把"参数 / 数据 / 算力 三轴 scaling"摸透了——Chinchilla 给出最优配比、MoE 给出参数稀疏化路线、long context 用 RoPE / ALiBi 解决。换范式意味着重新趟一遍 scaling law,这是巨大的工程成本,没有公司愿意承担这个 R&D 风险。
  4. 评测体系成熟:MMLU / HumanEval / GSM8K 这一整套 benchmark 都是为"prompt → 续写答案"的 AR 范式设计的。Diffusion LM 需要同时证明"我能跑这些 bench、并且跑得不差",再加证一些 AR 做不到的(infilling、并行 decoding、可控性)。这是双倍举证负担。
🧭 这一节其实是"反方辩护":本章题眼问的是"为什么图像投降了语言没投降"。一种廉价答案是"惯性",但讲师拒绝廉价答案——AR 在语言模态上确实有结构性优势,这些优势不是 diffusion LM 喊几句就能抹平的。承认这一点,反而让 diffusion LM 真正赢下的地方(infilling / 双向 / 并行)看起来更有分量。

六、AR 的硬限制:reversal curse + 推理慢

但 AR 也有讲师在 Lecture 5 一并列出的两个真正会撞墙的硬限制——它们也是后面 diffusion LM 章节反复回来挑战的"敌人"。

6.1 反转诅咒(Reversal Curse)

讲师举的例子非常具体:

「问模型 'Who is Tom Cruise's mother?'——它能答 Mary Lee Pfeiffer。但反过来问 'Who is Mary Lee Pfeiffer's son?'——它经常答不出来。这是 reversal reasoning,AR 模型天生很难做。」

根源在 §3 列的"单向条件"性质——AR 训练数据全是"前文 → 后文",所以 "Tom Cruise" 的 representation 里"嵌入了"妈妈是 Mary Lee 这个事实,但 "Mary Lee" 的 representation 里从来没显式地被要求嵌入"儿子是 Tom Cruise"这个反向事实。这不是 scale 能解决的——是训练目标的几何结构决定的盲区。

6.2 推理慢:14 步 vs 75 步

讲师反复拿出的一个具体数字(chunk 群体引用,特别是 Lecture 6):

「生成同样长度的文本,diffusion 大概要 14 步,AR 要 75 步——diffusion 推理快得多。」

这里要小心理解:AR 的"75 步"是序列长度,diffusion 的"14 步"是denoising 步数。它们不是同一种"步"。但单步成本类似的前提下,"步数少一半"直接折算到推理延迟,对实时应用(聊天、代码补全)是重大区别。

🛠️ 实践对齐:14 vs 75 是讲师为了让你建立直觉给的"典型值"。LLaDA-8B 的论文用 32 个 denoising 步在 8B 规模上接近 LLaMA-8B 性能;后来 Mercury 等系统又把这个数压到个位数。请把这两个数字当作"量级",不要当作"基准"。

七、Diffusion 视角:把文本视作 high-dim token space 里的概率分布

这一节是整章最关键的认知跨越——它是后面 20 章的入口。讲师 Lecture 5 给了一个非常简洁的对比:

「图像我们曾经这样想:把图拆成 pixels;扩散模型在 high-dim pixel 空间里学习『有意义的图』的概率分布,然后从中采样。那同样的事可以搬到文本:把文本拆成 token;扩散在 high-dim token 空间里学『有意义文本』的概率分布——『有意义』意思是 grammar 和 logic 都对,它们在 high-dim 里只占一小块小空间。」

把这段话翻译成数学语言:

  • 设 vocabulary 大小为 $V$,序列长度为 $L$。整段文本就是一个向量 $\mathbf{x} \in \{1,\ldots,V\}^L$。
  • 所有可能的 $\mathbf{x}$ 总数是 $V^L$——天文数字($50000^{1024}$)。
  • "合法的"(grammar + logic 都对的)文本只是这个 $V^L$ 空间里极薄的一片。
  • AR:用链式法则一格一格采样这片薄区域。
  • Diffusion:从纯噪声 / 全 MASK 出发,所有位置同时往这片薄区域"游走"——每步都用神经网络同时修正所有位置。
Autoregressive:一字一字往前长 Diffusion:全位并行精修 step 1 从 → step 2 从 前 step 3 有 step 5 从 前 有 座 山 序列长度 = 步数;已生成 token 不可改 step 1 ▒ ▒ ▒ ▒ ▒ step 2 从 ▒ 有 ▒ 山 step 3 从 前 有 座 山 step 5 从 前 有 座 山 步数 ≪ 序列长度;任意位置可重写 • AR:每步只确定 1 个 token,序列长 = 步长 • Diffusion:每步同时降噪所有位置——讲师所称"all positions in parallel" • 关键差别 = 时间复杂度从 O(L) 变成 O(T),T 通常 ≪ L

7.1 "tokenize text → diffusion in high-dim token space" 这一步是真正的范式跳跃

过去很多人误以为 diffusion 只能用在连续数据上(图像、音频)。讲师在 Lecture 5 这段话的厉害之处是:他指出只要你把文本先 tokenize 到一个高维离散空间,"在那个空间里学概率分布"这件事和图像没有本质区别。具体怎么"在离散空间做扩散"——是把 token 替换成 MASK / 用绝对位置 embedding 注入连续 noise / 还是别的招——这是 Module 6 才会展开的事。本章只需要你接受这个认知。

但这里有一个真正的技术难点必须现在就提一句:离散 token 没有"加一点点高斯噪声"这个直观操作。图像里你可以把像素值 $x_t = \sqrt{\bar\alpha_t} x_0 + \sqrt{1-\bar\alpha_t} \epsilon$ 平滑地变化;文本里 token id 是离散的,你没法说"`猫` 加一点 noise 变成 `猫.0173`"——这种东西不存在。MDLM / SEDD 等工作的核心贡献就是定义一种合理的"离散噪声过程"——最简单的版本是"以概率 $p_t$ 把 token 替换成 ``,$p_t$ 随时间从 0 涨到 1"。这就是讲师承诺的"3 个新概念"里的第一个。

7.2 "范式"二字到底意味着什么

讲师在 Lecture 5 用"range"这个词代替"paradigm",但语义一样——同一种"学习数据分布"的任务,可以有多种合法的解法:

  • AR / 链式法则视角:把高维联合分布拆成一连串"条件下一个"。
  • VAE / 变分视角:引入潜变量 z,最大化 ELBO(第 2-3 章)。
  • Diffusion / 去噪视角:定义一条加噪马尔可夫链,训练神经网络反演这条链(第 4-8 章)。
  • Score 视角:直接学 $\nabla_x \log p(x)$,用 Langevin 采样(第 9-10 章)。
  • Flow 视角:学一个连续时间的速度场,用 ODE 把噪声推向数据(第 12-15 章)。

这五条线在数学上有等价 / 互推关系——但工程上、数据上、模态上各自有舒适区。"为什么图像选 diffusion,文本选 AR"就是问"在这个模态上,哪条线的工程账本最好算"。这一问题没有一句话答案,要靠后面 20 章一项项给。

八、关键差异表(讲师在多节课累计给出的 7 条对比)

维度Autoregressive (AR)Diffusion
预测目标下一个 token $p(x_t \mid x_{同时还原所有被 MASK / 加噪的 token
条件方向严格因果(左 → 右)双向(任意位置 attend 任意位置)
推理步数(典型)~75 步 / 75 token~14 步(步数 ≪ 序列长度)
错了能改不能——已生成 token 永久固定可以——后续 denoising 步会修正
infilling 填空不原生支持,需要特殊 prompt 技巧原生支持(被 MASK 的位置自动被填)
reversal reasoning「Mary Lee 的儿子是谁?」常失败双向训练 → 更对称
训练 scaling 经验从 GPT-1 到 GPT-4 已经摸透2024 年后才在 8B 规模开始可比
🧭 读表的正确姿势:这张表不是"diffusion 完胜"或"AR 完胜"。它是 7 个具体的设计权衡点。Module 6(第 19-21 章)会一项一项告诉你:哪些权衡 diffusion LM 已经接近 / 超过 AR,哪些还差距明显。

九、Vizuara 的「80% + 3 个新概念」承诺

讲师 Lecture 7(chunk #73)的核心承诺是整本教材的写作大纲:

「To truly understand diffusion language models, we actually really need to understand how auto-regressive models — I may also call this traditional language models — are built from scratch. ... For diffusion language models, their architecture is 80% similar to traditional language models with the addition of these three concepts.」

这"3 个新概念"是什么?讲师 Lecture 5-7 没在本章揭谜,但在后面章节会逐步给出(教材路线对齐如下):

  1. 前向噪声 / MASK 过程(第 4 章对应图像版本;第 19 章对应离散版本)——把"训练时只看前文"换成"训练时看部分被破坏的全文"。
  2. 时间步条件 / noise schedule(第 4-6 章铺好)——网络必须知道"当前在哪一步降噪"。
  3. 损失函数从 next-token CE 改成 denoising 目标(第 7-8 章;第 20-21 章离散化)——loss 改了,但 backbone Transformer block 不变。
🔭 这一节是整本教材的脚手架预告:Module 1(VAE / ELBO)打数学基础,Module 2(DDPM)讲图像扩散的"完整版",Module 3-4(Score / Flow)给视角升级,Module 5(采样 / latent)讲工程加速,Module 6(离散 / 语言)才回到 Karpathy 的那个问题。你现在在第 1 章,距离回答题眼还有 20 章。

十、为什么选 Vizuara 这门课作主线?

讲师 Dr. Raj Dandekar 在 Lecture 1(chunk #5)的自我介绍里给出了这门课的"出身":

「Hello everyone, this is Dr. Raj Dandekar. I'm very excited to present this learning material. ... when I started thinking about diffusion language models, I thought it was very difficult and the initial phase took a very long amount of time to really understand what's going on. But the final implementation, building it fully from scratch, comparing it with auto-regressive models, was fairly straightforward.」

本教材选 Vizuara《Diffusion Language Models from Scratch》(21 lectures)做主源而不是任何一篇综述,有三个理由:

  1. "from scratch" 写代码——每个公式都对应一段 PyTorch;不是空谈架构图。这与 Karpathy 的 nano-GPT 系列同源。
  2. 正面对比 AR 和 diffusion——不是"假装 diffusion 是全新东西",而是承认 80% 是 ARM,明确告诉你哪 20% 才是创新。
  3. 时间新——录制时间在 2025-2026,涵盖 MDLM / LLaDA / Mercury 等最新工业系统。

副源是 CMU 10-799 S26(Kelly Hu 主讲)和 Vizuara 同系列的图像扩散课。这三条线分别提供:

  • Vizuara LM 课:工程视角,PyTorch 实现,离散文本扩散。
  • Vizuara 图像课:物理直觉(前向扩散 ↔ 热力学)、概率分布游走的隐喻。
  • CMU 10-799:数学严谨度(ELBO 推导、Score Matching 几何),称变分技巧为"史上最伟大的数学技巧"。
📺 Vizuara《Diffusion Language Models from Scratch》Lecture 5(2:23 处)——讲师 Dr. Raj Dandekar 复述 Karpathy 的核心追问:"why text prefers AR but image / video prefer diffusion?"

十一、读者地图:从这一章去哪

读完这一章你应该不会写任何 diffusion 代码——这是预期的。这一章的产出是研究品味和结构骨架,而不是技术细节。下面是接下来的 reading path:

  • 立刻去:第 2 章 VAE:把数据压成「潜空间」再生成。理由:DDPM 本质上是 T 步 hierarchical VAE,跳过 VAE 直接学 diffusion 会丢掉一整条数学骨架。
  • 跟着去:第 3 章 ELBO:似然的下界。理由:ELBO 是后面所有 diffusion 损失函数的母模板。
  • 之后:第 4-8 章 DDPM 完整推导;第 9-11 章 Score / SDE 视角升级;第 12-15 章 Flow Matching 与 Consistency;第 16-18 章采样器与 latent diffusion;第 19-21 章回到本章题眼——离散扩散与语言模型。
🟡 教材外补充(讲师没明说但你应该知道):
  • 图像生成投降给 diffusion 的时间点是 2020-2022 年——DDPM(Ho et al. 2020)→ DDIM(Song et al. 2020)→ Imagen / DALL·E 2 / Stable Diffusion(2022)。PixelCNN / PixelRNN 那种像素级 AR 模型已彻底淘汰。
  • 文本扩散的真正工业化要到 2024-2026 年——MDLM(Sahoo et al. 2024)→ LLaDA-8B(Nie et al. 2025)→ Mercury(Inception Labs 2025)。8B 规模上才接近同尺寸 LLaMA,更大规模还在追。
  • "AR 是惯性还是技术必然"这个问题,目前学界没有共识。本教材给出的工作假设是:AR 在 KV-cache + scaling law 上的 8 年积累不是几篇 paper 能短期追平的;diffusion LM 真正的杀手锏可能是 infilling / 控制 / agentic 任务里的"非自回归"用法,而不是在普通对话上直接换掉 AR。
本章六个必须记住的锚点
  1. 题眼问题(Karpathy + Dr. Raj 双源):「Why has language stuck with AR while images and video surrendered to diffusion?」——本教材剩下 20 章的所有公式都是这个问题的素材。
  2. 研究方法论锚点:好研究始于反直觉的问题;"from scratch" 的学习路径会暴露你知识缺口——这是 Karpathy 的箴言,也是本教材的态度。
  3. AR 的形式化定义:$p(x_1,\ldots,x_T)=\prod_t p(x_t\mid x_{
  4. ARM 三阶段骨架:input(tokenize + embedding)→ processor($N$ 个 Transformer block,每个含 LN / Attention / Dropout / Residual / FFN / Dropout-Residual 共 6 个零件)→ output(LayerNorm + 投到 vocab 算交叉熵)。维度 768 全程不变。这套骨架后面 20 章会原样复用。
  5. AR 的两个真撞墙限制:reversal curse("Mary Lee 的儿子是谁?")+ 推理慢(同样长度文本,AR ~75 步,diffusion ~14 步)。
  6. diffusion 视角的认知跳跃:把文本 tokenize 到 high-dim token space,"在那个空间里学概率分布"这件事和图像没有本质区别——"why should images and video generation models have all the fun?"(Sahoo et al., MDLM 2024)。
  7. "80% + 3" 承诺:diffusion LM = ARM × 80% + 3 个新概念。所以学 diffusion LM 不可能跳过 ARM——这是本教材为什么花前 8 章铺数学和 DDPM、Module 6 才回到语言的根本原因。