Why Attention Patterns Exist: A Unifying Temporal Perspective Analysis
Qingyue Yang, Jie Wang, Xing Li, Yinqi Bai, Xialiang Tong, Huiling Zhen, Jianye Hao, Mingxuan Yuan, Bin Li
TL;DR
TAPPA introduces a unifying temporal framework to explain the emergence of diverse attention patterns in autoregressive LLMs by analyzing the temporal evolution of queries under RoPE. It defines a quantitative measure, $q$-similarity, to distinguish predictable versus unpredictable patterns and provides theoretical conditions for Re-access, Sequential, and Seasonal patterns arising from the joint effect of queries, keys, and RoPE. The framework leverages a channel-wise decomposition of attention and the RoPE relative-position identity $R_m^\top R_n = R_{m-n}$ to explain phenomena such as periodic diagonals and seasonal repeats. Empirically, TAPPA improves downstream efficiency for KV-cache compression and LLM pruning using a simple $q$-similarity based budget adjustment, demonstrating practical impact and enabling broader, theory-driven optimization of transformer inference.
Abstract
Attention patterns play a crucial role in both training and inference of large language models (LLMs). Prior works have identified individual patterns such as retrieval heads, sink heads, and diagonal traces, yet these observations remain fragmented and lack a unifying explanation. To bridge this gap, we introduce \textbf{Temporal Attention Pattern Predictability Analysis (TAPPA), a unifying framework that explains diverse attention patterns by analyzing their underlying mathematical formulations} from a temporally continuous perspective. TAPPA both deepens the understanding of attention behavior and guides inference acceleration approaches. Specifically, TAPPA characterizes attention patterns as predictable patterns with clear regularities and unpredictable patterns that appear effectively random. Our analysis further reveals that this distinction can be explained by the degree of query self-similarity along the temporal dimension. Focusing on the predictable patterns, we further provide a detailed mathematical analysis of three representative cases through the joint effect of queries, keys, and Rotary Positional Embeddings (RoPE). We validate TAPPA by applying its insights to KV cache compression and LLM pruning tasks. Across these tasks, a simple metric motivated by TAPPA consistently improves performance over baseline methods. The code is available at https://github.com/MIRALab-USTC/LLM-TAPPA.
