知识讲堂

← 返回日报
算法理论 第一讲

无分类器引导

历史演进

扩散模型的条件生成需要将采样过程引向目标条件(文本、类别、说话人身份),但早期方法依赖额外训练的分类器,无分类器引导(CFG)通过一个极简的训练技巧彻底消除了这一依赖,成为现代生成式 AI 的基石技术。

2015-2020
扩散模型条件生成的早期困境

Sohl-Dickstein 等人(2015)提出扩散概率模型时,条件生成能力极为有限。同期 GAN 通过条件拼接(Conditional GAN, Mirza & Osindero 2014)实现可控生成,但扩散模型的迭代去噪过程缺乏自然的条件注入点。2020 年 Ho 等人的 DDPM 复兴了扩散模型,在无条件图像生成上取得突破,但如何让模型"听从指令"仍是核心短板。将条件信息简单拼接到输入或通过交叉注意力注入,虽然可行,但生成结果对条件的遵循度(fidelity)远不及 GAN。

2021
分类器引导的突破与代价

Dhariwal 与 Nichol 在里程碑论文 "Diffusion Models Beat GANs on Image Synthesis"(NeurIPS 2021)中提出分类器引导(Classifier Guidance):在各噪声水平的数据上训练一个独立分类器 $p_\phi(c|x_t)$,利用其梯度 $\nabla_{x_t}\log p_\phi(c|x_t)$ 在每步去噪时将采样推向目标类别。这一方法首次让扩散模型在 ImageNet 上全面超越 BigGAN,证明了"引导"思路的巨大潜力。但代价显而易见:需要额外训练一个在所有噪声水平上都有效的分类器,训练成本高;且分类器只能处理离散类别标签,难以扩展到自由文本等复杂条件。

2022
无分类器引导的诞生

Ho 与 Salimans 在 "Classifier-Free Diffusion Guidance"(首发于 NeurIPS 2021 Workshop,正式发表于 2022)中提出了一个优雅到令人惊叹的替代方案:训练时以概率 $p_{uncond}$(通常 10%-20%)随机将条件替换为空标记 $\varnothing$,使同一个模型同时学会条件预测 $\epsilon_\theta(x_t, c)$ 和无条件预测 $\epsilon_\theta(x_t, \varnothing)$;推理时,通过线性外推两者之差来放大条件信号。无需额外分类器,无需修改模型架构,仅需改动数据加载逻辑和采样公式。这一方法迅速被 DALL·E 2(OpenAI, 2022)、Imagen(Google, 2022)、Stable Diffusion(Stability AI, 2022)全面采纳,成为条件扩散模型的标准配置。

2023-2024
从图像到全模态扩展

CFG 从图像生成扩展到视频(Make-A-Video、Sora)、音频(AudioLDM、MusicGen)、语音合成(VoiceBox、VALL-E、F5-TTS)和 3D 生成(DreamFusion 中的 SDS 损失本质上依赖 CFG)。实践中发现引导尺度 $w$ 需要精细调节,催生了动态引导调度和负提示(Negative Prompting)等实用改进。

2025-2026
流匹配时代的 CFG 演化

随着流匹配取代传统扩散成为主流范式,CFG 被自然移植但行为出现微妙差异。论文 [30] 提出联合残差重加权(Joint Residual Reweighting),针对流匹配 TTS 中文本条件与说话人条件的不同引导需求分别调控,解决了多条件场景中单一 $w$ 无法兼顾的问题。

核心思想
训练时随机丢弃条件,让一个模型同时学会"有条件"和"无条件"生成;推理时放大两者差异,使生成结果更忠实于条件——无需额外分类器,一个模型搞定一切。
数学结构

扩散模型条件生成的核心是得分函数。贝叶斯定理给出分解:$\nabla_{x_t}\log p(x_t|c) = \nabla_{x_t}\log p(x_t) + \nabla_{x_t}\log p(c|x_t)$,其中 $x_t$ 是第 $t$ 步噪声样本,$c$ 是条件。右侧第二项是隐式分类器梯度。分类器引导直接用外部分类器估计该项。CFG 的关键洞察是将其改写为两个模型已知量之差:$\nabla_{x_t}\log p(c|x_t) = \nabla_{x_t}\log p(x_t|c) - \nabla_{x_t}\log p(x_t)$。代入并引入引导尺度 $w$,得到核心公式:$$\tilde{\epsilon}_\theta(x_t, c) = \epsilon_\theta(x_t, \varnothing) + w \cdot \big[\epsilon_\theta(x_t, c) - \epsilon_\theta(x_t, \varnothing)\big]$$ 其中 $\epsilon_\theta(x_t, c)$ 是条件噪声预测,$\epsilon_\theta(x_t, \varnothing)$ 是无条件预测(训练时条件被替换为空标记),$w$ 是引导尺度。当 $w=1$ 退化为标准条件生成;$w>1$ 放大条件信号。从分布角度,这等价于采样自修改后的分布 $\tilde{p}(x|c) \propto p(x)^{1-w} \cdot p(x|c)^w$,即对条件后验做指数加权——分布变得更尖锐,集中在高条件似然区域,牺牲多样性换取保真度。负提示将 $\varnothing$ 替换为负面条件 $c_{neg}$:$\tilde{\epsilon} = \epsilon_\theta(x_t, c_{neg}) + w \cdot [\epsilon_\theta(x_t, c) - \epsilon_\theta(x_t, c_{neg})]$,直观含义是"远离负面、靠近正面"。多条件场景的一般形式为 $\tilde{\epsilon} = \epsilon_\varnothing + \sum_i w_i(\epsilon_{c_i} - \epsilon_\varnothing)$,各条件可独立控制引导强度。

工作机制

通过训练时的条件随机丢弃让单一模型内化两种生成模式,推理时利用两者的差异向量作为隐式引导信号,控制生成的条件遵循程度。

Step 1条件丢弃训练(Conditional Dropout Training)

①做什么:在标准条件扩散/流匹配模型训练中,以概率 $p_{uncond}$(通常 0.1-0.2)将条件 $c$ 替换为空标记 $\varnothing$(全零向量或特殊 token)。模型在同一训练过程中同时优化条件预测和无条件预测。②为什么这样设计:这是 CFG 最精妙之处——避免了训练两个独立模型或额外分类器。当条件被丢弃时,模型被迫仅依赖数据边际分布预测,自然学会了无条件生成。$p_{uncond}$ 是关键超参数:过高(如 0.5)会严重削弱条件学习能力,过低(如 0.01)则无条件预测质量差,引导效果不佳。③关键细节:对于文本条件,$\varnothing$ 通常是空字符串经文本编码器后的嵌入向量;对于多条件输入(文本+图像+说话人),可独立丢弃各条件,产生 $2^n$ 种组合,但训练成本随条件数指数增长,实践中常只丢弃全部或不丢弃。

Step 2双路前向推理(Dual Forward Pass)

①做什么:推理时每个去噪步执行两次前向传播——一次输入真实条件 $c$,一次输入空标记 $\varnothing$——分别得到 $\epsilon_\theta(x_t, c)$ 和 $\epsilon_\theta(x_t, \varnothing)$。②为什么这样设计:这是 CFG 的主要计算代价——推理 FLOPs 翻倍。但相比训练额外分类器的方案,这是训练简单、推理略贵的优雅权衡。③关键细节:实践中将条件和无条件输入在 batch 维度拼接,一次前向得到两个输出再拆分。在 GPU 上,当模型受显存带宽而非算力限制时(大模型常见情况),batch 合并几乎不增加

长远价值
前沿动向

往期讲解档案 122 个知识点

2026年06月25日MVDR波束成形MVDR BeamformingSpatial FilteringCovariance Estimation
2026年06月24日神经缩放定律Scaling LawsCompute-Optimal TrainingPower Law
2026年06月23日最小贝叶斯风险解码Minimum Bayes RiskDecision TheoryHypothesis Selection
2026年06月23日PID控制与生成调控PID ControllerFeedback ControlClosed-loop Generation
2026年06月22日生成模型评估度量Frechet Inception DistanceGenerative EvaluationFeature Statistics
2026年06月21日浮点量化收缩偏差FP4 TrainingShrinkage BiasLow-Precision Arithmetic
2026年06月21日模型上线仿真Deployment SimulationShadow TestingOffline Evaluation
2026年06月20日现代联想记忆Hopfield NetworkAssociative MemoryEnergy-Based Model
2026年06月19日离散扩散语言模型Discrete DiffusionAbsorbing StateConcrete Score
2026年06月18日循环变换器架构Looped TransformerWeight TyingAdaptive Computation
2026年06月17日韵律建模演进Prosody PredictionF0 ModelingDuration Prediction
2026年06月16日说话人日志Speaker DiarizationSpeaker EmbeddingEEND
2026年06月15日偏好对齐优化Preference OptimizationDPOReward Modeling
2026年06月14日多令牌并行预测Multi-Token PredictionSpeculative DecodingParallel Decoding
2026年06月13日流匹配生成模型Flow MatchingRectified FlowOptimal Transport Path
2026年06月13日实时管线延迟预算Latency BudgetPipeline OrchestrationTime-to-First-Token
2026年06月12日MoE路由机制Mixture of ExpertsSparse GatingRouter Design
2026年06月11日连续自回归生成Continuous AutoregressiveLatent PredictionAudioVAE
2026年06月10日KV缓存压缩KV Cache CompressionToken EvictionAttention Sparsity
2026年06月09日浏览器端模型推理WebGPUBrowser InferenceClient-side ML
2026年06月02日残差向量量化Residual Vector QuantizationAudio TokenizationNeural Codec
2026年05月31日彩色噪声扩散采样Colored NoiseSpectral BiasSDE Solver
2026年05月31日算子融合编译原理Kernel FusionOperator Fusiontorch.compile
2026年05月20日AI生成内容溯源 (7 chars) ✓Content ProvenanceC2PASynthID
2026年05月19日推理委托设计模式 (8 chars) ✓ Let me now write the full content for both topics. Actually, I realize I should double-check: is "Runtime Abstraction" or "Delegate Pattern" too close to any covered keyword? Looking at the list: Cluster Scheduling, Co-design, Collective Communication, Computational Expressiveness, CUTLASS... No, none of these overlap. OK, let me finalize and write everything out. Let me reconsider the engineering topic one more time. The title "推理委托设计模式" is good but maybe I should make it even more specific and interesting. What about focusing on the "graph partitioning" aspect - how ML runtimes decide which operations to delegate to which backend? This is a more specific and technically interesting angle. No, I think the broader "delegate pattern" is better because it covers the full picture and is more useful to the reader. Let me write it all out now. For the engineering topic, let me think about the history: - Early days: frameworks were monolithic (Caffe, early TensorFlow) - TensorRT (2017): NVIDIA's specialized inference engine, initially standalone - ONNX Runtime (2019): Microsoft introduced "Execution Providers" - the first major delegate-like abstraction - TFLite delegates (2018-2019): TensorFlow Lite introduced delegate API for GPU, NNAPI, etc. - ExecuTorch (2023-2024): PyTorch's answer to edge inference with a clean delegate API - 2025-2026: MLX delegate, Qualcomm AI Engine Direct delegate, etc. This is a rich history. Let me write it up. Actually, I want to make sure I have the dates right: - TensorRT was first released around 2016-2017 - ONNX was announced in 2017 - ONNX Runtime was open-sourced in 2018-2019 - TFLite was released in 2017, delegates came later - ExecuTorch was announced at PyTorch Conference 2023 OK, let me write everything now. I'll be thorough. One more thought: for the MATH section of the engineering topic, I could discuss the graph partitioning problem formally, or I could discuss the cost model for deciding whether to delegate. Let me think... The graph partitioning for delegation can be formalized as: - Given a computation graph $G = (V, E)$ where $V$ is the set of operations and $E$ is data dependencies - And a set of delegates $D = \{d_1, ..., d_m\}$ where each delegate supports a subset of operations $S_i \subseteq V$ - Find a partition $P = \{P_0, P_1, ..., P_m\}$ (where $P_0$ is the fallback/CPU partition) that minimizes total execution time - Subject to: each $
2026年05月17日连续批处理异步化
2026年05月10日连续潜在扩散语言模型Continuous Latent DiffusionNon-autoregressive LMDiffusion Language Model
2026年05月10日零样本跨语言语音克隆Zero-shot Voice CloningCross-lingual TTSIPA Phoneme Representation
2026年05月09日最优传输音频距离Optimal TransportFréchet Audio DistanceRiemannian Metric
2026年05月09日推荐系统推理核内广播优化Intra-kernel BroadcastEmbedding TableRecommendation Inference
2026年05月08日扩散Transformer异常值令牌Outlier TokensDiffusion TransformerAttention Sink
2026年05月08日WebRTC低延迟语音工程WebRTCReal-time AudioJitter Buffer
2026年05月07日音素级深度伪造检测原理Phoneme-level Deepfake DetectionSelf-supervised Speech EmbeddingEmotional Speech Synthesis
2026年05月07日AI训练网络协议工程哲学Multi-path Reliable ConnectionRDMA over EthernetCollective Communication
2026年05月05日对抗解纠缠说话人验证Speaker DisentanglementAdversarial TrainingCross-lingual Verification
2026年05月05日LLM推理为何用语言Chain-of-ThoughtLatent ReasoningToken Space
2026年05月01日跨架构知识蒸馏原理Cross-Architecture DistillationDiffusion LMAutoregressive Teacher
2026年05月01日AI评估计算瓶颈工程LLM Evaluation InfrastructureBenchmark SaturationEval Compute Bottleneck
2026年04月29日平衡传输语音增强Schrödinger BridgeStochastic Differential EquationSpeech Enhancement
2026年04月29日深度学习理论形成Deep Learning TheoryLoss LandscapeNeural Tangent Kernel
2026年04月28日语义进度函数原理Semantic Progress FunctionDiffusion TrajectoryNonlinear Denoising
2026年04月28日大模型OCR选型认知OCR BenchmarkModel Selection BiasCost-Performance Tradeoff
2026年04月27日说话人验证核心原理Speaker Verificationd-vectorECAPA-TDNN
2026年04月27日GPU核函数语言选型GPU Kernel EngineeringCuTe DSLCUTLASS
2026年04月26日时长控制TTS原理Duration ModelingProsody ControlAutoregressive TTS
2026年04月26日AI研究价值评估困境Research EvaluationPublication BiasPeer Review
2026年04月25日全双工对话建模原理Full-Duplex DialogueTurn-TakingVoice Activity Detection
2026年04月25日流式TTS文本规范化Text NormalizationStreaming TTSInverse Text Normalization
2026年04月24日离散扩散语言模型原理Discrete DiffusionMasked Diffusion Language ModelAbsorbing Diffusion
2026年04月24日跟进ML研究的认知工程Information OverloadResearch TriageSpaced Repetition
2026年04月23日一致性正则化ASR原理Consistency RegularizationUnified ASRTransducer
2026年04月23日流式TTS文本规范化工程Text NormalizationStreaming TTSInverse Text Normalization
2026年04月22日神经编码器伪影检测Neural Audio CodecArtifact DetectionForensic Residual
2026年04月22日AI研究复现危机工程Reproducibility CrisisML EngineeringExperimental Rigor
2026年04月21日扩散SNR偏差校正原理Signal-to-Noise RatioDiffusion Timestep BiasScore Matching
2026年04月21日论文复现危机根治工程Reproducibility CrisisAblation StudyExperimental Rigor
2026年04月20日音频时序定位原理Temporal GroundingAudio Event DetectionCross-modal Alignment
2026年04月20日论文复现危机根因Reproducibility CrisisBenchmark OverfittingEvaluation Validity
2026年04月19日流匹配对齐原理Flow Matching AlignmentReward Gradient BackpropagationTrajectory Optimization
2026年04月19日分布式训练任务编排Distributed Training OrchestrationCluster SchedulingFault Tolerance
2026年04月18日最优传输信号融合Optimal TransportWasserstein BarycenterTime-Frequency Resolution
2026年04月18日分布式训练任务调度Distributed Training OrchestrationJob SchedulingCluster Resource Management
2026年04月17日扩散语音识别原理Masked Diffusion Language ModelDiscrete DiffusionASR Decoding
2026年04月17日Mel尺度跨文化偏差Mel ScalePsychoacousticsCultural Bias
2026年04月16日音频水印对抗原理Audio WatermarkingSemi-FragilePsychoacoustic Masking
2026年04月16日推测解码草稿树工程Speculative DecodingDraft TreeBlock Diffusion
2026年04月15日对抗流模型原理Continuous Normalizing FlowAdversarial TrainingFlow Matching
2026年04月15日代理状态可观测性工程Agent ObservabilityDistributed TracingState Machine Debugging
2026年04月14日过程奖励模型原理Process Reward ModelStep-level SupervisionReasoning Chain
2026年04月13日离散令牌音源分离Discrete Token ModelingSource SeparationConditional Generation
2026年04月13日超算API工程哲学Distributed Training OrchestrationSupercomputer API DesignFault Tolerance
2026年04月12日信息瓶颈原理演进Information BottleneckVariational IBDisentanglement
2026年04月12日Safetensors格式工程哲学SafetensorsModel SerializationMemory-Mapped IO
2026年04月11日归一化层演进原理Layer NormalizationRMS NormalizationBatch Normalization
2026年04月11日GEMM自调优后端工程GEMM AutotuningTorchInductorCuteDSL
2026年04月10日多令牌预测原理Multi-Token PredictionSpeculative DecodingMedusa Heads
2026年04月10日ML从业者认知校准Calibration BiasCapability IllusionBenchmark Overfitting
2026年04月09日编码器-解码器LM原理Encoder-Decoder LMCross-Attention ConditioningSequence-to-Sequence
2026年04月09日torch.compile归一化优化torch.compileLayerNormRMSNorm
2026年04月08日KV缓存压缩原理KV Cache CompressionRoPE Position EncodingAttention Score Estimation
2026年04月08日音效基础模型工程Sound Effect GenerationFoundation ModelFoley Synthesis
2026年04月07日可验证奖励强化学习Verifiable RewardRLVRProcess Reward Model
2026年04月07日LLM技能退化认知机制Cognitive OffloadingSkill AtrophyDesirable Difficulty
2026年04月06日音素可解释说话人验证Phoneme-aware Speaker VerificationInterpretable BiometricsLocal Acoustic Evidence
2026年04月06日音频幻觉攻击评估Hallucination AttackAudio Language Model ReliabilityAdversarial Probing
2026年04月05日潜在空间推理原理Latent Space ReasoningContinuous RepresentationToken-Free Inference
2026年04月05日mRNA模型极低成本训练Biology Foundation ModelCross-Species TransferLow-Budget Training
2026年04月04日编码器-解码器TTS原理Encoder-Decoder TTSText ConditioningPositional Capacity
2026年04月04日大模型训练的MXFP8工程MXFP8MicroscalingMixed Precision Training
2026年04月03日在线知识蒸馏原理Online DistillationKnowledge TransferStudent-Teacher
2026年04月03日MoE专家并行调度工程Expert ParallelismMixture of ExpertsAll-to-All Communication
2026年04月02日波形潜空间扩散TTSwaveform latent diffusionnon-autoregressive TTSlatent space acoustic modeling
2026年04月02日波形隐空间扩散原理waveform latent spacediffusion TTSVAE audio codec
2026年04月02日LLM量化权重工程weight quantizationLLM compression4-bit quantization
2026年04月02日扩散语言模型离散生成Discrete DiffusionMasked Diffusion Language ModelNon-autoregressive TTS
2026年04月02日LLM后训练库工程演进RLHF engineeringPPO training stabilityreward hacking
2026年04月02日声学证据瓶颈原理Audio Evidence BottleneckAcoustic GroundingAudio Language Model
2026年04月02日状态空间模型音频建模State Space ModelMambaSelective Scan
2026年04月02日实时语音增强工程选型Real-time Speech EnhancementNoise SuppressionStreaming Inference
2026年04月02日对话上下文压缩原理Context CompressionAbstractive SummarizationCross-Attention Fusion
2026年04月02日说话人匿名化工程Speaker AnonymizationVoice ConversionStreaming Inference
2026年04月02日视听语音识别融合Audio-Visual Speech RecognitionLip ReadingViseme
2026年04月02日GPU训练吞吐加速工程MXFP8MoE TrainingExpert Parallelism
2026年04月01日熵驱动多样性生成diversity samplingtypicality biasrepulsion in latent space
2026年04月01日说话人分割工程选型speaker diarizationbenchmark methodologystreaming ASR pipeline
2026年03月31日转向检测联合建模turn-taking detectionvoice activity detectionjoint acoustic-linguistic modeling
2026年03月31日基准测试的系统性失效benchmark contaminationevaluation validityLLM judge reliability
2026年03月31日扩散模型声学生成diffusion modelscore matchingstochastic differential equation
2026年03月31日TTS开源生态竞争open-weight TTStime-to-first-audiomultilingual speech synthesis
2026年03月30日注意力机制变体演进Multi-Head AttentionGrouped Query AttentionMulti-head Latent Attention
2026年03月30日设备端语音推理架构on-device inferenceExecuTorchvoice agent pipeline
2026年03月29日混合自回归流匹配TTSautoregressive semantic tokensflow matching acoustic decoderhybrid TTS architecture
2026年03月29日NCCL超时诊断方法论NCCL watchdog timeoutdistributed training debuggingcollective communication
2026年03月29日混合架构音频表示Mambastate space modelaudio representation learning
2026年03月29日DeepSeek预训练加速工程MXFP8 trainingexpert parallelismMoE pretraining
2026年03月27日说话人验证度量学习speaker verificationmetric learningcurriculum learning
2026年03月27日MX浮点格式加速训练MXFP8microscalingmixed precision training
2026年03月26日TTS模型极限压缩model compressionknowledge distillationTTS on-device
2026年03月26日小模型极限压缩哲学model compressionknowledge distillationquantization
2026年03月25日流匹配生成原理flow matchingrectified flowODE
2026年03月25日神经音频编解码器neural audio codecresidual vector quantizationEnCodec
2026年03月25日推测解码加速推理speculative decodingdraft modeltoken verification