在注意力机制中使用量化Softmax预训练Transformer

·

研究论文 · 2026/09/30

低精度Transformer系统越来越多地量化注意力矩阵乘法,而softmax通常保持较高精度。在预训练期间,近似softmax会改变训练模型的梯度以及前向计算。我们通过K区间注意力研究这种交互,它使用K+1个网格值近似指数函数。我们改变每行网格校准、插值与硬舍入、以及直通代理相对于归一化的位置。我们推导相应的反向规则,包括校准导数,并在模型、数据和优化器匹配的预训练实验中比较这些选择。分离行极值保持前向计算不变,但导致验证损失延迟增加。在K=4时使用硬舍入、最小-最大校准和归一化前代理会产生大的损失差距;改变任一选择可显著减少差距。在124M参数和2.5B训练token下,固定窗口校准与归一化后代理在K=4时相对于softmax的验证损失差距为+0.019 nats,而归一化前代理在K=16时为+0.004 nats。

该研究为低精度Transformer预训练中近似softmax的设计提供了实证指导,有助于在保持模型性能的同时降低计算精度。

Low-precision Transformer systems increasingly quantize attention matrix multiplications, while softmax often remains at higher precision. During pretraining, an approximate softmax changes the gradients that train the model as well as its forward computation. We study this interaction with K-interval attention, which approximates the exponential using K+1 grid values. We vary per-row grid calibration, interpolation versus hard rounding, and the placement of a straight-through surrogate relative to normalization. We derive the corresponding backward rules, including calibration derivatives, and compare these choices in pretraining experiments matched on model, data, and optimizer. Detaching the row extrema leaves the forward computation unchanged but produces a delayed increase in validation loss. With hard rounding at K=4, min-max calibration and a pre-normalization surrogate incur a large loss gap; changing either choice substantially reduces it. At 124M parameters and 2.5B training tokens, fixed-window calibration with a post-normalization surrogate yields a validation loss gap of +0.019 nats relative to softmax at K=4, and with a pre-normalization surrogate yields +0.004 nats at K=16.

阅读原文

参与讨论