11.8 Further Reading
The architectures built in this chapter share a common design: a pre-norm residual stream (Section 11.1), causal or bidirectional multi-head attention (Section 11.2, Section 11.4), a key–value cache compressed across heads, tokens, or channels (Section 11.3), and feed-forward layers scaled either densely (Section 11.6) or through sparse expert routing (Section 11.7). This section surveys important architectural variations and research directions that build on these foundations.
11.8.1 Normalization Placement and Residual Stream Variants
Pre-norm (RMSNorm before each sublayer) is the default in most modern Transformers because it preserves an unattenuated identity path from the output back to the first layer (Section 11.1). In very deep models or long FP16/BF16 training runs, however, an unnormalized residual stream can accumulate large activation norms across depth, while attention score magnitudes can drift upward until softmax saturates. Two families of refinements address this (Figure 11.8.1):
- Sublayer output normalization (Sandwich-LN / Peri-LN) and post-norm variants. Normalizing both the input and the output of each sublayer (\(x + \operatorname{Norm}(f(\operatorname{Norm}(x)))\)) bounds the magnitude of each residual update while keeping the identity skip connection intact, a pattern used in CogView (Ding et al. 2021) and Gemma 2/3 (Gemma Team 2024, 2025). OLMo 2 (Team OLMo et al. 2025) instead moves the RMSNorm to the output of each sublayer (\(x + \operatorname{Norm}(f(x))\)) and combines it with QK-Norm, bounding residual stream growth without gating the identity path through a post-addition normalization.
- Query–key normalization (QK-Norm). Applying RMSNorm to queries and keys per head before computing \(QK^\top / \sqrt{d_h}\) (Section 11.1.2.5) bounds the pre-softmax logits by Cauchy–Schwarz regardless of residual stream growth (Henry et al. 2020; Dehghani et al. 2023). It is standard in ViT-22B, Gemma 3, Qwen3, and OLMo 2.
- Depth-scaled post-norm and soft-capped logits. DeepNorm (H. Wang et al. 2024) keeps the Post-LN block but up-weights its skip path by an explicit depth-dependent constant, \(\operatorname{Norm}(\alpha x + f(x))\) with \(\alpha = (2L)^{1/4}\), while down-scaling the initialization of the branch weights by \(\beta = (8L)^{-1/4}\). Both make each update small relative to the stream, which stabilizes Post-LN Transformers to 1,000 layers. Alternatively, Gemma 2 bounds attention and final logits via smooth tanh soft-capping (\(c \tanh(z / c)\)), though QK-Norm largely supersedes attention logit soft-capping in newer models.
11.8.2 Feed-Forward Networks and Activation Functions
The original Transformer used a two-matrix ReLU feed-forward network with intermediate width \(d_{\textrm{ff}} = 4d\) (Vaswani et al. 2017). GPT-2 and BERT replaced ReLU with GELU (Hendrycks and Gimpel 2016). Following Shazeer (2020), almost all modern language models use gated linear units (Dauphin et al. 2017), either SwiGLU (SiLU gate) or GeGLU (GELU gate), with intermediate width \(d_{\textrm{ff}} \approx \frac{8}{3}d\) rounded to a hardware-friendly multiple of 128 or 256 so that the three projection matrices (\(W_{\textrm{gate}}, W_{\textrm{up}}, W_{\textrm{down}}\)) match the \(8d^2\) parameter and FLOP budget of an un-gated \(4d\) FFN (Section 11.1). At extreme widths, parallel Transformer blocks (PaLM (Chowdhery et al. 2022), ViT-22B (Dehghani et al. 2023)) compute attention and the FFN in parallel from the same normalized input (\(x + \operatorname{Attn}(\operatorname{Norm}(x)) + \operatorname{FFN}(\operatorname{Norm}(x))\)), allowing the input projections of attention and the FFN to be fused into a single large matrix multiplication.
11.8.3 Long-Context Inference and Cache Compression
Because decoding is memory-bandwidth bound (Section 11.3.2.1), reducing key–value cache traffic is central to efficient serving:
- Grouped-query and multi-head latent attention. Multi-query attention (MQA) (Shazeer 2019) and grouped-query attention (GQA) (Ainslie et al. 2023) share key and value heads across groups of query heads (Section 11.3.3). Multi-head latent attention (MLA), introduced in DeepSeek-V2 (DeepSeek-AI 2024) and kept in DeepSeek-V3 (DeepSeek-AI et al. 2024), generalizes low-rank KV compression (Section 11.3.3.2) by projecting keys and values jointly into a single low-dimensional latent vector \(c_t^{\textrm{KV}} \in \mathbb{R}^{d_c}\) (\(d_c \ll H d_h\)) cached in memory, while pairing it with a decoupled low-dimensional RoPE key vector so rotary position encodings remain compatible with weight absorption during decoding.
- Sliding windows, attention sinks, and hybrid stacks. Retaining the initial prompt tokens alongside a rolling window of recent tokens (StreamingLLM (Xiao et al. 2024), Section 11.3.3.3) preserves generation quality during streaming inference because the softmax denominator absorbs excess probability mass on the initial “sink” tokens. Several recent architectures interleave local sliding-window attention layers with full global causal attention layers (five local layers per global one in Gemma 3, alternating layers in gpt-oss), or interleave attention layers with linear-time state space / recurrent layers (Chapter 12).
- Speculative decoding. Because verifying \(m\) candidate tokens in parallel has nearly the same memory-bandwidth cost as decoding a single token (Section 11.3.2.1), speculative decoding (Leviathan et al. 2023; Chen et al. 2023) uses a fast draft model (or extra multi-token prediction heads attached to the target model) to propose \(m\) tokens and verifies them in a single target-model forward pass via a rejection-sampling rule that preserves the exact target distribution.
11.8.4 Encoders, Cross-Attention, and Vision Backbones
- Bidirectional encoders and retrieval. While causal decoders dominate open-ended generation, bidirectional encoders (Section 11.4) remain the workhorse for dense text embeddings, reranking, and token-level classification. RoBERTa (Liu et al. 2019) and DeBERTa (He et al. 2021) refine BERT’s masked language modeling pretraining recipe, while ModernBERT (Warner et al. 2024) brings the modern pre-norm, RoPE, SwiGLU, and unpadded FlashAttention stack to bidirectional encoders.
- Vision Transformers and hierarchical hybrids. Training ViTs effectively at moderate data scales relies on strong data augmentation and regularization (DeiT (Touvron et al. 2021)), self-supervised masked patch prediction (MAE (He et al. 2022)) or self-distillation (DINOv2 (Oquab et al. 2024)), and 2D rotary position embeddings. For dense prediction tasks (detection, segmentation) requiring multi-scale feature maps, Swin Transformers (Liu et al. 2021) restrict self-attention to shifted local 2D windows across a hierarchical pyramid, while ConvNeXt (Liu et al. 2022) transfers Transformer block design choices back into pure depthwise-separable convolutional networks.
11.8.5 Scaling Laws and Mixture-of-Experts Design
- Compute-optimal vs. inference-aware scaling. Kaplan et al. (2020) first established power-law scaling of language model cross-entropy loss with model size \(N\), dataset size \(D\), and compute \(C\). Hoffmann et al. (2022) (Chinchilla) showed via IsoFLOP curves that training loss is minimized at fixed pretraining compute when \(N\) and \(D\) scale in equal proportion (\(D \approx 20 N\)). Modern open-weights models (such as Llama 3 8B trained on 15T tokens, or Qwen3) deliberately over-train smaller models far beyond the Chinchilla ratio (Section 11.6) to amortize training compute against total lifetime inference cost (Sardana et al. 2024).
- Sparse Mixture of Experts. Building on Top-\(K\) noisy gating (Shazeer et al. 2017), GShard (Lepikhin et al. 2021), and Switch Transformer (Fedus et al. 2022), modern MoE models differ mainly in granularity (Section 11.7): Mixtral 8x7B (Jiang et al. 2024) routes each token to 2 of 8 full-width experts, whereas Qwen3 (Yang et al. 2025) and DeepSeek-V3 (DeepSeek-AI et al. 2024) select 8 of more than a hundred narrow ones. DeepSeek-V3 also adds an always-active shared expert (Dai et al. 2024) and balances its load mainly through dynamic per-expert router biases (L. Wang et al. 2024), with only a very small auxiliary penalty left. Dense checkpoints can also be converted into MoE models via sparse upcycling (Komatsuzaki et al. 2023), initializing each expert from the trained dense FFN before continuing pretraining.