The Evolution of Mainstream Large Language Model Architectures: RoPE, GQA, SwiGLU, MoE, and Training Stability
This article explains how mainstream large language model architectures have evolved despite keeping a familiar overall structure. It covers rotary position encoding, grouped-query attention, gated feed-forward networks, pre-normalization, residual connections, and mixture-of-experts sparsity, with practical guidance for evaluating inference cost, context length, training stability, and observability.
1. Introduction: Same Skeleton, Different Core
About seven years have passed since autoregressive decoder-based large language model architectures became widely used. When you place architecture diagrams from early decoder models around 2019 next to mainstream models from 2024-2025, the overall skeleton looks surprisingly similar: token embeddings, a stack of decoder layers, an attention sublayer and a feed-forward sublayer in each layer, and a final output projection. This superficial similarity can be misleading.
If you only look at the macro structure, you may underestimate how much has been redesigned inside each module. Positional encoding moved from absolute positions to rotary schemes. Standard multi-head attention gave way to grouped-query attention under inference-cost pressure. Gated mechanisms reshaped feed-forward networks. These changes may look local, but together they define the capability boundary and efficiency level of this generation of models.
2. Positional Encoding: From Adding Lookup Vectors to Rotating Alignment
Attention is essentially a set operation and is not sensitive to input order by itself. Without explicit position information, “cats eat fish” and “fish eat cats” can look identical to the model. Positional encoding is therefore a prerequisite for modeling sequence structure.
Early approaches learned a separate vector for each absolute position or added fixed sinusoidal encodings to token embeddings. These approaches have two main limitations. First, learned position vectors are constrained by the maximum sequence length seen during training, and performance can degrade sharply when the model is applied to longer sequences. Second, absolute positions do not naturally express relative distance.
Rotary position encoding, or RoPE, changes how position is injected. Instead of adding position information, RoPE applies a rotation to query and key vectors according to their absolute positions. When the rotated query and key vectors are combined through an inner product, the result depends only on their relative position difference. This has several advantages:
- It naturally encodes relative position and aligns with the linguistic intuition that closer tokens tend to be more strongly related.
- It does not require additional trainable parameters, making it memory-friendly.
- By adjusting rotation frequencies, it supports some degree of length generalization through techniques such as interpolation, extrapolation, and frequency scaling.
3. Attention: From Everyone-Talks-to-Everyone to Grouped Conversations
In standard multi-head attention, each head has its own key and value projections. Adding more heads can improve representational capacity. However, during autoregressive inference, the KV cache grows linearly with the number of heads, becoming a major bottleneck for memory and bandwidth. This issue is especially important for long-context and high-concurrency scenarios.
Grouped-query attention, or GQA, offers a compromise between multi-head attention and single-head attention. Multiple query heads share one set of key and value heads. For example, 32 query heads can be configured so that every 8 query heads share one KV group. This can significantly reduce the KV cache and improve throughput while preserving model quality almost unchanged. The family can be understood as follows:
- Multi-head attention, MHA: each query head has its own KV pair.
- Multi-query attention, MQA: all query heads share one KV pair.
- Grouped-query attention, GQA: the number of groups is configurable and sits between MHA and MQA.
This is a typical engineering tradeoff: sacrificing a small amount of quality for substantial efficiency gains. It becomes especially important when inference cost is a core constraint.
4. Feed-Forward Networks and Activation Functions: Introducing Gating
The feed-forward sublayer in a Transformer layer is usually a two-layer structure that expands the dimension, applies a nonlinear transformation, and then projects back down. Activation functions evolved from ReLU and GELU to gated variants such as SwiGLU. A typical implementation looks like this:
def swiglu_ffn(x, w_gate, w_up, w_down):gate = silu(x @ w_gate) # gating branchup = x @ w_up # information branchreturn (gate * up) @ w_down # element-wise modulation followed by down-projection
Compared with a single activation function, the gating branch allows the network to selectively control information flow, similar to a soft form of sparse selection. In practice, this often leads to more stable convergence and a better quality-to-parameter tradeoff. The cost is an additional projection matrix and roughly one-third more parameters in the feed-forward block. To balance total computation, practitioners often reduce the hidden dimension when using gated feed-forward networks.
5. Normalization, Residual Connections, and Training Stability
Several architectural choices have become standard for stable deep-network training:
- Normalization placement: Moving from post-layer normalization to pre-layer normalization, often called Pre-Norm, significantly improves training stability in deep networks. It can allow larger learning rates and shorter warmup schedules.
- Lightweight normalization: Root-mean-square-based normalization schemes omit mean centering, reducing computation overhead while maintaining a good balance between quality and speed.
- Residual connections: Residual connections are a foundation of modern deep networks. They allow gradients to flow across layers and make it practical to train networks with dozens or even hundreds of layers.
6. Sparsity: Mixture of Experts
Another important direction is sparse architectures that aim to provide large capacity without paying full computation cost. Mixture-of-experts, or MoE, replaces a feed-forward layer with multiple expert subnetworks. For each token, a router selects only a small number of experts to participate in computation.
As a result, the total parameter count can be very large, giving the model high capacity, while the number of parameters actually activated for each token remains limited, keeping computation controllable. This changes the cost curve significantly. However, it also introduces new engineering challenges, including load balancing, routing stability, and memory usage.
7. Deeper Perspective: Gradual Reconstruction Rather Than Complete Rewrite
Are these architectural changes patches or a revolution? They are better understood as gradual structural reconstruction. The overall skeleton remains similar, but each key component has been redesigned for greater density and efficiency. The most important advances often do not come from novel-looking diagrams alone. They come from:
- Order-of-magnitude reductions in training and inference cost, such as KV sharing, memory-access optimization for attention operators, and sparse activation.
- Continued scaling of context length and data size, supported by better positional-encoding extrapolation.
- Accumulated engineering experience for stably training very large and very deep networks.
Innovation is increasingly system-level. Architecture, data, parallelism strategies, and memory optimization together determine final capability. Comparing only architecture diagrams can miss this important layer.
8. Practical Engineering Recommendations
- Prioritize inference cost: For long-context and high-concurrency workloads, prefer grouped-query attention or more aggressive KV-sharing architectures when appropriate.
- Match length requirements: For long-document processing, evaluate the positional encoding’s ability to extrapolate to longer sequences, and use targeted fine-tuning or implementations that support length extrapolation.
- Balance capacity and compute: When compute is limited, sparse approaches such as mixture-of-experts may be worth considering, but reserve capacity for load balancing and memory tuning.
- Improve training stability: For deep models, the standard combination of Pre-Norm and residual connections is recommended, together with a reasonable warmup schedule and gradient clipping.
- Maintain observability: Regardless of the architecture, monitor memory usage, throughput, and routing distribution with metrics, alerts, and logs.
9. Conclusion
The evolution of modern large language model architectures is a path of repeated tradeoffs among efficiency, stability, and expressiveness. The shift toward rotary positional encoding, grouped attention, gated feed-forward networks, and sparse capacity may appear fragmented, but together they support the move toward larger, longer-context, and more efficient models. Understanding the motivations and costs behind these mechanisms is more valuable than memorizing individual names. It is also a key step in moving from simply using models to being able to select, modify, and build them.
