Large Language Model Architecture and Parameter Scale: How Model Design Has Evolved
This article explains how total parameters, active parameters, context length, and numerical precision affect the cost of running large language models. It covers attention designs such as grouped-query attention, sliding-window attention, and low-rank compression, along with mixture-of-experts routing, KV cache memory estimation, and quantization. It ends with a checklist for model selection and capacity planning.
1. Problem Background
Today’s leading large language models differ widely in size. Total parameter counts have grown from tens of billions to trillions, but the number of parameters used in each inference step has stayed at the scale of several billion. Context windows have expanded from 128K tokens to the million-token range, and the GPU memory needed to support them has become the main constraint on serving cost. Some models now have hundreds of experts, and their routing granularity has become finer as a result.
These factors are closely linked. Parameter count affects storage, active parameters affect compute, context length affects the cache, and numerical precision affects bandwidth. Looking at a single metric rarely shows whether an architecture suits a given scenario. This article first clarifies several core concepts. It then examines attention structures, mixture-of-experts structures, KV cache, and numerical formats. Finally, it provides a checklist for model selection and planning.
2. Core Concepts
2.1 Total Parameters and Active Parameters
Total parameters are the number of all trainable weights in a model. This number determines the storage size of the model file and the memory required to load it. Active parameters are the weights used in the forward pass for a single token. This number determines the compute required for each step.
In a dense model, every layer participates in processing every token, so total and active parameters are equal. In a mixture-of-experts (MoE) model, only some experts participate in each computation, so the two numbers can differ by several times or even by tens of times. When discussing how large a model is, both numbers should be stated. Otherwise, storage cost and compute cost are easily confused.
2.2 Context Length and Effective Context
Context length is the maximum number of tokens a model can receive in a single request. It does not necessarily match the range of information the model can use effectively. The method used to extrapolate positional encodings and the share of long texts seen during training both affect how well the model handles long-range dependencies. In practice, teams usually verify performance with long-context evaluation sets rather than relying only on the maximum value in the configuration file.
2.3 Numerical Precision
Weights and intermediate results can be stored in floating-point or integer formats with different bit widths. Lower bit widths reduce storage and bandwidth requirements but cause greater precision loss. Training typically uses higher precision. Inference can often use lower precision while maintaining acceptable quality.
3. Evolution of Attention Structures
3.1 Multi-Head Attention and KV Cache
Standard multi-head attention keeps separate keys and values for each head. During autoregressive generation, the keys and values of past tokens must be cached to avoid recomputing them. The cache size grows with the number of heads, the number of layers, and the sequence length. For this reason, the cache is the main memory cost in long-context inference.
3.2 Multi-Query and Grouped-Query Attention
Multi-query attention lets all query heads share a single set of keys and values. This reduces the cache size to one divided by the number of heads, but it also reduces expressive capacity. Grouped-query attention offers a compromise. It divides the query heads into several groups, and each group shares one set of keys and values. Many current large models use this approach because it balances quality and cache cost well.
3.3 Local and Sparse Attention
Sliding-window attention limits each token to attending to a recent window of tokens. Its compute and cache costs depend on the window length rather than the full context length. Some architectures use global attention in a few layers and local attention in the rest, which balances long-range dependencies against efficiency.
Sparse attention computes only a subset of attention scores, chosen by a predefined rule or by a learned selection mechanism. Its implementation is more complex and requires specialized kernels before it delivers real speed gains.
3.4 Low-Rank Compression
The basic idea of low-rank compression is to project key and value representations into a lower-dimensional latent space and cache the compressed vectors. These vectors are then expanded back when needed. This significantly reduces the cache size. The cost is extra compute for the projection and expansion steps, so the trade-off depends on the specific hardware.
4. Mixture-of-Experts Structures
4.1 Routing Granularity
A mixture-of-experts layer contains multiple feed-forward networks, called experts. A router selects the highest-scoring experts for each token, and only those experts run. With more experts and smaller individual experts, routing becomes finer-grained. This lets model capacity grow without increasing the compute per step. However, fine-grained routing also adds communication and scheduling overhead.
4.2 Shared Experts
Some architectures keep a small number of shared experts that every token passes through. These learn general features. The routed experts learn domain-specific knowledge. The share of shared experts should be determined by the training data distribution and the inference latency target.
4.3 Load Balancing
If routing concentrates on a few experts, those experts become overloaded while the others stay idle for long periods. During training, auxiliary losses or bias adjustment mechanisms are commonly used to keep the load roughly balanced across experts. During inference, the load distribution across expert-parallel ranks must also be considered. Otherwise, some compute nodes become bottlenecks.
4.4 Estimating Active Parameters
The following example uses an assumed configuration to show how to estimate active parameters from shared parameters and routed expert parameters.
def active_params(shared_b, routed_total_b, num_experts, top_k):"""Estimate the number of active parameters per token in a mixture-of-experts model (unit: B)."""if top_k > num_experts:raise ValueError("top_k cannot exceed the total number of experts")routed_active = routed_total_b * top_k / num_expertsreturn shared_b + routed_active# Assumed configuration: 20B shared parameters, 380B routed expert parameters, top-8 of 256 expertsprint(active_params(20, 380, 256, 8)) # Output: 31.875
This result shows that a hypothetical model with 400B total parameters has about 31.9B active parameters per token. A real model also includes attention layers, embedding layers, and output layers. These components should be counted separately when estimating.
5. Estimating KV Cache Memory
Each token needs one set of keys and one set of values cached at every layer. The KV cache size in bytes for a single sequence can be estimated with the following formula:
KV cache bytes = 2 × layers × KV heads × head dimension × sequence length × bytes per element × batch size
def kv_cache_gib(layers, kv_heads, head_dim, seq_len,bytes_per_elem=2, batch=1):total_bytes = (2 * layers * kv_heads * head_dim* seq_len * bytes_per_elem * batch)return total_bytes / (1024 ** 3)# Assumed configuration: 60 layers, 8 KV heads, head dimension 128, BF16, 128K contextprint(round(kv_cache_gib(60, 8, 128, 131072), 2)) # Output: 30.0
Under this assumed configuration, the cache for one 128K sequence is about 30 GiB. The cache grows linearly as the batch size increases. In long-context serving, cache capacity often becomes the limiting factor before compute capacity does.
6. Numerical Formats and Quantization
Weight quantization can reduce parameters from 16 bits to 8 bits or 4 bits. This halves or quarters the memory footprint. Activations and the KV cache can also be quantized, but sensitive layers need careful attention. Common practices include per-channel or per-group quantization, smoothing of outlier values, and keeping key layers at higher precision.
The benefit of quantization depends on the bottleneck. If inference is limited by memory bandwidth, lower bit widths directly increase throughput. If it is limited by compute units, the benefit depends on whether the hardware natively supports the target format.
7. Architectural Trade-offs and Hardware Constraints
Architecture design usually balances the following goals:
- Quality and compute: Increasing active parameters often improves capability, but it also raises inference cost.
- Context and cache: Extending context requires compressing the cache or limiting the attention range.
- Capacity and communication: More experts require expert parallelism, which adds cross-node communication.
- Precision and throughput: Lower precision increases throughput, but teams must verify that task quality remains acceptable.
These trade-offs determine where hardware planning should focus. Long-context workloads need more memory capacity. High-concurrency workloads need more memory bandwidth. Mixture-of-experts workloads need faster interconnects.
8. Selection and Planning Recommendations
When evaluating a model architecture, follow these steps:
- Record both total and active parameters. Estimate storage and per-step compute separately.
- Based on the target context length and concurrency, calculate the peak KV cache memory.
- Confirm how the attention approach (grouped-query attention, sliding-window attention, or low-rank compression) affects quality. Verify with long-text evaluations on the target tasks.
- Check the load distribution of mixture-of-experts layers and estimate the communication overhead from expert parallelism.
- Combine the quantization scheme with measurements of actual memory and throughput gains. Complete a quality regression test before deployment.
With this process, teams can compare parameter scale, architectural design, and hardware cost within one framework. This reduces the chance of misjudging a model based on a single metric.
