技术总览Technical Overview
自回归(AR)语言模型将文本生成建模为链式条件概率的逐步采样;扩散语言模型(dLM)则将其建模为从全掩码序列到目标序列的迭代去噪过程。两者的根本区别在于:前者是严格的顺序生成,后者允许全局建模与并行揭示。 Autoregressive LMs decompose text generation as a chain of conditional probabilities; diffusion LMs model it as iterative denoising from a fully masked sequence. The former emphasizes sequential generation, the latter global modeling and parallel reveal.
语言生成能否摆脱固定的从左到右的顺序约束,转而优先确定高置信度位置?Can language generation move beyond fixed left-to-right order and prioritize high-confidence positions?
dLM 以随机掩码、双向预测与多步揭示,替代 AR 的单向 next-token prediction。DLLM replaces AR's unidirectional next-token prediction with random masking, bidirectional prediction, and multi-step reveal.
其意义不在于替代 AR,而在于扩展生成范式:天然支持 infilling、全局重评估与可控的揭示顺序。Rather than simply replacing AR, it extends the generation paradigm: naturally supporting infilling, global re-evaluation, and controllable reveal order.
AR 的本质:一条链AR Essentials: A Chain
文本被分解为一条严格有序的决策链:第 i 个词元仅依赖其左侧上下文,信息流严格单向。 Text is decomposed into a strictly ordered decision chain: token i depends only on left context; information flows unidirectionally.
- 训练与推理的目标完全一致:均为 next-token prediction。Training and inference share the same objective: next-token prediction.
- 每一步仅针对当前位置,缺乏全局重评估机制。Each step targets only the current position with no global re-evaluation.
- 生成顺序固定为从左到右,逐词元展开。Generation order is fixed: left-to-right, token by token.
为什么需要 dLMWhy DLLM
生成 N 个词元需要 N 次前向传播。KV Cache 仅能降低单步开销,无法改变串行的本质。Generating 1000 tokens requires ~1000 forward passes. KV cache reduces cost but not the sequential nature.
许多任务天然适合先确定全局结构、再填充局部细节的生成方式。Many tasks benefit from determining global structure first, then filling in details.
训练依赖 ground truth 而推理依赖模型自身输出,二者的分布偏差随步数累积。Training relies on ground truth while inference relies on model output; errors accumulate.
顺序生成范式(AR)Sequential Paradigm (AR)
严格从左到右逐词元生成;一旦某位置出错,后续所有条件分布均受污染。Strictly left-to-right; once an error occurs, all subsequent conditional distributions are affected.
全局揭示范式(dLM)Global Reveal Paradigm (DLLM)
基于全局上下文同时评估所有位置的置信度,优先填充最确定的位置;揭示顺序由模型自行决定。Evaluates confidence across all positions globally; fills highest-confidence positions first; order is dynamically determined.
从连续扩散到离散扩散From Continuous to Discrete Diffusion
图像扩散使用连续高斯噪声;文本不存在自然的连续噪声空间,因此 dLM 以 MASK token 作为离散噪声的替代。 Image diffusion uses continuous Gaussian noise; text has no natural continuous noise space, so DLLM uses MASK as a discrete noise proxy.
| 概念Concept | 连续扩散(DDPM)Continuous (DDPM) | 离散扩散(MDLM / dLM)Discrete (MDLM / DLLM) |
|---|---|---|
| 噪声Noise | 高斯噪声Gaussian | 随机 MASKRandom MASK |
| 去噪目标Denoising target | 预测原始像素Predict original pixels | 预测被 MASK 的词元Predict masked tokens |
| 前向过程Forward | x₀ → xT,越来越模糊x₀ → xT, increasingly blurred | x₀ → xT,越来越多位置被掩码x₀ → xT, more positions masked |
| 反向过程Reverse | 逐步去噪Gradual denoising | 逐步揭示Gradual reveal |
dLM 的训练机制Training: How DLLM Learns to Fill Blanks
Step 1 — 采样 tStep 1 — Sample t
Step 2 — 随机 maskStep 2 — Random mask
Step 3 — 双向前向传播Step 3 — Bidirectional forward
Step 4 — 只在掩码位置算 lossStep 4 — Loss on masked only
单步训练流程示意Single-Step Training Illustration
Step 1 · 采样 tStep 1 · Sample t
从均匀分布采样 t ∼ U[0,1),以此确定 assistant 区域的 mask 比例。Sample t ~ U[0,1) to determine mask intensity for the assistant region.
Step 2 · 随机 mask assistant 区Step 2 · Random mask assistant region
Prompt 区域保持不变;assistant 区域按比例 t 随机替换为 MASK。Prompt stays intact; assistant region is randomly replaced with MASK by ratio t.
Step 3 · 双向前向传播Step 3 · Bidirectional forward
模型以带 MASK 的完整序列为输入,输出所有被掩码位置的词元分布。Model takes the masked sequence as input and outputs classification distributions for all masked positions.
Step 4 — 只在 M 位置算 lossStep 4 — Loss on M positions only
仅在 MASK 位置计算损失,并按 pmask 进行重加权。Non-MASK positions are excluded; MASK positions are weighted by pmask.
和 BERT / AR 的关键区别Key Differences from BERT / AR
BERT 使用固定的 mask 比例(如 15%);dLM 通过连续参数 t 覆盖从低到高的全部损坏强度。BERT uses a fixed mask ratio; DLLM uses continuous t covering all corruption intensities.
AR 仅学习预测下一个词元;dLM 学习同时恢复多个被掩码位置。AR learns only the next token; DLLM learns to recover multiple positions simultaneously.
训练时的 mask → 预测 → 损失计算详细过程Training: Mask → Predict → Loss Computation
Prompt + assistant 完整文本Complete prompt + assistant text
t=0.6 → assistant 区 60% 被 maskt=0.6 → 60% of assistant region masked
双向 forward → 预测所有 M 位置Bidirectional forward → predict all M positions
预测词元Predicted
真实词元Ground truth
损失公式:Loss formula: loss = Σi∈{我,AI,助}i∈{I,AI,assis} CE(predi, targeti) / pmask
非 mask 位置不参与损失计算;pmask 平衡不同 t 下的梯度贡献。Non-mask positions excluded; pmask balances gradient contribution across different t.
交互式训练模拟器Interactive Training Simulator
加权损失公式Weighted Loss Formula
除以 pmask 的目的是平衡不同 t 下的梯度贡献:t 较小时被 mask 的位置少但每个位置更关键,t 较大时反之。 Dividing by pmask balances gradient contributions across different t: when t is small, fewer masks but each position matters more; when t is large, more masks but each should carry less weight.
训练数据格式Training Data Format
| 训练Training | 推理Inference | |
|---|---|---|
| 步数Steps | 1 步 forward1 forward | 多步迭代(steps × blocks)Multi-step (steps × blocks) |
| mask | 随机比例(t 控制)Random ratio (t-controlled) | 全 MASK → 按置信度逐步揭示Full MASK → reveal by confidence |
| 本质Essence | 看到部分信息预测全部Predict all from partial info | 多步迭代逐步补全Iterative step-by-step completion |
推理:从全掩码到逐步揭示Inference: From Full Mask to Gradual Reveal
dLM 的推理本质上是一个迭代去噪过程:将生成区初始化为全 MASK 序列,然后按置信度逐步揭示词元。 DLLM inference is an iterative denoising process: initialize a fully masked sequence, then gradually reveal tokens by confidence.
初始化画布Initialize Canvas
交互式推理模拟器Interactive Inference Simulator
一个 block 的去噪过程(静态版)One Block Denoising Process (Static)
初始Initial
Step 1 — 全序列 forward → 置信度排序 → 揭示 top-kStep 1 — Full forward → confidence ranking → reveal top-k
Step 2 — 再次 forward → 继续揭示高置信位置Step 2 — Forward again → reveal high-confidence positions
Step 3 — 收敛完成Step 3 — Converged
每步揭示的词元数由 remaining / remaining_steps 动态计算,而非固定常数。Tokens revealed per step = remaining / remaining_steps, not a fixed top-k constant.
每步均对全序列做前向传播,而非仅处理当前 block;双向注意力可利用全部已知上下文。Each step processes the full sequence, not just the current block; bidirectional attention leverages all known context.
Block 并行:AR ↔ 全并行的连续旋钮Block Parallelism: AR ↔ Full Parallelism Continuum
block_size 决定了 dLM 的行为更接近自回归还是并行去噪。它并非离散的模式开关,而是质量与速度之间的连续调控旋钮。 block_size determines whether DLLM behaves more like AR or parallel denoising; it's not a discrete mode switch but a continuous knob between quality and speed.
| block_size | 行为Behavior | 速度 / 质量Speed / Quality |
|---|---|---|
| = max_new_tokens | 全序列一次性去噪Global one-shot denoising | 速度最快,质量取决于步数与采样策略Fastest; quality depends on steps & sampling |
| 8 ~ 32 | 分块并行去噪Local block parallelism | 工程实践中常用的折中方案Common engineering trade-off |
| = 1 | 退化为逐词元自回归Degenerates to AR | 速度最慢,但最接近 AR 的严格顺序生成Slowest; closest to strict sequential generation |
A2D:从 AR 到 dLM 的两步转换A2D: Two-Step AR → DLLM Conversion
AR Model
已训练的 AR 权重Pretrained AR weights
1. 关闭因果约束1. Disable causal mask
2. 扩展词表2. Extend vocabulary
DLLM Model
继承 AR 的全部语言知识,仅需微调Inherits all AR knowledge; fine-tune only
- 无需从零训练,AR 的语言知识可直接迁移。No training from scratch; AR knowledge transfers directly.
- 可采用冻结 FFN、仅调 Attention 的低成本微调策略。Low-cost fine-tuning: freeze FFN, tune attention only.
- 核心意义:任何开源 AR 模型理论上均可低成本地转化为 dLM。Implication: any open-source AR model can be converted to DLLM at low cost.
采样与控制:Gumbel-Max、Top-k、CFGSampling & Control: Gumbel-Max, Top-k, CFG
相较 softmax + multinomial,Gumbel-Max 在低精度数值条件下更稳定,适用于推理阶段的离散采样。More stable than softmax + multinomial under low precision; ideal for discrete sampling during inference.
控制采样随机性:0 趋近贪心解码,1 为标准采样。过高则输出散乱,过低则重复。Controls sampling randomness: 0 → greedy, 1 → standard; too high → incoherent, too low → repetitive.
Top-k 截断长尾噪声;CFG 通过有条件与无条件两次前向传播的差值来增强 prompt 引导。Top-k truncates long-tail noise; CFG amplifies prompt constraint via conditional/unconditional forward difference.
Gumbel-Max
CFG
AR 与 dLM 的系统对比AR vs DLLM: Fair Comparison
| 维度Dimension | AR LM | Masked Diffusion LM |
|---|---|---|
| 注意力Attention | 单向(causal)Unidirectional causal | 双向(bidirectional)Bidirectional |
| 生成顺序Generation order | 从左到右,逐词元生成Left-to-right token by token | 按置信度排序,优先填充最确定的位置By confidence; most certain first |
| 训练目标Training objective | next-token prediction | masked-token prediction |
| 推理步数Inference steps | O(N) | O(T),由步数 × block 数决定O(T), fixed steps / block combination |
| 编辑能力Editing capability | 通常需额外机制支持Usually requires extra mechanisms | 天然支持 infilling 与局部补全Native infilling / local completion |
| 训练成本Training cost | 一般需从零训练Usually from scratch | 可从 AR 权重迁移Transferable from AR |
结论并非“dLM 已取代 AR”,而是:dLM 将语言生成从严格的顺序链式过程,扩展为可迭代、可全局重评估的推理过程。 The conclusion is not “DLLM replaces AR”, but: DLLM extends language generation from a strict sequential chain into an iterative, globally re-evaluable inference process.
调参建议Tuning Guidelines
值越小越稳定但越慢,越大越快但对步数与采样策略更敏感。Smaller = slower but stabler; larger = faster but depends more on steps & sampling.
步数过少会导致每步揭示过多,补全质量下降。Fewer tokens revealed per step; too few steps leads to coarse completion.
过高则输出散乱,过低则重复;通常需与 top_k 联合调节。Too high = chaotic; too low = repetitive; usually tuned with top_k.
截断候选词元空间,平衡多样性与生成稳定性。Controls candidate token space; affects diversity and stability.
增强对 prompt 的忠实度,但过高可能引发模式崩塌。Improves prompt fidelity; too high may cause mode collapse.
项目实践结构Project Structure
目录结构Directory Structure
训练 / 推理命令Training / Inference Commands
开放问题与未来方向Open Problems & Future Directions
如何使 block 边界语义化,而非简单的固定长度切分。How to make block boundaries more semantic rather than fixed-length.
能否将 draft/verify 思路与多步去噪结合,进一步压缩推理开销。Can draft/verify be combined with multi-step denoising to reduce inference cost?
文本、图像、音频统一 token 化后,能否共享同一套扩散生成范式。Can text, image, audio share a unified diffusion paradigm after tokenization?
如何以更少的步数与掩码配置,逼近乃至追平 AR 的生成质量。How to match AR quality with fewer steps and mask configurations.
总结Summary
二者并非简单的替代关系:AR 强调顺序一致性,dLM 强调全局建模与迭代修正。 They are not simple substitutes. AR emphasizes sequential consistency; DLLM emphasizes global modeling and iterative refinement.