10.8 Further Reading
The preceding sections developed one representative design for each layer component: softmax lookup (Section 10.1), scaled dot-product scoring and masking (Section 10.2), multi-head and grouped-query self-attention (Section 10.3), positional encodings (Section 10.4), tiled online softmax (Section 10.5), sliding-window and linear attention (Section 10.6), and mechanistic circuits (Section 10.7). This section surveys closely related variants, architectural refinements in modern open-weights models, and primary literature.
10.8.1 The Lookup and Its Normalization#
10.8.1.1 Attention as Associative Memory#
Ramsauer et al. (2021) connect softmax attention to classical associative memories by showing that one step of softmax attention corresponds to a single update of a continuous modern Hopfield network whose stored patterns are the key/value rows. The inverse temperature ( in kernel regression, in dot-product attention) determines whether the fixed points are individual stored patterns (high inverse temperature) or metastable averages over multiple patterns (low inverse temperature). Using this lens, they observe that early layers in pretrained encoders such as BERT predominantly operate in the broad-averaging regime, whereas deeper layers operate in the sharp-retrieval regime. Adaptive kernel bandwidths (Silverman, 1986) correspond to query- or head-dependent softmax temperatures.
10.8.1.2 Monotone Alignment#
A year before Bahdanau et al. (2015) introduced unconstrained content-based alignment for machine translation, Graves (2013) introduced a differentiable monotone location-based attention mechanism for handwriting synthesis, parameterizing a mixture of Gaussian windows whose mean positions advance monotonically with each pen stroke—an inductive bias suited to speech and handwriting ((Rabiner and Juang, 1993)) but too restrictive for word-order inversions in translation (Section 10.2.4).
10.8.1.3 Weights That Need Not Sum to One#
Because a softmax row must sum to one, a query with no relevant keys often dumps its probability mass onto the initial token—the attention sink of Section 10.2.3.2 and Section 10.7 (see also Section 11.3.3.3). Sun et al. (2024) link attention sinks to massive outlier activations in the residual stream that act as implicit bias terms, while Barbero et al. (2025) argue that sinks prevent representation collapse in deep long-context transformers by providing a no-op target.
Several recent designs relax the unit-sum constraint so heads can idle without an input token sink:
- Sigmoid attention (Ramapuram et al., 2025) replaces the row-wise softmax with an elementwise logistic sigmoid shifted by , initializing weights near .
- Gated attention (Qiu et al., 2025), used in Qwen3-Next (Team, 2025), multiplies each head's softmax output by an input-dependent sigmoid gate.
- Learnable sink logits, used in
gpt-oss(OpenAI, 2025), append a trainable virtual key score to the softmax denominator with no associated value vector. - Differential attention (Ye et al., 2025) subtracts two softmax distributions per head to cancel common-mode background weight on irrelevant keys.
10.8.2 Self-Attention and Heads#
10.8.2.1 Origins and Head Redundancy#
Self-attention evolved from intra-attention recurrences (Cheng et al., 2016), recurrence-free decomposable attention for natural language inference (Parikh et al., 2016), and multi-row sentence embeddings with diversity penalties (Lin et al., 2017), before Vaswani et al. (2017) unified projected multi-head self-attention in the Transformer.
While multiple heads are essential to overcome the single-mixture bottleneck (Section 10.3.2), trained models often exhibit substantial head redundancy at test time: Michel et al. (2019) and Voita et al. (2019) showed that a large fraction of heads in BERT and NMT models can be pruned post hoc with minimal degradation, leaving a core of positional, syntactic, and rare-word heads. In modern architectures, parameter and cache efficiency is achieved prior to training via grouped-query attention (Section 10.3.3.6, Section 11.3.3).
10.8.3 Positions#
10.8.3.1 Learned Relative Positions#
Before RoPE, relative offsets were injected via trainable per-offset key embeddings (Shaw et al., 2018), skew-indexed relative logits in the Music Transformer (Huang et al., 2018), or logarithmic distance-bucket scalar biases in T5 (Raffel et al., 2020). ALiBi replaced learned buckets with fixed linear slopes, and RoPE achieved exact offset-only score dependence via parameter-free coordinate rotations.
10.8.3.2 RoPE in Trained Models#
Open-weights models have progressively increased the RoPE base frequency to support longer contexts: from in Llama 2 to in Llama 2 Long (Xiong et al., 2024) and Llama 3 (Grattafiori et al., 2024), and in the global layers of Gemma 3 (Team, 2025). Increasing shifts more coordinate pairs into the slow regime whose wavelength exceeds the training window (Section 10.4.5.3). Barbero et al. (2025) show that trained models use high-frequency RoPE pairs for positional heads (such as previous-token heads) and low-frequency pairs as nearly position-invariant semantic channels—motivating p-RoPE, which zeroes out the lowest frequencies entirely so semantic channels do not drift at extreme distances. For post-training context extension beyond YaRN (Peng et al., 2024), LongRoPE (Ding et al., 2024) uses evolutionary search over per-dimension rescale factors to extend context windows up to 2M tokens.
10.8.3.3 Length Generalization and Long-Context Utilization#
Chi et al. (2023) analyze ALiBi's effective receptive field, corroborating our finding in Section 10.4.5.2 that flat perplexity extrapolation reflects local windowing rather than long-range retrieval. For causal models without positional encodings (NoPE, (Haviv et al., 2022)), Wang et al. (2024) show that attention entropy grows with sequence length and can be counteracted by per-head temperature scaling—a mechanism used at inference time in the NoPE global layers of Llama 4 (AI, 2025). Finally, low aggregate perplexity on long documents does not guarantee effective retrieval across the full window: Liu et al. (2024) demonstrate a "lost in the middle" phenomenon where accuracy drops significantly when relevant facts appear in the middle of a long context rather than near the start or end.
10.8.4 Cost#
10.8.4.1 Early Linear-Complexity Approximations#
Prior to FlashAttention, numerous architectures approximated the attention matrix: Performer (Choromanski et al., 2021) used positive orthogonal random features to approximate the exponential kernel; Linformer (Wang et al., 2020) applied low-rank sequence projections; Reformer (Kitaev et al., 2020) used locality-sensitive hashing; and Longformer (Beltagy et al., 2020) and Sparse Transformer (Child et al., 2019) combined local windows with strided or global tokens (surveyed by Tay et al. (2020)).
10.8.4.2 Windows and Content-Adaptive Sparsity in Released Models#
While Mistral 7B (Jiang et al., 2023) applied sliding
windows in every layer (later dropped in (AI, 2023)), subsequent
architectures interleave local windows with periodic global layers: 1:1 in
Gemma 2 (Team, 2024), 5:1 in Gemma 3 (,
(Team, 2025)), 1:1 with in gpt-oss
(OpenAI, 2025), and chunked local layers paired with NoPE global layers
in Llama 4 (AI, 2025).
Beyond fixed positional windows, hardware-aligned content-based sparse attention has emerged for long-context training and decoding, including Native Sparse Attention (NSA, (Yuan et al., 2025)), Mixture of Block Attention (MoBA, (Lu et al., 2025)), and DeepSeek Sparse Attention (DeepSeek-AI et al., 2025).
10.8.4.3 FlashAttention-2, FlashAttention-3, and FlexAttention#
Following FlashAttention (Dao et al., 2022), FlashAttention-2 (Dao, 2024) parallelizes across the query sequence dimension and defers normalization until the end of the key loop. On Hopper GPUs, FlashAttention-3 (Shah et al., 2024) overlaps asynchronous Tensor Core matrix multiplications with warp-specialized softmax exponentiation and supports FP8 via incoherent orthogonal pre-rotations. FlexAttention (Dong et al., 2025) compiles arbitrary score-modification closures and block masks into fused Triton kernels, while parallel KV-cache decoding kernels split the key axis and reduce partial states via online softmax.
10.8.4.4 Gated Recurrences and Hybrids#
Modern linear-attention descendants address memory capacity via two upgrades taught in Chapter 12: (1) data-dependent forget gates (Gated Linear Attention, (Yang et al., 2024), Section 12.6) and (2) error-correcting delta updates (DeltaNet, (Schlag et al., 2021; Yang et al., 2024), and Gated DeltaNet, (Yang et al., 2025), Section 12.7). Production architectures combine these recurrent layers with periodic full softmax attention layers (typically 1 in 4 to 1 in 8 layers) to preserve exact associative recall (Team, 2025; Team, 2025; MiniMax, 2025) (Section 12.8).
10.8.5 Circuits in Large Models#
10.8.5.1 Activation Patching, Superposition, and Explanation#
To go beyond zero/mean ablation (Section 10.7.3.3), activation patching substitutes activations from a clean run into a corrupted run to isolate causal pathways (Meng et al., 2022; Wang et al., 2023), automated via ACDC (Conmy et al., 2023) or first-order attribution patching (Nanda, 2023; Kramár et al., 2024; Zhang and Nanda, 2024; Heimersheim and Nanda, 2024). When features outnumber residual-stream dimensions (superposition, (Elhage et al., 2022)), sparse autoencoders and attribution graphs disentangle polysemantic directions into monosemantic features
(Bricken et al., 2023; Cunningham et al., 2024; Ameisen et al., 2025). These interventional tools also resolve the classical debate between Jain and Wallace (2019) and Wiegreffe and Pinter (2019) over whether attention weights constitute faithful explanations.
10.8.5.2 In-Context Learning as an Algorithm#
Alongside induction-head copying (Olsson et al., 2022), transformers trained on in-context regression families can implement gradient descent, ridge regression, and least-squares solvers directly in their forward pass (Garg et al., 2022; von Oswald et al., 2023; Akyürek et al., 2023), though the extent to which general text pretraining induces implicit gradient descent remains debated (Shen et al., 2024).
10.8.6 Recommended Resources#
- Visual introductions: 3Blue1Brown, Attention in Transformers, Step-by-Step (2024); Jay Alammar, The Illustrated Transformer (2018); Peter Bloem, Transformers from Scratch (2019); Lilian Weng, The Transformer Family Version 2.0 (2023).
- Foundational and circuit monographs: Elhage et al., A Mathematical Framework for Transformer Circuits (2021); Olsson et al., In-Context Learning and Induction Heads (2022); Weiss, Goldberg, and Yahav, Thinking Like Transformers (2021) and Sasha Rush's companion Transformer Puzzles.