Understanding LLM Architecture and Parameter Scale: A Technical Guide

    A practical guide to how large language model architecture shapes parameter count, memory usage, and inference cost. Covers Transformer decoder structure, dense versus Mixture-of-Experts designs, attention variants, KV cache estimation, position encoding, and deployment planning tips.

    1. Why Architecture and Parameter Scale Matter

    When choosing or deploying a large language model, common questions include: how much VRAM does the model need, what is the latency per request, what drives the cost per million tokens, and is the quality gain from more parameters worth it. All of these questions can only be answered by starting from the model’s architecture.

    Parameter count is the most intuitive metric, but it only describes how “big” a model is. Two models with hundreds of billions of parameters can differ by several times in inference compute depending on whether they use a dense or a Mixture-of-Experts architecture. How attention is implemented affects VRAM usage for long-context workloads. Position encoding and context extension methods determine the maximum sequence length a model can handle. Understanding architecture is therefore the prerequisite for resource estimation and solution evaluation.

    2. Basic Structure of the Transformer Decoder

    Almost all current large language models are based on the Transformer decoder architecture. A typical decoder layer contains the following components:

    1. Token embedding layer: maps tokens to vectors; its parameter count is vocabulary size times hidden dimension.
    2. Multi-head attention layer: computes dependencies between positions in the sequence.
    3. Feed-forward network (FFN) layer: applies a nonlinear transformation to each position’s vector and usually holds most of the parameters.
    4. Normalization and residual connections: stabilize training, commonly using pre-normalization.
    5. Output layer: maps the final hidden states back to vocabulary dimension, often sharing weights with the token embeddings.

    The total number of layers, hidden dimension, number of attention heads, FFN intermediate dimension, and vocabulary size together determine the parameter count. The following pseudocode illustrates the relationship between these hyperparameters and total parameters:

    1. function estimate_params(layers, hidden, ffn_dim, vocab, tie_embedding):
    2. attn = 4 * hidden * hidden # Q, K, V, and O projection matrices
    3. ffn = 3 * hidden * ffn_dim # three matrices of the gated FFN
    4. per_layer = attn + ffn
    5. embed = vocab * hidden
    6. head = 0 if tie_embedding else vocab * hidden
    7. return layers * per_layer + embed + head

    This function ignores the small parameter counts of normalization layers and bias terms, which is sufficient for order-of-magnitude estimation.

    3. Dense Models vs. Mixture-of-Experts Models

    3.1 Dense Models

    Dense models use all parameters in every forward pass. Their structure is simple, training and inference behavior is predictable, and the engineering ecosystem is relatively mature. The drawback is that compute per token grows with parameter count, so inference cost rises roughly linearly with scale.

    3.2 Mixture-of-Experts Models

    Mixture-of-Experts (MoE) models split the feed-forward network into multiple expert subnetworks. A router decides which experts process each token, typically via top-k selection—for example, activating only 2 experts per token.

    This introduces two concepts:

    • Total parameters: the sum of all experts and shared components; this determines model capacity and storage requirements.
    • Active parameters: the parameters actually involved in computing each token; this determines per-step compute.

    Suppose a model has 8 experts, each with E parameters, shared components with S parameters, and each token activates 2 experts:

    1. total_params = S + 8 * E
    2. active_params = S + 2 * E

    When E is much larger than S, active parameters are roughly one quarter of total parameters, and per-step compute is significantly lower than a dense model of the same total size. This is why a model can have a very large total parameter count while inference speed resembles that of a mid-sized model.

    MoE architectures also come with costs:

    • VRAM must still hold all expert parameters, so deployment requirements do not decrease with lower active parameters.
    • Unbalanced routing can overload certain experts, requiring load-balancing losses or capacity limits to constrain.
    • In multi-GPU deployments, experts are distributed across devices, and moving tokens between devices adds communication overhead.

    3.3 Selection Perspective

    If your task is latency-sensitive and hardware is limited, small to mid-sized dense models are usually easier to deploy. If you need greater knowledge capacity and can accept higher VRAM demands and communication costs, MoE architectures offer better value. When selecting a model, compare total parameters, active parameters, VRAM usage, and throughput together—not just the advertised parameter count.

    4. Attention Variants and Their Memory Cost

    4.1 Attention Variants

    The core attention computation scales with the square of sequence length, and inference requires caching the keys and values of previous tokens—the KV cache. To reduce cache size, several common variants have emerged:

    • Multi-Head Attention (MHA): every query head has its own key and value heads; strong expressiveness but the largest cache.
    • Multi-Query Attention (MQA): all query heads share a single set of keys and values; smallest cache, but quality may degrade.
    • Grouped-Query Attention (GQA): query heads are grouped, with each group sharing a set of keys and values; a common compromise between quality and cache size.
    • Sparse or sliding-window attention: attends only to local or selected positions, reducing compute for long sequences.
    • Low-rank KV compression: projects keys and values into a lower-dimensional latent space before caching, further compressing memory.

    4.2 Estimating the KV Cache

    The bytes per token occupied by the KV cache can be calculated as:

    1. kv_bytes_per_token = 2 * layers * kv_heads * head_dim * bytes_per_value

    where 2 accounts for keys and values. For a 32-layer model with 8 KV heads, head dimension 128, and 16-bit floating point values:

    1. 2 * 32 * 8 * 128 * 2 = 131072 bytes ≈ 128 KiB / token

    With a context of 32,768 tokens, a single sequence’s KV cache is about 4 GiB. If a service needs to handle 16 such sequences concurrently, the cache alone requires roughly 64 GiB—something that must be accounted for when planning server memory.

    Reducing KV heads from 32 to 8 with the same configuration cuts the cache to one quarter. This shows how the choice of attention variant directly affects concurrency capacity and long-context costs.

    5. Position Encoding and Long-Context Extension

    Transformers are inherently order-agnostic, so position encoding is needed to inject positional information. The current mainstream approach is Rotary Position Embedding (RoPE), which applies position-dependent rotations to queries and keys so that attention scores depend on relative positions.

    The context length used during training is usually limited. If you directly inference on longer text, positional information falls outside the training distribution and quality drops noticeably. Common extension approaches include:

    1. Position interpolation: scale position indices proportionally so longer positions fall within the range seen during training.
    2. Frequency scaling: apply different scaling strategies to different frequency components of the rotary encoding, balancing short-range and long-range dependencies.
    3. Continued training: perform a small amount of additional training on longer text so the model adapts to the new position distribution.

    A model’s advertised context length is not the same as its effective length. In practice, evaluate the model’s stability at your target length using retrieval, summarization, and chunked processing.

    6. Parameter Scale and Resource Estimation

    6.1 Weight Memory

    Model weight memory can be estimated as the number of parameters multiplied by bytes per parameter:

    1. weight_memory = params * bytes_per_param

    Bytes per parameter at different precisions:

    • 16-bit floating point: 2 bytes
    • 8-bit integer: 1 byte
    • 4-bit integer: roughly 0.5 bytes

    For a 70B parameter model, 16-bit storage requires about 140 GB, while 4-bit quantization reduces this to about 35 GB. Actual memory usage also includes activations, the KV cache, and runtime overhead—typically reserve at least 20% headroom.

    6.2 Compute Estimation

    For a dense model, generating each token takes roughly two multiply-accumulate operations per parameter, i.e., about 2x the parameter count in floating-point operations. MoE models are calculated using active parameters instead. This means that at the same total parameter count, an MoE model has lower per-step compute, but its memory requirements remain unchanged.

    6.3 Rough Scale Tiers

    The industry typically divides model sizes into the following ranges. These are empirical divisions, and standards vary by scenario:

    • Below 1B parameters: suitable for edge devices and simple classification or extraction tasks.
    • Several billion to low tens of billions: suitable for general-purpose chat and lightweight services, deployable on a single GPU or a few GPUs.
    • Tens of billions: strong capability, usually requiring multiple GPUs or high-memory devices.
    • Hundreds of billions and above, or MoE models with total parameters in the hundreds of billions to trillions: used mainly for complex reasoning and comprehensive tasks, requiring distributed inference for deployment.

    The relationship between parameter scale and quality is not linear. Data quality, training steps, post-training methods, and context management at inference time all significantly affect final performance.

    7. Engineering Considerations for Inference Deployment

    When deploying large models, costs can be controlled in several ways:

    • Quantization: reduce weight precision to lower memory and bandwidth pressure; verify the accuracy loss.
    • Batching: combine multiple requests into one computation to improve hardware utilization, at the cost of increased per-request queuing time.
    • Cache reuse: reuse the KV cache for requests sharing the same prefix, ideal for multi-turn conversations and fixed system prompts.
    • Parallelism strategies: tensor parallelism splits computation within a layer, pipeline parallelism splits layers, and expert parallelism splits experts in MoE models.
    • Monitoring metrics: track time-to-first-token, generation speed, memory usage, and request queuing time—not just average throughput.

    A simple capacity planning workflow:

    1. 1. Calculate static model memory based on weight precision
    2. 2. Calculate KV cache based on target concurrency and context length
    3. 3. Reserve headroom for activations and runtime overhead
    4. 4. Choose GPU count and parallelism strategy to meet memory requirements
    5. 5. Load-test with real traffic to calibrate throughput and latency

    8. Selection and Practical Recommendations

    1. Clarify the task type. Classification, extraction, and formatting tasks usually do not need the largest models—validate with smaller models first.
    2. Compare total and active parameters together. For MoE models, deployment cost is mainly driven by total parameters, while inference speed is driven by active parameters.
    3. Account for long-context costs. Longer contexts mean larger KV caches and attention computation; specify the combination of maximum length and concurrency in your plan.
    4. Validate with your own evaluation set. Public benchmarks can differ substantially from real business scenarios; evaluate accuracy, stability, and cost with real samples.
    5. Keep room for swapping models. Decouple the interface layer from the model layer so you can switch between models of different sizes and architectures.

    9. Summary

    LLM architecture determines how parameters are stored and computed. Dense models are straightforward, while MoE models trade lower per-step compute for greater total capacity. Attention variants and the KV cache determine memory pressure under long contexts and high concurrency, and position encoding methods determine whether the context can be reliably extended. With these concepts in hand, you can estimate memory and compute from layer count, hidden dimension, head count, and expert configuration, and use that to plan your deployment.