LLM Architecture Evolution in 2025: A Complete Guide to Attention, Positional Encoding, and MoE
This article breaks down how leading open-source LLM architectures evolved through 2024 and 2025, focusing on the structural changes behind attention mechanisms, positional encoding, feed-forward layers, normalization, sparse expert routing, and tokenization. Instead of comparing benchmark scores, it explains each design tradeoff in terms of inference cost, long-context capability, and transferability, and closes with practical engineering guidance for model selection, caching and bandwidth budgeting, and building reproducible comparison baselines.
1. Why Revisit Model Architecture in 2025
Roughly seven years have passed since the first autoregressive generative pre-training architecture was published. Put an early 2019 baseline model next to a flagship open-source model from 2024 or 2025, and the first impression is often “not much has changed”: still a stack of decoder blocks, still autoregressive next-token prediction, still residual connections plus layer normalization. But if you drop the level of observation from “how layers are stacked” down to “the internal construction of each sub-layer,” you find that nearly every module has been rewritten.
This rhythm of evolution — a stable skeleton with all parts replaced — creates a practical difficulty for engineering: it is hard to tell whether a model performs well because its structure is better, or because its data mix, training steps, and post-training strategy happen to be more suitable. Differences in datasets, hyperparameters, and compute budgets are usually not fully disclosed, so single-point benchmark comparisons have almost no attribution value.
There are still three reasons why structural comparison is worth doing:
- Structure sets the lower bound on inference cost. Attention complexity, the fraction of activated tokens, and cache footprint are all direct sources of your bill after launch.
- Structure sets the upper bound on long-context capability. The positional encoding scheme and attention sparsification strategy directly constrain the sequence length that can be handled stably.
- Structure is transferable. Data cannot be reproduced, but the design tradeoff behind a module can be borrowed for your own model or fine-tuning pipeline.
This article does not discuss benchmark scores or training algorithm details. It does one thing: decompose the architectural changes in current text-focused flagship models into comparable dimensions and provide a basis for engineering judgment.
2. Attention: From Multi-Head to Grouped-Query and Cross-Step Sharing
Multi-head attention has long been the default choice. Its problem is that the inference stage must cache the key-value pairs of every head, cache size grows linearly with the number of heads, and the decoding stage is limited by memory bandwidth, so compute often sits idle.
Grouped-query attention is the current mainstream compromise: let multiple query heads share one group of key-value heads, compress the cache to a fraction of its original size, and largely preserve representational capacity. A further direction is multi-query attention, where all query heads share a single key-value group. This is the most aggressive compression, but it tends to cause quality regression on small models.
Two structural modifications are more noteworthy:
- Cross-step attention sharing. Some models let several adjacent layers reuse the same key-value cache, extending sharing into the “layer dimension,” with very obvious cache gains in long-context scenarios.
- Attention sparsification and local windows. A sliding window limits the visible range of each token, and a small number of global tokens are added on top, pushing complexity from quadratic down to nearly linear.
Schematically, the cache size of grouped-query attention can be understood like this:
# Pseudocode: expresses only the order-of-magnitude relationship of cache sizekv_heads = 8 # number of key-value heads, far fewer than query headsquery_heads = 64 # number of query headshead_dim = 128cache_per_token = 2 * kv_heads * head_dim # one copy each for K and V# Cache grows linearly with sequence length and is independent of query_heads
The engineering implication is direct: when you want to expand context from a few thousand to hundreds of thousands of tokens, the first thing to check is not compute but the cache and bandwidth budget.
3. Positional Encoding: From Absolute to Rotary and Long-Range Extrapolation
Absolute positional encoding adds position information directly to the embeddings and extrapolates poorly. Rotary positional encoding applies position information to queries and keys in the form of a rotation matrix, changing only the relative angle between the two. It therefore carries relative-position semantics naturally and can achieve length extrapolation by adjusting the rotary base frequency.
Two improvement directions discussed repeatedly around 2025 are:
- Base frequency scaling. Interpolating or scaling the low-frequency dimensions keeps the attention distribution smooth beyond the training length, avoiding the attention collapse that occurs with direct extrapolation.
- Sharing and decoupling of positional embeddings. Some work strips position-related computation out of every layer and injects it only at specific layers, reducing redundant computation.
It is worth noting that length extrapolation is not a capability you get for free by “changing one parameter.” Any extrapolation scheme needs validation at the target length, watching whether attention entropy and perplexity show abnormal increases.
4. Feed-Forward Networks and Normalization: Activation Replacement and Stability Techniques
The feed-forward sub-layer usually accounts for the majority of parameters, so its modification has the most direct payoff. Gated linear unit structures (such as SwiGLU) have largely replaced the earlier GELU/ReLU schemes: one projection path acts as a gate, the other performs the transformation, the two are multiplied element-wise and then projected down, which typically converges faster at the same parameter count.
The choice of normalization position has also been reshuffled:
- Post-normalization is closer to the original design and stable to train, but requires more careful warmup.
- Pre-normalization is easier to train and is the choice of most current models.
- Debiased normalization and double normalization (adding one before and one after the sub-layer) are used to suppress scale drift in deep activations.
In addition, to reduce the probability of training divergence, weight scaling before the output projection and initialization scaling on the residual branch have become de facto standard practice. These techniques do not change model capacity but significantly affect whether a large model can converge smoothly.
5. Sparsification: Mixture of Experts and Token-Level Activation
A mixture-of-experts layer replaces the dense feed-forward network with multiple parallel expert networks plus a routing network, and each token activates only a few of the experts. Its value lies in decoupling “total parameter count” from “per-step computation”: total parameters can be made very large while the actual computation per token stays controllable.
Three practical problems must be handled in deployment:
- Load balancing. Routing tends to collapse onto a few experts, requiring an auxiliary loss or an auxiliary-loss-free bias adjustment strategy.
- Communication overhead. When experts are distributed across different devices, cross-device dispatch and aggregation become the bottleneck.
- Fine-tuning difficulty. Sparse structures are more sensitive to learning rate and routing temperature, and fine-tuning on small datasets can easily break the existing routing distribution.
Sparsity on the attention side (shared key-values, local windows) and sparsity on the feed-forward side (expert routing) are two orthogonal routes that can be stacked, which is also the common combination in current flagship models.
6. Tokenization and Vocabulary Design
Tokenization is often overlooked, but it affects sequence length, multilingual efficiency, and inference cost at the same time. Byte-level encoding is the general baseline; increasing vocabulary size can shorten sequences but raises the parameters and memory footprint of the embedding and output layers. A more common approach in recent years is to redraw the merge rules for digits and code, avoiding splitting multi-digit numbers into unpredictable fragments and thereby improving consistency on arithmetic and code tasks.
7. Engineering Recommendations
When selecting and deploying models on Baidu AI Cloud, you can proceed in the following order:
- Define constraints first. Clarify context length, concurrency, per-request latency, and cost ceilings before discussing structural merits.
- Build a validation pipeline with general capabilities. Use object storage for data and artifacts, a container platform to host inference services, and log and monitoring services to observe cache hit rate, time to first token, and throughput.
- Establish your own comparison baseline. Fix the data and hyperparameters and replace only a single structural variable, so attribution is valid.
- Focus on cache and bandwidth rather than peak compute. The decoding stage is usually bandwidth-bound, and the payoff of key-value cache strategies often exceeds switching to a larger model.
- Long context must be measured. Use attention distributions and perplexity curves to verify whether extrapolation is genuinely usable.
8. Conclusion
The 2025 evolution of model architecture is essentially a finer tradeoff between “representational capacity” and “inference cost”: attention does sharing and sparsification, positional encoding does extrapolation, feed-forward layers do gating and sparse routing, and normalization does scale stabilization. The skeleton has not been overturned, but every part has been redesigned. For developers, understanding these tradeoffs is more valuable than memorizing a model’s parameter table, because it determines how far you can go within a limited budget.
