通过连续深度批处理实现循环语言模型的深度自适应推理

·

研究论文 · 2026/09/28

循环语言模型的一个主要优势是深度自适应推理:通过以可变次数循环共享层块,模型可以对“简单”token使用较少计算,对“困难”token使用较多计算。然而,不同循环次数的token无法共享统一的前向传播,因此无法由vLLM等标准批处理系统处理。深度自适应推理的实际价值取决于批处理能否高效实现。我们提出了首个通过连续深度批处理(CDB)实现深度自适应循环语言模型的高效方法,该方法在循环步骤之间形成新批次。我们的方法动态调度架构中的循环和非循环部分,管理循环KV缓存,并提前预测哪些token将退出循环,以便异步准备批次。在Ouro 1.4B和Huginn 3.5B上的实验表明,完全循环的架构最适合深度自适应推理,因为循环核心之外的大型非循环层(例如token嵌入、LM头和未共享的transformer块)会减慢并复杂化调度。总体而言,CDB实现了估计最大加速的99%,进一步收益主要取决于模型架构和退出行为。

该研究解决了循环语言模型深度自适应推理中批处理效率的关键瓶颈,提出的CDB方法显著提升了推理速度,对高效部署此类模型具有重要实践意义。

A main promise of looped language models is depth-adaptive inference. By looping a block of shared layers a variable number of times, the model can use less compute for "easy" tokens and more for "hard" ones. However, tokens with different numbers of loops cannot share a uniform forward pass and therefore cannot be handled by standard batching systems such as vLLM. The practical value of depth-adaptive inference thus hinges on whether batching can be made efficient. We introduce the first efficient method for depth-adaptive looped LMs via continuous depth batching (CDB), which forms new batches between loop steps. Our method dynamically schedules looped and non-looped parts of the architecture, manages looped KV-caching, and predicts which tokens will exit the loop in advance so it can prepare batches asynchronously. Experiments on Ouro 1.4B and Huginn 3.5B show that fully looped architectures are best suited to depth-adaptive inference, as large non-looped layers outside the recurrent core (e.g., token embedding, LM head, and unshared transformer blocks) slow down and complicate scheduling. Overall, CDB realizes up to 99% of the estimated maximum speedup available, leaving further gains primarily dependent on model architecture and exit behavior.

阅读原文

参与讨论