知识讲堂

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

流匹配生成模型

扩散模型像醉汉在迷雾中摸索回家,走走停停绕弯路;流匹配则是清醒的人沿导航直线回家——路径更直、步数更少、到达更快。
历史演进

扩散模型虽然生成质量优异,但其弯曲的随机轨迹需要大量采样步数,流匹配的诞生就是为了找到从噪声到数据的更直、更快的确定性路径。

2018
FFJORD与连续正则化流

Grathwohl等人提出FFJORD,将离散的正则化流推广为连续时间形式:用神经网络参数化速度场 $v_t(x)$,通过求解常微分方程 $dx/dt = v_t(x)$ 变换分布。这在理论上极为优雅,但训练时需要通过ODE求解器反向传播(伴随方法),计算代价高昂,难以扩展到高维图像或音频数据。FFJORD奠定了"用ODE做生成"的理论基础,但实用性受限。

2020-2021
得分SDE与概率流ODE的启示

Song等人在NeurIPS 2020提出Score-based SDE框架,将扩散模型和得分匹配统一在随机微分方程下。关键发现是:每个前向SDE都对应一个确定性的概率流ODE,两者生成相同的边际分布。这暗示了一个深刻的可能性——也许根本不需要随机性,确定性ODE路径就足够了。但该工作仍然依赖扩散过程定义的弯曲路径,未能找到最优路径。

2022
Flow Matching的突破

Lipman、Chen等人(Meta AI)在ICLR 2023发表"Flow Matching for Generative Modeling",提出了改变范式的条件流匹配(CFM)训练目标。核心突破在于:无需在训练中求解任何ODE,只需对条件速度场做简单的均方误差回归。他们证明了一个关键定理——条件流匹配损失在期望意义下等价于不可计算的边际流匹配损失。这使得CNF的训练复杂度降至与扩散模型完全相同,同时路径可以自由选择为直线(最优传输路径)。几乎同时,Liu等人独立提出Rectified Flow,使用线性插值 $x_t=(1-t)x_0+tx_1$ 定义路径,并提出"reflow"迭代矫正技术进一步拉直路径。

2023-2024
工业级验证与全面采用

Stability AI在Stable Diffusion 3中采用流匹配替代传统扩散,图像质量和采样效率均获提升。Meta的Voicebox(2023)率先将流匹配引入语音合成,在零样本TTS上取得突破性结果。随后字节跳动Seed-TTS、微软E2 TTS、CosyVoice等主流语音系统纷纷转向流匹配。在音乐生成领域,Stability Audio和后续工作也采用此框架。流匹配从理论创新迅速成为音频、图像乃至视频生成的事实标准。

2025-2026
蒸馏加速与流式部署

如FlashTTS [31]所示,流匹配与蒸馏技术结合实现极低步数(1-4步)的高质量生成。PianoKontext [9]展示了流匹配在音乐表现力渲染中的应用。当前研究聚焦于一步生成的质量保持、离散数据上的流匹配扩展、以及与自回归模型的统一框架。

核心思想
训练神经网络预测从噪声到数据的速度场,沿确定性ODE直线路径生成样本,比扩散模型路径更直、步数更少、训练同样简单。
数学结构

流匹配的核心是学习速度场 $v_\theta(x,t)$,定义从噪声 $p_0=\mathcal{N}(0,I)$ 到数据 $p_1$ 的ODE:$\frac{dx_t}{dt}=v_\theta(x_t,t),\; t\in[0,1]$。直接匹配边际速度场不可行,因为它需要知道所有数据点的贡献。条件流匹配(CFM)的突破在于:定义条件概率路径 $p_t(x|x_1)$,对于最优传输线性路径取 $x_t=(1-t)x_0+tx_1$,其条件速度场为常数 $u_t(x|x_1)=x_1-x_0$。训练损失为:$$\mathcal{L}_{\text{CFM}}=\mathbb{E}_{t\sim U[0,1],\,x_1\sim p_1,\,x_0\sim\mathcal{N}(0,I)}\|v_\theta(x_t,t)-(x_1-x_0)\|^2$$其中 $x_t=(1-t)x_0+tx_1$ 是线性插值点。Lipman等人的定理2证明 $\nabla_\theta\mathcal{L}_{\text{CFM}}=\nabla_\theta\mathcal{L}_{\text{FM}}$,即条件损失的梯度等于边际损失的梯度,因此优化条件损失等价于优化不可计算的边际损失。为什么速度目标是 $x_1-x_0$?因为线性路径上任意时刻的瞬时速度恒等于终点减起点,这是直线运动的本质特征。相比扩散模型的得分函数 $\nabla_x\log p_t(x)$(随 $t$ 剧烈变化),恒定速度目标使回归问题更加良态。推理时用Euler法采样:$x_{t+\Delta t}=x_t+\Delta t\cdot v_\theta(x_t,t)$,步长 $\Delta t=1/N$。路径越直,$N$ 可以越小——这是流匹配相比扩散在采样效率上的根本优势。

工作机制

流匹配通过在训练时学习噪声到数据的直线速度场,在推理时沿该速度场做ODE积分来生成样本,整个过程无需随机噪声注入。

Step 1概率路径选择与数据配对

从数据集采样真实样本 $x_1$,从标准高斯采样噪声 $x_0$,构成配对 $(x_0,x_1)$。选择线性插值路径 $x_t=(1-t)x_0+tx_1$,对应欧氏空间中的最优传输路径。为什么选线性而非其他参数化?因为线性路径是两点间的测地线,速度场恒定(无曲率),神经网络只需学习一个与时间无关的方向场,学习难度最低。相比扩散模型中先加噪到纯高斯再沿弯曲路径去噪,线性路径的"信噪比"在时间轴上均匀变化,避免了扩散模型在 $t\to0$ 和 $t\to1$ 附近的数值不稳定。关键参数:$\sigma_{\min}$(路径终点残余噪声,通常 $10^{-5}$)控制路径是否严格到达数据点。

Step 2条件速度场回归训练

均匀采样时间 $t\sim U[0,1]$,计算插值点 $x_t$ 和目标速度 $u_t=x_1-x_0$,训练网络 $v_\theta(x_t,t)$ 最小化MSE损失。网络架构复用扩散模型的成熟设计——图像用DiT/U-Net,语音用Transformer或U-Net处理mel谱。时间 $t$ 通过正弦编码或自适应LayerNorm注入。为什么训练不需要ODE求解器?CFM定理保证对条件速度场的回归在梯度意义下等价于对边际速度场的回归,因此只需标准的前向-反向传播。这使得流匹配的训练代码与扩散模型几乎相同——只需将噪声预测目标 $\epsilon$ 替换为速度目标 $x_1-x_0$,将噪声调度替换为线性插值。实现细节:batch中每个样本独立采样 $t$,梯度累积与扩散训练完全一致。

Step 3ODE采样生成

推理时从 $x_0\sim\mathcal{N}(0,I)$ 出发,用数值ODE求解器沿速度场积分到 $t=1$。最简单的Euler法:x = torch.randn_like(target_shape) # x_0 for i in range(N): t = i / N x = x + (1/N) * model(x, t, condition) # Euler step(Midpoint、Heun、Dopri5)可用更少步数达到相同精度。为什么ODE而非SDE?确定性路径没有随机噪声注入,每一步都朝目标前进不会"走弯路"。实际中Euler法10-50步即可获得高质量结果,而扩散SDE采样器通常需50-1000步。对于语音生成,FlashTTS使用约8步流匹配采样即达到高自然度。关键权衡:步数 $N$ 越大精度越高但延迟越大,需根据应用场景选择。

Step 4路径矫正与蒸馏加速

为将步数压缩到1-4步,采用两类技术。第一类是Reflow迭代矫正:用训练好的模型生成大量ODE轨迹 $(x_0\to x_1)$,将轨迹端点作为新的配对数据重新训练模型。每轮reflow使路径更直,因为新配对的 $x_0$ 和 $x_1$ 已经被模型"对齐"过。2-3轮后路径接近完美直线,一步生成成为可能。第二类是一致性蒸馏:训练学生模型直接预测ODE轨迹终点,跳过中间步骤。FlashTTS [31]的X-pred均值流蒸馏属此类——教师模型提供多步轨迹作为监督,学生模型学习单步到达。为什么蒸馏对流匹配特别有效?因为原始路径已接近直线,学生只需学习微小曲率修正,而非扩散模型中的大幅路径矫正。

Step 5条件生成与引导机制

实际应用需要条件生成(文本→语音、文本→图像)。将条件 $c$(文本编码、说话人嵌入、乐谱等)注入速度场:$v_\theta(x_t,t,c)$。分类器自由引导(CFG)同样适用:$\tilde{v}=v_\theta(x_t,t,\varnothing)+w\cdot(v_\theta(x_t,t,c)-v_\theta(x_t,t,\varnothing))$,其中 $w$ 是引导强度。训练时以概率 $p_{uncond}$(通常10-20%)随机丢弃条件,使模型同时学习有条件和无条件速度场。PianoKontext [9]通过此机制将简洁的演奏上下文编码为条件,引导流匹配生成富有表现力的钢琴音频。Voicebox则用掩码条件实现语音编辑和风格迁移——将已知音频区域作为条件,让模型填充被掩码的区域。

长远价值

流匹配已成为2024-2026年生成模型的主流范式。Stability AI的SD3用它生成图像,Meta的Voicebox/AudioBox用它生成语音和音效,字节Seed-TTS、微软E2 TTS、阿里CosyVoice均基于此框架。其训练简单性(与扩散等价)、采样高效性(步数少5-10倍)和理论优雅性(最优传输连接)使其在未来数年仍将是生成建模的核心框架。视频生成领域也在快速采用。

前沿动向

当前热点:(1) 1-2步生成的质量保持与多样性维持问题;(2) 离散数据(文本、代码)上的流匹配扩展(如Flow Matching on discrete state spaces);(3) 流匹配与自回归的统一框架探索;(4) 高分辨率长视频中的时空流匹配架构设计;(5) 最优传输耦合在高维空间的可扩展近似算法。

工程·思维 第二讲

实时管线延迟预算

历史演进

当AI系统从离线批处理走向实

核心思想
工作机制
长远价值
前沿动向

往期讲解档案 106 个知识点

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