Library of Layers (LoL): Adaptively Ordering Transformer Layers at Runtime
该论文提出了一种名为Library of Layers (LoL)的架构,通过动态选择Transformer层来提高模型效率和可解释性。
更新于 2026-11-03。作者:Abdellah Rahmani、Sean McLeish、Ang Li、Sanae Lotfi、Pascal Frossard、Micah Goldblum。
中文摘要
计算机程序员将相同的可重用计算原语(例如,条件语句或循环)按不同的顺序链接起来,以实现不同的算法。相比之下,现有的语言模型架构总是以相同的顺序执行其层。我们引入了层库(LoL),这是一种在推理过程中动态排列其层的架构,以解决手头的问题。LoL只有一个超参数,即其全局层库中变换器块的大小,这允许它在参数重用和稀疏性之间无缝过渡,将密集、深度递归和专家混合架构的参数效率和FLOPs效率权衡泛化到一个统一的家族中。我们表明,当在文本数据上预训练时,LoL在所有上述基线中均实现了有竞争力的性能。在合成的数独和迷宫数据上,我们观察到模型采用不同的层排列顺序来实现不同的解决方案策略,并且我们可以干预路由,迫使模型对一个特定的问题实例应用特定的解决方案策略。在多语言自然语言环境中,我们发现LoL根据语言和脚本选择不同的层排列模式。同样,我们在安全数据上训练LoL,并将探测器拟合到其路由输出,发现这些探测器可以以高AUROC区分安全文本和不安全文本。LoL为模型动态构建自己的计算图提供了通往未来的途径,从而实现更高效和可控的推理。
英文摘要
Computer programmers chain together the same reusable computational primitives, for example, conditional statements or loops, but in different orders to implement different algorithms. In contrast, existing language model architectures always execute their layers in the same order. We introduce Library of Layers (LoL), an architecture that dynamically orders its layers during inference to solve the problem at hand. LoL has a single hyperparameter, the size of its global library of transformer blocks, that allows it to transition seamlessly between parameter reuse and sparsity, generalizing the parameter-efficiency and FLOPs-efficiency tradeoffs of dense, depth-recurrent, and mixture of experts architectures in one unified family. We show that LoL achieves competitive performance with all three above baselines when pretrained on text data. On synthetic sudoku and maze data, we observe that the model employs distinct layer orderings to implement different solution strategies, and we can intervene on routing to force a model to apply a specific solution strategy to a problem instance. In a multilingual natural language setting, we find that LoL chooses different layer order patterns based on language and script. Similarly, we train LoL on safety data and fit probes to its router outputs, finding that these probes distinguish safe from unsafe text with high AUROC. LoL provides a path toward a future in which models dynamically compose their own computational graph, enabling more efficient and controllable reasoning.
解读
一句话总结
该论文提出了一种名为Library of Layers (LoL)的架构,通过动态选择Transformer层来提高模型效率和可解释性。
问题1:这篇论文想要解决什么具体问题?
- 问题背景:现有的Transformer语言模型在推理时总是以固定的顺序执行层,这限制了模型的灵活性和效率。
- 现有方案不足:现有的模型架构如MoE和循环Transformer虽然提高了效率,但仍然限制了层的执行顺序。
- 研究目标:设计一个能够动态选择层以适应不同问题的模型,提高效率和可解释性。
问题2:论文的核心创新点是什么?
- 技术创新:LoL通过一个小的路由器从全局Transformer块库中动态选择层,实现参数重用和稀疏性之间的平衡。
- 方法改进:引入了窗口注意力掩码策略,允许不同窗口自适应选择层顺序,同时防止注意力空间不匹配和保持因果性。
- 优势:LoL在保持高效率的同时,提供了模型内部执行路径的可视化,便于控制和解释。
问题3:实验结果如何验证了方法的有效性?
- 关键实验:在多种合成和真实世界数据上进行了实验,包括多语言文本、安全文本、数独和迷宫任务。
- 性能提升:LoL在数独和迷宫任务中学习了不同的层顺序模式,并通过强制执行策略的层顺序来控制模型的策略。
- 对比结果:LoL在各种稀疏性水平上表现与基线模型相当,包括循环Transformer和MoE模型。
问题4:这个研究的实际应用价值是什么?
- 应用场景:LoL可以应用于需要灵活推理和高效计算的场景,如语言模型、数学推理和算法合成。
- 实施建议:通过调整库的大小,可以在参数重用和稀疏性之间进行权衡,以适应不同的应用需求。
- 局限与展望:LoL目前是一个初步探索,未来可以结合测试时学习等技术,进一步提高模型的灵活性和能力。