揭示Transformer在上下文强化学习中的真实工作机制
Beyond Linear Attention: Softmax Transformers Implement In-Context Reinforcement Learning

- 用标准softmax注意力模拟加权softmax时序差分迭代
- 层数越多,策略评估误差越小,理论证明收敛性
- 解释预训练参数为何能自然涌现,适合算法研究者
上下文强化学习(ICRL)研究的是:模型在预训练后,通过额外上下文信息适应新任务,无需更新参数。现有理论分析多依赖线性注意力假设,即用恒等映射替代softmax函数,这不切实际。本文首次在不使用该简化假设的前提下,对实际中使用的softmax注意力进行理论分析。我们发现,在特定参数下,带有softmax注意力的Transformer逐层前向传播等价于加权softmax时序差分(TD)学习的迭代过程。其中,加权softmax TD是一种新提出的强化学习算法,能在核空间中进行策略评估,包含线性TD和表格型TD作为特例。我们进一步证明,在特定收缩条件下,随着网络层数增加,策略评估误差呈指数下降。最后,我们证明这些参数是预训练损失的全局最小值,解释了其在数值实验中的自然出现。
原文摘要 · Abstract (English)
In-context reinforcement learning (ICRL) studies agents that, after pretraining, adapt to new tasks by conditioning on additional context without parameter updates. Existing theoretical analyses of ICRL largely rely on linear attention, which replaces the softmax function in the standard attention with an identity mapping. This paper provides the first theoretical understanding of ICRL without making the unrealistic linear attention simplification. In particular, we consider the standard softmax attention used in practice. We show that, with certain parameters, the layerwise forward pass of a Transformer with such softmax attention is equivalent to iterative updates of a weighted softmax temporal difference (TD) learning algorithm. Here, weighted softmax TD is a new RL algorithm that performs policy evaluation in kernel space and adopts both linear TD and tabular TD as special cases. We also prove that under a certain contraction condition, the policy evaluation error decays as the number of layers grows, with the identified parameters above. Finally, we prove that those parameters are a global minimizer of a pretraining loss, explaining their emergence in our numerical experiments.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。