知识讲堂

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

循环变换器架构

历史演进

循环变换器的根本动因是打破"深度与参数量线性绑定"的限制——既然不是每个输入都需要同等计算量,为何不用同一组权重反复"思考",以固定参数换取可变深度?

1990
循环神经网络确立权重共享范式

Elman(1990)和 Jordan(1986)的循环网络在每个时间步共享同一权重矩阵,本质上就是一种"循环深度"架构:将网络在时间维度展开后,等价于一个所有层权重相同的深层前馈网络。这一设计证明了有限参数可以支撑无限深度的计算,但受困于梯度消失/爆炸问题,其深度利用效率有限。RNN 奠定了"权重复用即计算复用"的基本哲学。

2016
Graves 提出自适应计算时间(ACT)

DeepMind 的 Alex Graves 发表"Adaptive Computation Time for Recurrent Neural Networks",首次将"不同输入应获得不同计算量"形式化。ACT 在每个循环步骤引入一个停止概率 $p_t$,模型学会对简单输入提前停止、对困难输入继续迭代。这是突破性贡献:它不仅将计算深度从超参数变成了可学习量,更揭示了一个深刻洞见——计算资源的最优分配应该是输入自适应的。ACT 的正则化项 $\mathcal{R} = \sum_t R(t)$(残余思考步数之和)为后续所有自适应深度方法提供了模板。

2018
Universal Transformer 将循环引入自注意力

Dehghani 等人(Google Brain/DeepMind)提出 Universal Transformer(UT),将同一 Transformer block 重复应用 $T$ 次,配合 ACT 实现自适应深度。UT 在理论上比标准 Transformer 更具计算通用性——在合理假设下是图灵完备的。它在算法推理任务(如拷贝、排序)和 LAMBADA 语言建模上超越了固定深度 Transformer,证明共享权重加循环可以弥补参数量的不足。UT 的核心创新在于引入 step embedding(循环步编码),让共享层能区分"第几次思考"。

2019
深度均衡模型(DEQ)将循环推至极限

CMU 的 Bai、Kolter 和 Koltun 提出 Deep Equilibrium Models(DEQ),将循环次数推至无穷大:直接求解不动点 $h^* = f_\theta(h^*)$,绕过显式迭代。DEQ 使用 Anderson 加速或 Broyden 方法进行根求解,反向传播通过隐函数定理计算,内存开销为常数 $O(1)$,不依赖循环深度。DEQ 在语言建模(WikiText-103)和图像分割(Cityscapes)上达到与深层网络可比的性能,证明"无限深度的不动点"是一个实用的计算范式。

2021
PonderNet 改进停止机制

DeepMind 的 Banino 等人提出 PonderNet,用几何分布先验替代 ACT 的累积停止机制,使停止决策的概率建模更加原则化,训练更稳定。其核心改进是将停止决策建模为参数化几何分布的采样,并通过 KL 散度正则化约束迭代次数。

2024-2026
循环架构回归大语言模型

随着"测试时计算缩放"成为后 GPT-4 时代的核心范式(OpenAI o1/o3 等思维链模型通过增加推理步骤提升质量),循环变换器获得新生。ALBERT(2019)早已验证了跨层参数共享在 BERT 级模型的可行性,而 LoopCoder(2025)和今日的 LoopCoder-v2、Looped World Models 进一步证明:共享 block 循环可以高效缩放测试时计算,关键挑战转向如何降低顺序循环带来的延迟和 KV-cache 膨胀。

核心思想
循环变换器用同一组参数重复处理输入,每次迭代逐步精炼隐表示,以固定参数量换取按需可调的计算深度,让模型像反复思考一样逐步逼近更优解。
数学结构

设 $f_\theta$ 为参数为 $\theta$ 的 Transformer block。标准 Transformer 有 $L$ 层各自参数 $\{\theta_1,...,\theta_L\}$,总参数量 $L|\theta|$。循环变换器强制 $\theta_1=...=\theta_L=\theta$,参数量恒为 $|\theta|$,深度由循环次数 $T$ 控制。前向传播为迭代映射:$h^{(t+1)} = f_\theta(h^{(t)})$,其中 $h^{(0)}$ 为输入嵌入。为保证收敛性,需要 $f_\theta$ 满足压缩映射条件:存在 $0 < \gamma < 1$,使 $\|f_\theta(x) - f_\theta(y)\| \leq \gamma\|x-y\|$。由 Banach 不动点定理,必存在唯一不动点 $h^* = f_\theta(h^*)$,且收敛速度为几何级数 $\|h^{(t)}-h^*\| \leq \gamma^t\|h^{(0)}-h^*\|$。DEQ 的关键贡献在于梯度计算:通过隐函数定理,不动点处的梯度为 $\frac{\partial h^*}{\partial \theta} = -(I - J_{h^*})^{-1}\frac{\partial f_\theta}{\partial \theta}\big|_{h^*}$,其中 $J_{h^*} = \frac{\partial f_\theta}{\partial h}\big|_{h^*}$ 为不动点处的 Jacobian 矩阵。这避免了对 $T$ 步迭代的反向传播,内存为 $O(1)$。为什么这样定义?因为在不动点处,微小参数扰动 $\delta\theta$ 导致新不动点 $h^*+\delta h$,满足 $h^*+\delta h = f_{\theta+\delta\theta}(h^*+\delta h)$,一阶 Taylor 展开后消去 $h^*=f_\theta(h^*)$ 即得上式。自适应停止通过学习的停止概率 $p_t = \sigma(w^\top h^{(t)} + b)$ 实现,最终输出为加权混合:$y = \sum_{t=1}^{T_{max}} \lambda_t \cdot g(h^{(t)})$,其中 $\lambda_t = p_t\prod_{s=1}^{t-1}(1-p_s)$ 是第 $t$ 步停止的概率(几何分布形式)。正则项 $\mathcal{L}_{ponder} = \text{KL}(\lambda \| \text{Geom}(\beta))$ 约束迭代次数的分布,$\beta$ 控制期望深度。参数效率的压缩比为 $T:1$——$T$ 次循环仅用一份参数。

工作机制

循环变换器将深层 Transformer 的独立层栈替换为共享 block 的重复应用,可选地用自适应停止机制为每个输入动态分配计算量。

Step 1输入嵌入与循环步编码

输入 token 经标准嵌入后,需要额外注入循环步编码(loop-step embedding)。与位置编码(编码 token 在序列中的位置)不同,循环步编码告诉共享 block "这是第几次迭代"。为什么这是必要的?因为所有迭代共享同一组参数,如果没有步编码,$f_\theta$ 在每次迭代中"不知道"自己处于精炼过程的哪个阶段——初次粗加工和末次精调的最优行为截然不同。实现方式通常有两种:(a) 正弦编码,将迭代步 $t$ 映射为与隐藏维度等长的向量加到 $h^{(t)}$ 上;(b) 可学习的步嵌入表,$T_{max}$ 个向量通过查表获得。实践中方式 (b) 在 $T_{max}$ 较小(如 $\leq 32$)时效果更好。

Step 2共享 Block 迭代精炼

核心计算循环将同一 Transformer block 应用 $T$ 次。每次迭代包含完整的多头自注意力和前馈网络计算,但权重完全共享:= embed(x); for t in range(T): h = h + loop_embed[t]; h = transformer_block(h)。阻尼迭代是一个重要的实现细节

长远价值
前沿动向

往期讲解档案 112 个知识点

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