Large Language Model Architecture and Parameter Scale Explained
This article breaks down the two fundamentals that shape large language model performance and cost: network architecture and parameter scale. It compares dense and sparse Mixture-of-Experts designs, reviews efficiency upgrades to attention, position encoding, and normalization, and explains how parameter counts translate into memory and compute requirements. It also covers inference strategies such as parallelism, KV cache management, speculative decoding, and quantization, ending with practical selection guidance.
1. Why Architecture and Parameter Scale Come First
In engineering practice, benchmark scores alone cannot tell you whether a language model is a good fit. Two underlying facts determine deployment cost, throughput, and the ceiling on quality: the network topology (how information flows within and across layers) and the parameter scale (model capacity and the fraction of it that is active). Topology determines how much useful computation you can extract per unit of compute; parameter scale determines memory footprint, parallelization strategy, and the minimum viable batch size.
One distinction matters throughout this article: total parameter count and the number of parameters actually activated in a single forward pass are not the same thing. In a dense architecture they are equal. In a sparse Mixture-of-Experts (MoE) architecture, the total can reach hundreds of billions or even trillions, while each token activates only a small subset. Every cost discussion below rests on this difference.
2. Four Dimensions of Mainstream Architectures
2.1 Dense Feed-Forward vs. Sparse Mixture-of-Experts
A dense model sends every token through the same computation path in every layer. It is simple to implement, has contiguous memory access, and suits small-to-medium scale deployments with high concurrency. A sparse MoE replaces the feed-forward sublayer with multiple expert networks plus a routing gate, activating only the Top-K experts. The payoff is parameter growth with roughly constant per-token computation. The costs are that memory must hold all experts, that uneven routing loads leave some devices idle, and that capacity factors, auxiliary load-balancing losses, and expert parallelism are needed to compensate.
An illustrative configuration (shown only to explain the fields, not any specific product interface):
model_config = {"hidden_size": 7168,"num_layers": 61,"attn": "grouped_query_attention", # Shares key/value heads to shrink the KV cache"ffn": {"type": "moe","num_experts": 256,"experts_per_token": 8, # Roughly 3% sparse activation"shared_experts": 1, # Carries general knowledge, stabilizes training},"max_position": 131072,}
2.2 Efficiency Upgrades to Attention
The problem with standard multi-head attention is not quality but that the KV cache grows linearly with sequence length. Three改造 are common in the industry. First, grouped-query attention and multi-query attention let multiple query heads share one set of key/value heads. Second, low-rank compressed key/value projection squeezes the cache into a low-dimensional latent vector and reconstructs it. Third, sparse or block attention computes only a local window plus a few global tokens. The three can be combined, and together they support contexts in the six-figure token range.
2.3 Position Encoding and Context Extrapolation
Rotary position encoding is now the de facto baseline. Long-context capability comes mainly from three things: staged window expansion during training, extrapolation via position interpolation or frequency scaling, and cache reuse plus prefix sharing on the inference side. What matters more in engineering is “effective context”: retrieval hit rate and the use of information in the middle of a long input often degrade noticeably after tens of thousands of tokens, which is not the same as the advertised window size.
2.4 Normalization, Activation, and Training Stability
Pre-normalization with residual connections is the default choice, and gated linear unit activations dominate the feed-forward layers. To reduce numerical fluctuation in large-scale training, common practices include low-precision accumulation, logit scaling for attention and routing, and keeping selected modules at higher precision.
3. Realistic Parameter Ranges and Cost Math
General-purpose models currently fall into three tiers. The lightweight tier has billions of parameters and can run on a single GPU or on-device. The mainstream tier has tens of billions of dense parameters or hundreds of billions of total parameters in sparse form, and usually needs multiple GPUs in one machine. The flagship tier reaches trillions of total parameters in sparse form and depends on multiple machines with expert parallelism.
A useful rule of thumb: inference memory is roughly the parameter count multiplied by bytes per parameter (2 for FP16, 1 for INT8, about 0.5 for INT4), plus KV cache and activation overhead. At 670 billion parameters in FP16, the weights alone come to roughly 1.3 TB, which is why quantization and cache compression are necessities rather than optimizations. On the training side, scaling follows an approximate power law: under a fixed compute budget, parameter count and training tokens must be scaled up together, and piling on parameters alone yields diminishing returns.
4. Inference Efficiency: From Architecture to Serving
- Parallelism strategies: tensor parallelism reduces per-layer latency, pipeline parallelism improves device utilization, expert parallelism carries the sparse layers, and sequence parallelism handles long contexts.
- Caching and batching: paged KV cache management limits fragmentation, continuous batching raises throughput, and prefix caching means system prompts and few-shot examples are computed only once.
- Speculative decoding: a small model drafts and the large model verifies, with the largest gains at small batch sizes.
- Quantization and distillation: weight quantization lowers the memory barrier, and distillation moves flagship capability into the lightweight tier, forming a tiered device-cloud deployment.
5. How to Choose
Choose a dense mainstream model if you want stability and low operational complexity. Choose a sparse architecture if throughput is the priority and memory is plentiful. Choose the lightweight tier with quantization for on-device use or high-concurrency short requests. When evaluating, test effective context and long-tail tasks on your own corpus rather than relying on advertised parameter counts and window sizes. In related practice at Baidu AI Cloud, model serving is typically combined with general capabilities such as container platforms, object storage, logging, and monitoring and alerting to form an observable, elastically scalable inference pipeline.
