通过梯度流分析训练 Transformer 识别词共现的动力学
Training Dynamics of Transformers to Recognize Word Co-occurrence via Gradient Flow Analysis
AI总结:
本文研究了浅层 Transformer 在词共现识别任务上的训练动力学,通过耦合动力系统框架分析了从随机初始化同时训练注意力矩阵和 MLP 层的梯度流,发现训练自然分为两阶段并证明了梯度自动平衡性质,最终实现接近最小的训练损失。
摘要:
理解 Transformer 的训练动力学对于解释大语言模型背后的强大能力非常重要。在本研究中,我们探讨了在识别两个指定词共现的任务上训练浅层 Transformer 的动力学。在研究 Transformer 训练动力学的文献中,通常会采用一些简化,如权重重参数化、注意力线性化、特殊初始化和惰性机制。相比之下,我们分析了从随机初始化开始,同时训练三个注意力矩阵和一个线性 MLP 层的梯度流动力学,并通过一个耦合动力系统提供了分析此类动力学的框架。我们确立了接近最小的损失,并刻画了训练后的注意力模型。我们发现梯度流作为一种内在机制,自然地将训练过程划分为两个阶段。在阶段 1,线性 MLP 快速与两个目标信号对齐以进行正确分类,而 softmax 注意力几乎保持不变。在阶段 2,注意力矩阵和 MLP 共同演化,以扩大分类间隔并将损失降至接近最小值。在技术上,我们证明了梯度流的一个新性质,称为梯度的自动平衡,该性质使得不同样本的损失值几乎以相同的速率下降,从而进一步促进了接近最小训练损失的证明。我们还进行了实验以验证我们的理论结果。
英文摘要:
Understanding the training dynamics of transformers is important to explain the impressive capabilities behind large language models. In this work, we study the dynamics of training a shallow transformer on a task of recognizing co-occurrence of two designated words. In the literature of studying training dynamics of transformers, several simplifications are commonly adopted such as weight reparameterization, attention linearization, special initialization, and lazy regime. In contrast, we analyze the gradient flow dynamics of simultaneously training three attention matrices and a linear MLP layer from random initialization, and provide a framework of analyzing such dynamics via a coupled dynamical system. We establish near minimum loss and characterize the attention model after training. We discover that gradient flow serves as an inherent mechanism that naturally divide the training process into two phases. In Phase 1, the linear MLP quickly aligns with the two target signals for correct classification, whereas the softmax attention remains almost unchanged. In Phase 2, the attention matrices and the MLP evolve jointly to enlarge the classification margin and reduce the loss to a near minimum value. Technically, we prove a novel property of the gradient flow, termed \textit{automatic balancing of gradients}, which enables the loss values of different samples to decrease almost at the same rate and further facilitates the proof of near minimum training loss. We also conduct experiments to verify our theoretical results.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。