arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2502.05795cs.LGcs.AI
收藏

深度在大语言模型中的诅咒

The Curse of Depth in Large Language Models

Westlake University(西湖大学);Emory University(埃默里大学);Dalian University of Technology(大连理工大学);University of Surrey(萨里大学);University of Oxford(牛津大学)

Wenfang Sun, Xinyuan Song, Pengxiang Li, Lu Yin, Yefeng Zheng, Shiwei Liu

AI总结:

本文提出LayerNorm Scaling方法,通过缩放输出方差缓解深度诅咒,提升大语言模型的预训练和微调性能。

摘要:

在本文中,我们引入了深度诅咒的概念,该概念强调、解释并解决了现代大语言模型(LLMs)中最近观察到的现象,即几乎一半的层的效果低于预期。我们首先确认了这一现象在最流行的LLM家族中广泛存在,如Llama、Mistral、DeepSeek和Qwen。我们的分析,理论和实证上,确定了LLM中深层无效的根本原因是广泛使用预层归一化(Pre-LN)。虽然Pre-LN稳定了Transformer LLMs的训练,但其输出方差随着模型深度呈指数增长,这不希望导致深度Transformer块的导数成为单位矩阵,因此几乎不贡献于训练。为了解决这一训练陷阱,我们提出了层归一化缩放(LNS),它通过深度的平方根逆来缩放层归一化输出的方差。这种简单的修改减轻了更深层Transformer层的输出方差爆炸,提高了它们的贡献。在广泛的模型大小(130M到7B)上,我们的实验表明,LNS在增强LLM预训练性能方面始终优于先前的归一化和缩放技术。此外,这种改进无缝地转移到监督微调。所有这些收益都可以归因于LayerNorm Scaling使深层层在训练过程中更有效地贡献。我们的代码可在https://github.com/lmsdss/LayerNorm-Scaling获取。

英文摘要:

In this paper, we introduce the Curse of Depth, a concept that highlights, explains, and addresses the recent observation in modern Large Language Models (LLMs) where nearly half of the layers are less effective than expected. We first confirm the wide existence of this phenomenon across the most popular families of LLMs such as Llama, Mistral, DeepSeek, and Qwen. Our analysis, theoretically and empirically, identifies that the underlying reason for the ineffectiveness of deep layers in LLMs is the widespread usage of Pre-Layer Normalization (Pre-LN). While Pre-LN stabilizes the training of Transformer LLMs, its output variance exponentially grows with the model depth, which undesirably causes the derivative of the deep Transformer blocks to be an identity matrix, and therefore barely contributes to the training. To resolve this training pitfall, we propose LayerNorm Scaling (LNS), which scales the variance of output of the layer normalization inversely by the square root of its depth. This simple modification mitigates the output variance explosion of deeper Transformer layers, improving their contribution. Across a wide range of model sizes (130M to 7B), our experiments show that LNS consistently outperforms previous normalization and scaling techniques in enhancing LLM pre-training performance. Moreover, this improvement seamlessly carries over to supervised fine-tuning. All these gains can be attributed to the fact that LayerNorm Scaling enables deeper layers to contribute more effectively during training. Our code is available at \href{https://github.com/lmsdss/LayerNorm-Scaling}{LayerNorm-Scaling}.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑