[论文解读] Pre-RMSNorm and Pre-CRMSNorm Transformers: Equivalent and Efficient Pre-LN Transformers
本文提出 Pre-RMSNorm 和 Pre-CRMSNorm 变体的 Transformer 模型,作为标准 Pre-LN Transformer 的等价、更高效版本,通过消除 LayerNorm 中冗余的均值计算实现。通过重新中心主干激活并对手动均值向量进行无损压缩,作者在不损失性能的前提下实现了 1%-10% 的训练与推理加速,统一了 LayerNorm 与 RMSNorm,在理论上等价、功能上完全一致的框架下实现统一。
Transformers have achieved great success in machine learning applications. Normalization techniques, such as Layer Normalization (LayerNorm, LN) and Root Mean Square Normalization (RMSNorm), play a critical role in accelerating and stabilizing the training of Transformers. While LayerNorm recenters and rescales input vectors, RMSNorm only rescales the vectors by their RMS value. Despite being more computationally efficient, RMSNorm may compromise the representation ability of Transformers. There is currently no consensus regarding the preferred normalization technique, as some models employ LayerNorm while others utilize RMSNorm, especially in recent large language models. It is challenging to convert Transformers with one normalization to the other type. While there is an ongoing disagreement between the two normalization types, we propose a solution to unify two mainstream Transformer architectures, Pre-LN and Pre-RMSNorm Transformers. By removing the inherent redundant mean information in the main branch of Pre-LN Transformers, we can reduce LayerNorm to RMSNorm, achieving higher efficiency. We further propose the Compressed RMSNorm (CRMSNorm) and Pre-CRMSNorm Transformer based on a lossless compression of the zero-mean vectors. We formally establish the equivalence of Pre-LN, Pre-RMSNorm, and Pre-CRMSNorm Transformer variants in both training and inference. It implies that Pre-LN Transformers can be substituted with Pre-(C)RMSNorm counterparts at almost no cost, offering the same arithmetic functionality along with free efficiency improvement. Experiments demonstrate that we can reduce the training and inference time of Pre-LN Transformers by 1% - 10%.
研究动机与目标
- 通过建立两者之间的等价性,解决关于在 Pre-LN Transformer 中 LayerNorm 与 RMSNorm 哪个更优的长期争议。
- 消除 Pre-LN Transformer 中的计算冗余,因为归一化本身已隐含均值重中心化,故该步骤本质上是冗余的。
- 提出压缩 RMSNorm(CRMSNorm),作为对零均值向量的无损压缩方法,以进一步提升效率。
- 正式证明 Pre-LN、Pre-RMSNorm 和 Pre-CRMSNorm Transformer 在训练与推理过程中在算术上完全等价。
- 实现 Pre-LN 模型到更高效 Pre-(C)RMSNorm 对应模型的无缝、零成本转换,以支持部署与训练。
提出的方法
- 识别出 Pre-LN Transformer 中主干分支的向量始终经过归一化,因此其均值分量是冗余的,可被移除。
- 通过在归一化前重新中心化主干输入,将 LayerNorm 替换为 RMSNorm,从而在保持模型功能的同时减少计算量。
- 提出压缩 RMSNorm(CRMSNorm),其接收一个 d−1 维向量,将其解压缩为零均值的 d 维向量,并在解压后的向量上应用 RMSNorm。
- 提出 Pre-CRMSNorm Transformer,将 CRMSNorm 应用于零均值激活与参数,实现无损压缩与效率提升。
- 通过数学推导,正式证明 Pre-LN、Pre-RMSNorm 与 Pre-CRMSNorm Transformer 在训练与推理过程中算术等价。
- 在 ViT 与 GPT 模型上实现并基准测试所提出的变体,以验证效率提升与等价性。
实验结果
研究问题
- RQ1是否可以在不损失模型功能或性能的前提下,用 RMSNorm 替换 Pre-LN Transformer 中的 LayerNorm?
- RQ2是否存在一种对零均值向量的无损压缩方法,可进一步提升归一化层的效率?
- RQ3能否在数学上正式证明 Pre-RMSNorm 与 Pre-CRMSNorm Transformer 在训练与推理过程中与 Pre-LN Transformer 算术等价?
- RQ4将 Pre-LN 替换为 Pre-(C)RMSNorm 变体后,实际训练与推理效率提升幅度是多少?
- RQ5在 ViT 与 GPT 等不同模型尺寸与架构中,效率提升的规模如何变化?
主要发现
- 在 ViT 模型上,Pre-RMSNorm 通过在移除冗余均值计算后将 LayerNorm 替换为 RMSNorm,将训练时间减少了 2.36%。
- Pre-CRMSNorm 通过消除重中心化层并使用压缩归一化,在原始 Pre-LN 模型基础上实现了 1.74% 的训练速度提升。
- 在 GPT-3 模型中,Pre-RMSNorm 在较小模型中将推理时间减少了高达 10%,在 GPT-3 XL 和 2.7B 参数变体中,经 int8 量化后观察到 4% 的减少。
- 加速效果在训练与推理中均保持一致,ViT 模型的相对增益为 1%-2.5%,GPT-3 Small 与 Medium 模型为 1.5%-1.8%。
- 在 ViT 中,归一化操作占训练时间的 10%-15%,因此 (C)RMSNorm 带来的效率提升在数据密集型训练流水线中尤为显著。
- 所提方法与现有效率技术(如量化与知识蒸馏)正交,可实现累积性能提升。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。