通过海森矩阵分析揭示变压器模型独特优化机制
What Does It Mean to Be a Transformer? Insights from a Theoretical Hessian Analysis
- 从海森矩阵出发,理论推导自注意力层的数学结构
- 发现其对数据和权重的非线性依赖具有异质性特征
- 解释为何需自适应优化器等特殊训练策略
Transformer 架构已彻底改变深度学习,超越了多层感知机(MLPs)和卷积神经网络(CNNs)。其核心的注意力模块在形式与功能上迥异于其他主流组件——相比之下,Transformer 更常搭配自适应优化器、层归一化、学习率预热等技术。这些外在表现背后的根源及具体作用机制尚不明确。本文通过理论比较损失函数的海森矩阵,深入揭示 Transformer 与其他架构的本质差异。针对单个自注意力层,我们(a)完整推导出 Transformer 的海森矩阵并以矩阵导数形式表达;(b)从数据、权重和注意力矩依赖角度刻画其特性;(c)在此过程中进一步突出其与经典网络海森矩阵的重要结构差异。结果表明,Transformer 中常见的架构与优化选择可追溯至其参数间高度非线性的、异质的数据与权重依赖关系。本研究为理解 Transformer 独特的优化景观及其挑战提供了更深层洞见。
原文摘要 · Abstract (English)
The Transformer architecture has inarguably revolutionized deep learning, overtaking classical architectures like multi-layer perceptrons (MLPs) and convolutional neural networks (CNNs). At its core, the attention block differs in form and functionality from most other architectural components in deep learning--to the extent that, in comparison to MLPs/CNNs, Transformers are more often accompanied by adaptive optimizers, layer normalization, learning rate warmup, etc. The root causes behind these outward manifestations and the precise mechanisms that govern them remain poorly understood. In this work, we bridge this gap by providing a fundamental understanding of what distinguishes the Transformer from the other architectures--grounded in a theoretical comparison of the (loss) Hessian. Concretely, for a single self-attention layer, (a) we first entirely derive the Transformer's Hessian and express it in matrix derivatives; (b) we then characterize it in terms of data, weight, and attention moment dependencies; and (c) while doing so further highlight the important structural differences to the Hessian of classical networks. Our results suggest that various common architectural and optimization choices in Transformers can be traced back to their highly non-linear dependencies on the data and weight matrices, which vary heterogeneously across parameters. Ultimately, our findings provide a deeper understanding of the Transformer's unique optimization landscape and the challenges it poses.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。