arXiv:2410.09605cs.LGcs.CL2024-10NeurIPS被引 14

通过梯度流分析揭示Transformer训练中词共现识别的两阶段机制

Training Dynamics of Transformers to Recognize Word Co-occurrence via Gradient Flow Analysis

  • 从随机初始化出发,联合训练注意力矩阵与MLP层,构建耦合动力系统
  • 训练分两阶段:先快速对齐信号,再协同优化提升分类边界至近最小损失
  • 发现梯度自动平衡机制,使各样本损失同步下降,理论证明更可靠

理解Transformer的训练动态对于解释大语言模型的强大能力至关重要。本文研究一个浅层Transformer在识别指定两个词共现任务中的训练过程。与以往工作常采用权重重参数化、注意力线性化、特殊初始化或懒惰区假设不同,本文分析从随机初始化开始同时训练三个注意力矩阵和一个线性MLP层的梯度流动态,并提出基于耦合动力系统的分析框架。我们证明了训练后损失趋近最小值,并刻画了训练后的注意力模型。发现梯度流天然地将训练过程分为两个阶段:第一阶段,线性MLP迅速对齐两个目标信号完成分类,而softmax注意力几乎不变;第二阶段,注意力矩阵与MLP共同演化,扩大分类边界并使损失降至近最小值。技术上,我们证明了梯度流的一个新性质—— extit{自动梯度平衡},该性质使不同样本的损失几乎以相同速率下降,进一步支持了近最小损失的证明。实验验证了理论结果。

原文摘要 · Abstract (English)

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.

Transformer训练动态梯度流

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。