The pursuit of computational efficiency has driven the adoption of low-precision formats for training transformer models. However, this progress is often hindered by notorious training instabilities. This paper provides the first mechanistic explanation for a long-standing and unresolved failure case where training with flash attention in low-precision settings leads to catastrophic loss explosion. Our in-depth analysis reveals that the failure is not a random artifact but caused by two intertwined phenomena: the emergence of similar low-rank representations within the attention mechanism and the compounding effect of biased rounding errors inherent in low-precision arithmetic. We demonstrate how these factors create a vicious cycle of error accumulation that corrupts weight updates, ultimately derailing the training dynamics. To validate our findings, we introduce a minimal modification to the flash attention that mitigates the bias in rounding errors. This simple change stabilizes the training process, confirming our analysis and offering a practical solution to this persistent problem. Code is available at https://github.com/ucker/why-low-precision-training-fails.
翻译:追求计算效率推动了低精度格式在训练Transformer模型中的应用。然而,这一进展常因众所周知的训练不稳定性而受阻。本文首次针对一个长期未解的失败案例给出机制性解释:在低精度设置下使用Flash Attention训练会导致灾难性的损失爆炸。我们的深入分析表明,这一失败并非随机现象,而是由两个相互交织的因素共同导致:注意力机制中相似低秩表示的出现,以及低精度算术固有的偏向性舍入误差的累积效应。我们证明了这些因素如何形成误差累积的恶性循环,破坏权重更新,最终彻底扰乱训练动态。为验证我们的发现,我们对Flash Attention进行了最小化修改,以减轻舍入误差的偏向性。这一简单改动稳定了训练过程,既证实了我们的分析,也为这一持续存在的问题提供了实用解决方案。代码见https://github.com/ucker/why-low-precision-training-fails。