Large Language Model Architecture Explained: Parameter Scale and Hardware Constraints
A practical breakdown of how LLM architectures are shaped by three hardware constraints—compute, memory bandwidth, and inter-device communication—covering total vs. active parameters, layer ordering strategies, and KV cache optimization techniques like GQA, MQA, MLA, sliding window, and linear attention. Includes worked examples for estimating MoE parameter counts and KV cache size.
Why All Architecture Design Revolves Around the Same Set of Constraints
Changes to large language model architectures may look scattered—attention variants, expert routing, layer ordering, and residual connections, among others. From an engineering perspective, however, every one of these changes must answer three questions. The first is compute: how many floating-point operations are needed per token. The second is memory access: how much VRAM the weights and KV cache occupy, and how many bytes must be read from memory at each decoding step. The third is communication: how much cross-device data transfer expert dispatch and tensor sharding generate during multi-GPU parallelism.
During autoregressive decoding, generating each token requires reading a large volume of weights and cached history, while the computation per step is small—so the bottleneck usually lands on memory bandwidth. This is why the goal of many architectural optimizations is not to reduce theoretical FLOPs, but to reduce the amount of data moved per step. Understanding this point makes the motivation behind various design trade-offs much clearer.
Total Parameters vs. Active Parameters
Total parameters are the sum of all learnable weights in a model; they determine storage footprint and model capacity. Active parameters are the number of weights actually involved in computation when processing a single token; they determine the per-token compute cost and set a lower bound on decoding latency. In dense models, the two are equal. In Mixture-of-Experts (MoE) models, only the experts selected by the router participate in computation at each layer, so active parameters are far smaller than total parameters.
The following example estimates both parameter counts for the feed-forward part of a single layer (attention excluded):
def ffn_params(hidden, inter, gated=True):# A gated feed-forward network has three matrices; a plain FFN has twomats = 3 if gated else 2return mats * hidden * interdef moe_layer_params(hidden, inter, n_experts, top_k, n_shared=0):per_expert = ffn_params(hidden, inter)total = (n_experts + n_shared) * per_expertactive = (top_k + n_shared) * per_expertreturn total, activetotal, active = moe_layer_params(hidden=4096, inter=1536, n_experts=128, top_k=8, n_shared=1)print(f"Total params/layer: {total/1e9:.2f}B, Active params/layer: {active/1e9:.3f}B")
This example uses a hypothetical configuration for demonstration only and does not correspond to any specific model. The output shows that total parameters are roughly an order of magnitude larger than active parameters. The ratio changes as the number of experts and routing settings vary: the more routed experts and the fewer activated per token, the wider the gap between total and active parameters.
Layer Ordering
Layer ordering determines which computation form is used at different depths. A common approach is to use dense feed-forward layers in the first few layers, allowing low-level features to stabilize first, then replace subsequent layers with MoE layers—trading a lower active cost for greater model capacity. Attention can also alternate by layer: some layers use global attention while the rest use sliding window attention or linear attention, with a small number of global layers responsible for aggregating long-range information.
The motivation behind this arrangement lies in cache structure. The KV cache of global attention grows linearly with context length, while local attention has a fixed cache ceiling. Hybrid layouts preserve long-range dependency capability while keeping cache overhead within an acceptable range.
Attention Sparsification and the KV Cache
Multi-head attention stores independent keys and values for every head. Grouped-query attention (GQA) lets multiple query heads share a single set of key-value heads, and multi-query attention (MQA) is its extreme form, keeping only one set. Multi-head latent attention (MLA) first compresses keys and values into low-dimensional latent vectors before caching, then projects them back when needed, further shrinking cache size. Sliding window attention only attends to the most recent fixed-length tokens, while linear attention replaces the full history sequence with a recurrent state.
KV cache size can be computed as: 2 × layers × KV heads × head dimension × sequence length × batch size × bytes per element. The factor of 2 accounts for the two separate caches for keys and values.
def kv_cache_bytes(layers, kv_heads, head_dim, seq_len, batch, dtype_bytes=2):# The factor of 2 accounts for the key and value cachesreturn 2 * layers * kv_heads * head_dim * seq_len * batch * dtype_bytes
