Understanding Large Language Model Architectures and Parameter Scale: A Technical Breakdown
This article explains how to evaluate a large language model by looking at its architecture before its parameter count. It separates total parameters, activated parameters per token, and inference memory footprint, then walks through decoder-only structure, attention variants such as GQA, MQA, and linear or hybrid attention, RoPE-based position encoding, dense versus sparse MoE designs, and a practical selection checklist covering KV cache estimation, batching, quantization, and scaling. Readers will gain a framework for identifying a model's structure and estimating its serving cost without relying on a single parameter table.
1. Why Structure Comes Before Parameter Count
Before asking how “big” a model is, it helps to define which quantity “big” refers to. The industry generally splits parameter scale into three independent metrics: total parameter count, activated parameters per token, and the memory and bandwidth actually consumed during inference. The mixture-of-experts (MoE) approach decouples the three completely. Total parameters can reach hundreds of billions or even trillions, yet each token passes through only a small subset of expert networks, so activated parameters are often just one tenth to one third of the total. Judging inference cost by total count alone almost always leads to the wrong conclusion.
Structurally, today’s mainstream decoder-only architectures can be abstracted as stacked blocks of “normalization + attention + feed-forward network,” each with a residual connection. The differences show up in four places: how attention is computed, how positional information is injected, whether the feed-forward layer is dense or sparse, and where normalization sits.
2. The Evolution of Attention Mechanisms
The complexity of standard multi-head self-attention grows with the square of sequence length, which directly determines the cost of long-context capability. Two optimization paths are widely adopted:
- Grouped-query attention (GQA) and multi-query attention (MQA): multiple query heads share a set of key-value heads, shrinking the KV cache by a multiple. This is the default configuration for long-context inference.
- Linear attention and hybrid attention: kernel functions or state updates replace full softmax interaction, pushing complexity down to linear. Pure linear designs still lose accuracy on precise retrieval tasks, so a common pattern is interleaving a few full-attention layers with mostly linear or sparse layers.
In addition, sparse attention (scoping computation by block, by window, or by token importance) and schemes that push attention down to a local window are also used heavily within specific length ranges.
A schematic layer description (pseudocode):
for layer_idx in range(num_layers):x = x + attn_norm(x) # Pre-normalizationx = x + moe_or_dense_ffn(x) # Sparse or dense feed-forwardx = x + post_norm(x) # Post-normalization (used by some designs)
3. Positional Encoding and Long-Context Extrapolation
Rotary position embedding (RoPE) has become the de facto standard. Its extrapolation ability depends on scaling strategies along the frequency dimension: a common approach is to interpolate low-frequency dimensions or scale them piecewise by wavelength, keeping the attention distribution relatively stable beyond the training length. In engineering terms, this must be paired with continued pre-training on long text during the training phase; encoding tricks alone cannot conjure long-context capability out of nothing.
4. Dense or Sparse: Two Paths to Parameter Scale
Dense models are usually more stable at the same activated parameter count and suit small to mid-scale deployment. Sparse mixture-of-experts models can hold greater knowledge capacity under a given compute budget, but three engineering problems must be solved: routing load balancing (avoiding overload on a few experts), the communication overhead introduced by expert parallelism, and expert caching and scheduling at inference time. A common compromise in practice is a “shared expert + routed expert” structure, where the shared part carries general capability and the routed part carries domain specialization.
By scale range, the observable distribution in the industry is roughly: device-side and lightweight scenarios sit in the billions; mainstream conversational models sit in the tens of billions to hundreds of billions of activated parameters; sparse flagship models can reach hundreds of billions to trillions in total parameters, with activated parameters kept within the low hundreds of billions.
5. From Structure to Deployment: A Selection Checklist
- Memory estimation: base it mainly on activated parameters and the KV cache, where KV cache ≈ layers × 2 × KV heads × head dimension × sequence length × bytes per value of precision.
- Batching strategy: for long context, prioritize paged KV management and prefix reuse, which can significantly cut repeated computation.
- Precision and quantization: low-bit weight quantization combined with KV cache quantization is the main lever for reducing long-context cost.
- Elastic scaling: inference services should support pooling by sequence length so that long and short requests do not interfere with each other.
6. A General Pattern for Running These Models in the Cloud
To serve models like these, the general practice is to use a container platform for orchestration and elastic scaling of inference services, object storage for model weights and datasets, a message queue to smooth out traffic peaks, and logging plus monitoring and alerting systems for observability of throughput, latency, and error rates. The general capabilities offered by Baidu AI Cloud can cover these pieces, letting teams focus on model structure and business fit rather than infrastructure operations.
7. Summary
To determine what structure a model has and how large its parameters are, the effective path is to confirm in order: the attention form, the positional encoding scheme, the sparsity of the feed-forward layer, and the normalization and residual layout, then separate total parameters from activated parameters. With this framework in hand, you can quickly assess structure and estimate cost when facing continuously updated model versions, without depending on any single parameter table.
