Causal Attention with Lookahead Keys
Abstract
In standard causal attention, each token's query, key, and value (QKV) are static and encode only preceding context. We introduce CAuSal aTtention with Lookahead kEys (CASTLE), an attention mechanism that continually updates each token's keys as the context unfolds. We term these updated keys lookahead keys because they belong to earlier positions yet integrate information from tokens that appear later relative to those positions, while strictly preserving the autoregressive property. Although the mechanism appears sequential, we derive a mathematical equivalence that avoids explicitly materializing lookahead keys at each position and enables efficient parallel training. On language modeling benchmarks, CASTLE consistently outperforms standard causal attention across model scales, reducing validation perplexity and improving average performance on a range of downstream tasks.
Lay Summary
Standard causal attention uses static keys which are fixed once generated. This limits the representation power of keys. We propose Causal Attention with Lookahead Keys (CASTLE) which updates keys as context unfolds so that keys can incorporate richer information and become smarter as the context progresses. Although this updating mechanism appears sequential, we derive a mathematical equivalence that enables efficient parallel training. Numerical results show that CASTLE outperforms standard causal attention on various language modeling benchmarks across different model scales.