测量Transformer前馈层的真实线性程度,发现其由训练决定而非架构设计。
How Linear Is a Transformer Feed-Forward Block? Per-Block Linear Recoverability Is Learned, Not Architectural
- 用最小二乘法分解前馈层,量化每层的线性可恢复率(R²_lin)
- 不同层线性度差异大,从近线性(>0.99)到强非线性(<0.3)不等
- 线性成分可压缩,低线性层不宜替换,适合模型优化与诊断
Transformer前馈网络(FFN)常被视为非线性计算单元,但其实际非线性程度鲜有量化。本文将每个FFN视为位置无关的输入-输出映射,通过闭式最小二乘法求出其最佳线性逼近,并以残差解释的方差占比(R²_lin)衡量线性可恢复性。在GPT-2、Pythia-160m和llama-160m共十二个模型中,各层的R²_lin表现出显著异质性和非单调性:相邻层间从接近线性(>0.99)到强非线性(<0.3)变化,且与激活函数无关——同宽的GELU模型如GPT-2与Pythia-160m具有截然不同的线性分布,说明线性特性是训练学习所得,非架构固有。对残差进行低秩双线性探测仅能解释少量线性成分,且增益与非线性无关,表明未被恢复的计算为高阶或分布式结构。该度量还可作为定向压缩信号:高可恢复层可大幅替换(如GPT-2早期FFN用8倍少参数实现+0.77困惑度提升),而低可恢复层则提示替换风险。研究还揭示方法论陷阱:训练线性基线在病态变换激活上易欠收敛,因此全文报告闭式最小二乘上限。
原文摘要 · Abstract (English)
Transformer feed-forward networks (FFNs) are often treated as nonlinear stores of computation, yet how nonlinear a trained FFN block actually is has rarely been measured. We treat each FFN as a position-wise input-to-output map and split it into the exact least-squares linear approximation plus a residual. The held-out variance the closed-form linear map explains defines a block's linear recoverability (R^2_lin), an optimiser-free measure of its linearity. Across all twelve blocks of GPT-2, Pythia-160m, and llama-160m, R^2_lin is highly heterogeneous and non-monotone with depth, ranging from near-linear (>0.99) to strongly nonlinear (<0.3) between adjacent blocks, and is not set by the activation function: same-width GELU models GPT-2 and Pythia-160m have sharply different profiles, so recoverability is a learned property of individual trained blocks, not an architectural one. A low-rank bilinear probe of the residual recovers only a few points of R^2, with gain uncorrelated with residual nonlinearity: the unrecovered computation is not a single position-wise product but higher-order or distributed structure. The measurement also serves as a targeted compression signal: recoverable blocks admit large single-layer replacements (GPT-2's early FFN at 8x fewer parameters for +0.77 perplexity), while low-recoverability blocks flag where this is unsafe. It further exposes a methodological pitfall: trained linear baselines can badly under-converge on ill-conditioned transformer activations, so we report the exact closed-form least-squares ceiling throughout.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。