Stable-SPAM: How to Train in 4-Bit More Stably than 16-Bit Adam
本文提出了一种名为Stable-SPAM的优化器,通过增强的梯度归一化和剪裁技术,在4位精度下训练大型语言模型时,比16位Adam更稳定,并实现了更好的性能。
更新于 2025-02-25。作者:Tianjin Huang、Haotian Hu、Zhenyu Zhang、Gaojie Jin、Xiang Li、Li Shen、Tianlong Chen、Lu Liu、Qingsong Wen、Zhangyang Wang、Shiwei Liu。
中文摘要
本文全面评估了针对4位训练提出的几种优化器,发现低精度位数会加剧对学习率的敏感性,并经常导致梯度范数不稳定,在高学习率下引起发散。在这些优化器中,SPAM以其动量重置和尖峰梯度裁剪为特点,在各个位数级别上取得了最佳性能,但难以稳定梯度范数,需要仔细调整学习率。为了解决这些局限性,我们提出了Stable-SPAM,该优化器融合了改进的梯度归一化和裁剪技术。具体来说,Stable-SPAM(1)通过跟踪尖峰梯度的历史最大值自适应地更新裁剪阈值;(2)根据其历史l_2范数统计对整个梯度矩阵进行归一化;(3)从SPAM继承了动量重置,周期性地重置Adam的第一和第二矩,以减轻尖峰梯度的累积。广泛的实验表明,Stable-SPAM有效地稳定了4位LLM训练中的梯度范数,相比Adam和SPAM提供了更优越的性能。值得注意的是,我们使用Stable-SPAM训练的4位LLaMA-1B模型在困惑度方面比使用Adam训练的BF16 LLaMA-1B模型提高了高达2个百分点。此外,当两个模型都在4位下进行训练时,Stable-SPAM达到了与Adam相同的损失,但所需的训练步数仅为后者的一半左右。代码可在https://github.com/TianjinYellow/StableSPAM.git上获取。
英文摘要
This paper comprehensively evaluates several recently proposed optimizers for 4-bit training, revealing that low-bit precision amplifies sensitivity to learning rates and often causes unstable gradient norms, leading to divergence at higher learning rates. Among these, SPAM, a recent optimizer featuring momentum reset and spike-aware gradient clipping, achieves the best performance across various bit levels, but struggles to stabilize gradient norms, requiring careful learning rate tuning. To address these limitations, we propose Stable-SPAM, which incorporates enhanced gradient normalization and clipping techniques. In particular, Stable-SPAM (1) adaptively updates the clipping threshold for spiked gradients by tracking their historical maxima; (2) normalizes the entire gradient matrix based on its historical l_2-norm statistics; and (3) inherits momentum reset from SPAM to periodically reset the first and second moments of Adam, mitigating the accumulation of spiked gradients. Extensive experiments show that Stable-SPAM effectively stabilizes gradient norms in 4-bit LLM training, delivering superior performance compared to Adam and SPAM. Notably, our 4-bit LLaMA-1B model trained with Stable-SPAM outperforms the BF16 LLaMA-1B trained with Adam by up to 2 perplexity. Furthermore, when both models are trained in 4-bit, Stable-SPAM achieves the same loss as Adam while requiring only about half the training steps. Code is available at https://github.com/TianjinYellow/StableSPAM.git.
解读
一句话总结
本文提出了一种名为Stable-SPAM的优化器,通过增强的梯度归一化和剪裁技术,在4位精度下训练大型语言模型时,比16位Adam更稳定,并实现了更好的性能。
问题1:这篇论文想要解决什么具体问题?
- 问题背景:4位精度训练大型语言模型时,由于精度降低,导致梯度敏感性和梯度范数不稳定,容易导致训练发散。
- 现有方案不足:现有的优化器如Adam和SPAM在低精度训练中容易发散,且需要仔细调整学习率。
- 研究目标:提出一种新的优化器Stable-SPAM,以解决低精度训练中的不稳定问题,并提高训练性能。
问题2:论文的核心创新点是什么?
- 技术创新:Stable-SPAM结合了自适应梯度范数(AdaGN)、自适应尖峰感知剪裁(AdaClip)和动量重置(MoRet)技术。
- 方法改进:AdaGN根据历史梯度范数统计数据自适应缩放梯度,AdaClip动态调整剪裁阈值,MoRet定期重置Adam的动量项。
- 优势:与现有方法相比,Stable-SPAM在4位精度训练中更稳定,性能更优。
问题3:实验结果如何验证了方法的有效性?
- 关键实验:在LLaMA模型上进行的各种实验,包括4位精度和16位精度训练。
- 性能提升:Stable-SPAM在4位精度训练中比Adam和SPAM实现了更好的性能,且在16位精度训练中与Adam相当。
- 对比结果:Stable-SPAM在4位精度训练中比BF16 LLaMA-1B模型训练的Adam模型降低了2个困惑度,且在4位精度下训练时,所需的训练步数仅为Adam的一半。
问题4:这个研究的实际应用价值是什么?
- 应用场景:适用于大型语言模型的低精度训练,特别是在资源受限的环境中。
- 实施建议:Stable-SPAM可以与现有的优化器结合使用,以提高低精度训练的稳定性和性能。
- 局限与展望:Stable-SPAM在低精度训练中的性能优势需要进一步在更多模型和数据集上验证。未来研究可以探索Stable-SPAM在其他低精度训练场景中的应用。
来源
机器可读索引:llms.txt