Modern LLM Architecture: Structure, Scale, and Hardware Constraints
This article explains how modern large language model architectures are shaped by compute, memory access, and communication constraints. It reviews the decoder-only Transformer backbone, attention variants that reduce KV cache cost, MoE design and communication trade-offs, numeric precision choices, and a practical checklist for translating architecture specifications into deployment decisions.
Modern LLM Architecture: Structure, Scale, and Hardware Constraints
1. Why Discuss Architecture Separately
Since the Transformer architecture centered on attention was introduced, the basic skeleton of large language models (LLMs) has not undergone a fundamental overturn. Real evolution has happened in the details: how attention is computed, how the feed-forward network is partitioned, and what numeric precision is used. These changes appear scattered, but they all point to the same set of hardware constraints: compute, memory access, and communication.
Looking at model releases in recent years, three highly consistent trends can be identified:
- Total parameters and activated parameters continue to separate. Total model parameters have climbed from hundreds of billions to trillions, but the parameters actually activated in each forward pass have remained stable at tens of billions. This means that “model knowledge capacity” and “single-step compute cost” have been decoupled.
- Context length and KV cache cost pull against each other. Supported context has expanded from 128K to 1M or even longer, but the size of the key-value cache (KV cache) has been repeatedly compressed through various architectural means, because with long sequences the KV cache often consumes more GPU memory than the weights themselves.
- The number of experts increases and routing granularity becomes finer. In Mixture-of-Experts (MoE) models, the number of experts has expanded from dozens in early designs to hundreds, and routing has evolved from “select 2 coarse-grained experts per token” to combinations of “fine-grained experts + shared experts.”
Understanding these three main lines provides the key to reading the architecture report of any new model. The following sections discuss each in turn.
2. Backbone: Decoder-Only Transformer Remains Dominant
Although alternatives such as state space models and linear attention have emerged, the vast majority of current flagship language models still adopt a decoder-only Transformer architecture, with Pre-Norm, Rotary Position Embedding (RoPE), and SwiGLU-style gated feed-forward networks as de facto standard configurations:
Input tokens→ Embedding layer→ N × [ RMSNorm → Attention block → Residual→ RMSNorm → MoE/FFN block → Residual ]→ Final normalization → Vocabulary projection output
Several common design points:
- Normalization: RMSNorm has largely replaced LayerNorm because it eliminates mean computation, reduces memory access overhead from element-wise operations, and is more stable in large-scale training.
- Position encoding: RoPE injects position information by applying rotation transformations related to relative position to queries/keys, naturally supporting extrapolation and interpolation for long-context extension. With techniques such as NTK-aware interpolation and frequency scaling, a shorter training context can be extended to million-token lengths at inference time.
- Activation function: SwiGLU and its variants consistently outperform GELU at the same parameter count and have become the default choice for feed-forward layers.
As these “standard components” converge, differences have become concentrated in two places: attention structure and expert routing.
3. Attention: A Persistent Battle Around KV Cache
Attention computation complexity grows quadratically with sequence length, while KV cache memory usage during inference grows linearly with length. When context reaches the 1M scale, even with a small batch size, the KV cache can consume tens or even hundreds of GB of GPU memory. Therefore, attention structure innovations in recent years have almost all centered on “how to store less and read less KV.”
3.1 From MHA to GQA and MQA
- Multi-Head Attention (MHA): Each attention head has independent K and V projections. It has the strongest expressiveness but the largest KV cache.
- Multi-Query Attention (MQA): All heads share one set of K and V. Cache is compressed to the extreme, but quality loss is obvious.
- Grouped-Query Attention (GQA): A compromise that groups query heads to share K and V, allowing cache size to be adjusted between the two extremes. It is currently the mainstream choice for mid-to-high-end open-source and commercial models.
The compression ratio of GQA is determined by “number of query heads / number of KV heads,” with common configurations from 4:1 to 8:1. It reduces KV cache by an order of magnitude with almost no quality loss.
3.2 Latent-Space Compressed Attention
A more aggressive approach is to cache a low-dimensional latent vector instead of caching K and V directly, and project it back to high dimension when needed. Its mathematical form can be summarized as:
c_t = W_DKV · h_t # Compress hidden state into a low-dimensional latent vector (cached object)k_t = W_UK · c_t # Up-project to reconstruct key when neededv_t = W_UV · c_t # Up-project to reconstruct value when needed
This type of “latent-variable attention” can compress KV cache to a few tenths or less of traditional MHA, while also avoiding repeated computation during inference by absorbing matrix multiplications (merging the up-projection matrix into the query projection). The cost is increased structural complexity and higher requirements for implementation engineering.
3.3 Sparse and Linear Attention
Another route is to reduce the range each token needs to attend to: sliding-window attention, block-sparse attention, and hierarchical/hybrid strategies for ultra-long contexts (dense nearby, sparse far away). Some models use an interleaved design in which most layers use local attention and a few layers use global attention, balancing quality and cost.
Engineering implication: When evaluating the inference cost of a model, the bytes per layer per token of KV cache often determine deployment shape in long-context scenarios more than total parameter count. When planning an inference cluster, it is advisable to first derive KV cache memory requirements from the target context length and concurrency, and then decide the parallel partitioning strategy.
4. Mixture of Experts (MoE): The Art of Decoupling Capacity and Cost
4.1 Basic Structure
MoE replaces the feed-forward layer with N parallel “expert” networks, and each token is routed to only k of them:
y = Σ_{i∈TopK(x)} g_i(x) · Expert_i(x)
Here g_i(x) is the gating weight output by the routing network. Total parameters grow linearly with the number of experts, while computation depends only on k. This is the source of the phenomenon of “trillions of total parameters and tens of billions of activated parameters.”
4.2 Three Key Evolution Directions
- Fine-grained experts: Split large experts into more small experts (for example, from 256 medium experts to hundreds of small experts), improving the expressive power of expert combinations and the degree of knowledge decoupling.
- Shared experts: Set one or more shared experts that are always activated for all tokens to carry general knowledge and reduce redundancy among routed experts.
- Load balancing: Routing naturally tends toward “winner takes all.” Without intervention, a few experts become overloaded while most remain idle. Mainstream methods include auxiliary balancing losses, loss-free bias adjustment (dynamically adding a bias term to routing logits), and capacity factor limits.
4.3 Real Hardware Constraints
MoE turns the compute bottleneck into a communication bottleneck. Experts are usually distributed across different devices (expert parallelism), and each layer requires an All-to-All communication to dispatch tokens and collect results. Therefore:
- Inter-node interconnect bandwidth (rather than single-GPU compute) often becomes the bottleneck in MoE training.
- For inference, a hybrid strategy of “tensor parallelism for the attention part + expert parallelism for the MoE part” can be used.
- The finer the routing granularity and the more experts there are, the higher the engineering complexity of communication scheduling, requiring system-level optimizations such as compute-communication overlap.
5. Numeric Formats: From FP16 to FP8 and Below
The expansion of parameter scale has forced the industry to continue pushing numeric precision lower:
- Training side: BF16 mixed precision is the baseline. A new generation of models commonly introduces FP8 training in feed-forward and matrix multiplication stages, controlling quantization error through fine-grained per-block scaling, which can nearly double training throughput.
- Inference side: Weight quantization to INT8/INT4 is already quite mature. KV cache can also be quantized to INT8 or even lower, forming a “two-pronged” approach together with attention structure compression.
- Caveats: Low precision is not free. Precision-sensitive modules such as router logits, normalization layers, and embeddings usually remain in high precision. When evaluating a quantization scheme, pay attention to degradation on long-context and complex reasoning tasks, not just perplexity.
6. Turning Architecture Information into Deployment Decisions
For a new model, the following checklist can be used to quickly assess its hardware requirements:
- Check activated parameter count: Determines single-step computation and therefore the lower bound of compute for training/inference.
- Check KV cache structure: Attention type (MHA/GQA/latent compression), number of KV heads, and dimensions determine long-context memory usage and memory bandwidth pressure.
- Check MoE configuration: Total number of experts, number activated per token, and whether shared experts exist determine communication patterns and parallel strategies.
- Check numeric formats: Training precision and officially recommended inference quantization schemes determine memory budgets and the range of eligible hardware.
- Check layer count and hidden dimension: Affect pipeline parallel split points and the minimum shard that can fit on a single GPU.
For example, a cloud platform offering general-purpose capabilities such as GPU compute instances, object storage, container platforms, logging, and monitoring can support the full lifecycle from evaluation and deployment to operations: object storage can host model weights and checkpoints, container platforms can orchestrate multi-node inference replicas, and monitoring and alerting can track KV cache hit rates, memory utilization, and latency distribution, forming a controllable LLM inference engineering system.
7. Conclusion
As the saying goes, one understands music after playing a thousand tunes and recognizes fine weapons after examining a thousand blades. The evolution of LLM architectures appears highly varied on the surface, but underneath it is always driven by the same set of physical constraints: compute determines the ceiling of activated parameters, memory access determines the form of the KV cache, and communication determines how MoE is partitioned. Grasp the three tensions of “capacity versus computation decoupling, cache versus context competition, and routing versus communication coexistence,” and no matter what the next generation of models is called or how many times the parameters multiply, you can quickly see its structural essence and engineering cost, while leaving sufficient headroom for accelerator and infrastructure planning.
