Model Carving: Training Transformers That Optimize Their Own Topology

LLM PTSAD ML TAVR ARC AI Systems and Hardware MCPKD
机器学习长期以来将模型架构的选择与训练过程分而治之。例如,经典的Transformer模型在每一层都固定采用相同类型、相同顺序的注意力子层(attention sublayer)和多层感知机子层(MLP sublayer),仅优化其中的参数权重。这种结构上的统一性是一种约定俗成的做法,而非基于原理的严谨设计选择,因而很可能并非最优方案:针对特定任务而言,真正最优的架构可能更小、更高效,且远非均匀一致。我们认为,理想情况下,训练过程本身应主动塑造模型的拓扑结构。为此,我们提出了“模型雕刻”(Model Carving)方法——它能在单次训练过程中同步学习Transformer的参数权重及其架构。具体而言,我们为每个子层引入可学习的标量门控(learnable scalar gates),使训练损失函数能够自主地在训练过程中“移除”模型自身的部分组件,从而释放出一个更小、更异构的内部网络。我们在标准Transformer(参数量从1.4亿至27亿)和循环式Transformer(looped Transformer,参数量从1.4亿至13亿)上对模型雕刻进行了预训练评估。结果表明,在同等训练计算量(training compute)下,经雕刻所得的模型所达到的验证损失显著低于密集模型(dense models)——而后者需额外高达1.7倍的计算量才能达到同等性能。此外,雕刻所得模型亦优于同等规模下通过剪枝(pruning)或知识蒸馏(distillation)获得的模型,这表明:面向边缘设备部署的小型化模型,最佳获取方式是在训练过程中直接“雕刻”而成,而非先训练一个大模型再事后压缩。这一优势不仅随模型规模扩大而增强,还能有效迁移到下游任务中,例如少样本学习(few-shot evaluation)与文本生成(generation)。由于被移除的子层在推理时完全不再执行,雕刻后的模型每处理一个token所需的浮点运算量(FLOPs)最多可降低34%,解码速度最高可提升1.6倍,且不以牺牲质量为代价。我们的实验结果表明:模型架构本身,如同权重一样,理应作为可学习变量在训练中动态确定,而非预先固定;而每一个大型Transformer模型内部,其实都蕴藏着一个更小、更快、更强的“精简版”模型,静待被雕刻而出。
Machine learning has largely kept separate the choice of architecture and the process of training. A classic Transformer, for instance, trains a fixed set of attention and MLP sublayers at every layer, in the same order, and optimizes the weights within. This uniformity is a convention rather than a principled design choice, and it is likely suboptimal: the best architecture for a given task may be smaller, more efficient, and far from uniform. We believe that, ideally, training itself should shape the model's topology. To this end, we introduce Model Carving, which learns both a Transformer's weights and its architecture in a single run. By applying learnable, scalar gates to each sublayer, we allow the training loss to remove the model's own components during training -- freeing a smaller heterogeneous network inside. We evaluate Model Carving by pre-training standard Transformers from 140M to 2.7B parameters and looped Transformers from 140M to 1.3B. At equal training compute, carved models reach a lower validation loss than dense models trained with up to 1.7 times more compute. Furthermore, carved models also outperform size-matched models produced by pruning or distillation, suggesting that the best way to obtain small models for edge devices is to carve them during training, not to compress a large one afterwards. This advantage both grows with scale and carries over to downstream tasks such as few-shot evaluation and generation. Because the removed sublayers no longer run, carved models also cost up to 34% fewer FLOPs per token and decode up to 1.6 times faster without cost in quality. Our results show that architecture, like weights, should be learned and not fixed in advance, and that inside every large transformer is a smaller, faster, stronger one waiting to be carved out.
许愿