Understanding Modern LLM Architectures and Parameter Scales

    A practical guide to how modern large language models are built: decoder-only Transformer backbones, attention variants like MHA, MQA, and GQA, dense versus MoE feed-forward layers, and how to interpret total versus active parameters when evaluating, deploying, and selecting LLMs.

    Modern large language models typically follow a common blueprint: a decoder-only Transformer backbone, plus positional encoding, normalization, attention layers, feed-forward or Mixture-of-Experts (MoE) layers, and an output head. The real differences between models usually lie not in the top-level names, but in how attention is organized, whether the feed-forward layers are sparse, how parameters are allocated, how context length is extended, and what trade-offs are made in training and inference engineering. Understanding these structural components and how parameter scale is measured delivers more long-term value than memorizing specific model names.

    1. Overall Architecture: The Decoder Backbone Remains Dominant

    Most modern LLMs use an autoregressive decoder architecture. The basic objective is simple: given a preceding token sequence, predict the next token. A simplified decoder block can be expressed as:

    1. def decoder_block(x, mask):
    2. x = x + attention(norm(x), mask)
    3. x = x + feed_forward_or_moe(norm(x))
    4. return x

    Real models apply extensive engineering optimizations across the embedding layer, the stack of decoder blocks, and the output layer, but the core information flow remains the same: tokens are mapped to vectors, transformed through multiple layers of representation, and finally projected by the output head onto the vocabulary dimension to produce a probability distribution over the next token.

    Key components include:

    • Embeddings and output head: The vocabulary size determines the parameter count of the embedding and output head. Some models share weights between input embeddings and the output head to reduce parameters.
    • Normalization layers: A common practice is to normalize before each sub-layer, using variants such as RMSNorm to improve training stability.
    • Positional encoding: Rotary position embeddings (RoPE) and frequency-adjustment schemes are widely adopted to encode relative token positions and support context extension.
    • Residual connections: These keep gradient flow stable in deep networks and make stacking dozens or more layers feasible.
    • Attention sub-layer: Routes information between tokens; it is the key driver of long-context capability and KV cache overhead.
    • Feed-forward sub-layer: Carries a large share of parameters and nonlinear transformation. In dense models it is typically a two-layer or multi-layer perceptron; in sparse models it may be replaced by a routed expert network.

    In terms of parameter distribution, the total parameter count of a dense model is roughly the sum of attention parameters, feed-forward parameters, embedding parameters, and output head parameters across all layers. A rough formula:

    1. P_total ≈ P_embed + L × (P_attn + P_ffn) + P_head

    where L is the number of layers. This formula is for building order-of-magnitude intuition; actual implementations are also affected by biases, normalization parameters, vocabulary size, hidden dimensions, head counts, and other factors.

    2. Attention Structures: MHA, MQA, GQA, and the KV Cache

    Multi-head attention (MHA) is the fundamental mechanism for modeling relationships between tokens. Traditional MHA assigns independent key and value heads to each query head, which is expressive but leads to a large KV cache at inference time. To reduce memory and bandwidth pressure, the industry commonly uses variants such as Multi-Query Attention (MQA) and Grouped-Query Attention (GQA), where multiple query heads share a smaller number of key-value heads, significantly shrinking the KV cache.

    KV cache size can be estimated as:

    1. M_kv ≈ 2 × L × H_kv × D_h × S × B × b

    where L is the number of layers, H_kv the number of key-value heads, D_h the per-head dimension, S the sequence length, B the batch size, and b the bytes per element; the factor of 2 accounts for keys and values. The formula shows that long contexts, large batches, and more key-value heads all compound memory pressure. Modern models therefore reduce overhead through grouped queries, low-rank compression, paged cache management, and cache quantization.

    Choosing an attention structure is not simply “the cheaper the better.” Too few key-value heads can hurt expressiveness; too many increase deployment cost. The right choice depends on context length, concurrency, latency targets, and hardware memory bandwidth.

    3. Feed-Forward Networks and MoE: Dense vs. Sparse

    The feed-forward network usually accounts for the largest share of model parameters. In dense models, every token passes through the same feed-forward parameters. In sparse Mixture-of-Experts models, the model contains multiple expert networks, but each token activates only a few of them. This gives rise to two distinct measurements:

    • Total parameters: The sum of all weights, which determines storage and loading footprint.
    • Active parameters: The parameters actually used in a single token’s forward pass, which better reflects compute cost and part of inference cost.

    A simplified expression for active parameters in MoE models:

    1. P_active ≈ P_embed + L × (P_attn + P_shared + (k / N) × P_experts) + P_head

    where N is the number of experts and k the number of experts activated per token. The formula shows that total parameters can be very large while active parameters remain far smaller. MoE’s advantage is greater representational capacity from a larger parameter pool while keeping per-token compute in check; the challenges are routing balance, expert-parallel communication, load fluctuation, and deployment complexity.

    Dense models, by contrast, have a simpler structure and stable inference paths, making them suitable for scenarios that demand predictable latency. The two are not substitutes but different trade-offs among capacity, cost, and engineering complexity.

    4. Parameter Scales: Common Ranges and Evaluation Criteria

    There is no single standard for parameter scale. Industry discussions often group models into lightweight, mid-size, large dense, and sparse MoE categories. The table below gives general discussion ranges for building intuition only — it is not a commitment about any specific product:

    Category Typical total parameters Active parameter profile Typical focus
    Lightweight models Hundreds of millions to 7B Usually close to total On-device, low latency, cost-sensitive
    Mid-size models 7B to 30B Usually close to total General inference, fine-tuning, private deployment
    Large dense models 30B to 100B Usually close to total High-quality generation, complex tasks
    Sparse MoE Hundreds of billions to trillions (total) Active can be far below total High throughput, large capacity, high engineering complexity

    It is worth emphasizing: parameter count is not the sole measure of capability. Data quality, training token count, vocabulary design, context length, alignment strategy, inference-time compute, and tool-use ability all affect final performance. Evaluations should consider total parameters, active parameters, layer count, hidden dimension, attention head configuration, context window, quantization support, and deployment cost together.

    5. Long-Context and Multimodal Extensions

    Long-context capability typically comes from three sources: positional encoding extrapolation or frequency adjustment, attention computation optimizations, and training data and task design. Simply enlarging the context window does not mean the model can effectively use long documents; training must cover long-range dependencies, and KV cache growth must be controlled at inference time.

    Multimodal models typically add a vision encoder and an alignment layer in front of the language backbone, mapping images and other modalities into representations the language model can process. Their parameter scale cannot be judged by the language backbone alone — the vision encoder, projection layers, and cross-modal alignment modules must also be counted. Deployment requires separately evaluating image preprocessing, visual encoding, language generation, and cache footprint.

    6. Training and Inference Engineering Essentials

    Common training objectives include next-token prediction, instruction fine-tuning, and preference optimization. Engineering techniques include data parallelism, tensor parallelism, pipeline parallelism, and expert parallelism. The choice of parallelism strategy depends on model size, cluster interconnect bandwidth, and memory capacity.

    On the inference side, processing splits into a prefill phase and a decode phase. Prefill processes the input in parallel, while decode generates tokens one at a time and is often memory-bandwidth bound. Common optimizations include:

    • Weight quantization and KV cache quantization;
    • Continuous batching and request scheduling;
    • Paged KV cache management;
    • Speculative decoding;
    • Operator fusion and efficient attention implementations;
    • Chunked or sparse computation for long contexts.

    Memory can be estimated as:

    1. M_weight ≈ P × b
    2. M_total ≈ M_weight + M_kv + M_activation + M_runtime

    where b is the bytes per parameter. FP16 uses roughly 2 bytes, INT8 roughly 1 byte, and INT4 roughly 0.5 bytes. Real deployments must also reserve room for activations, temporary buffers, communication buffers, and runtime overhead. When deploying in general-purpose cloud environments such as Baidu AI Cloud, you can combine container platforms for inference services, object storage for model weights, and logging and monitoring services for observability; actual sizing still depends on business concurrency, context length, and latency targets.

    7. Selection Guidance: Building a Decision Chain from Architecture to Scale

    When selecting a model, evaluate in the following order:

    1. Task complexity: Simple classification, extraction, and summarization can favor small to mid-size models; complex reasoning, long-document analysis, and multi-turn agent tasks need greater capacity.
    2. Context requirements: Long contexts amplify KV cache pressure — prioritize key-value head configuration, cache management, and quantization capabilities.
    3. Latency and throughput: For online low-latency scenarios, focus on active parameters and decode speed; for offline high-throughput scenarios, focus on batching and expert-parallel efficiency.
    4. Deployment cost: Total parameters determine weight storage, active parameters drive compute, and KV cache size caps concurrency.
    5. Controllability: Private deployment, fine-tuning, quantization, and observability should be assessed alongside model architecture.

    Overall, the evolution of modern LLM architectures revolves around three themes: supporting long contexts through more efficient attention and cache management, balancing capacity and compute with dense or sparse feed-forward layers, and controlling cost through engineered parallelism and quantized deployment. Parameter scales from hundreds of millions to trillions of total parameters all have their place. The key is understanding the relationship between total parameters, active parameters, and deployment overhead — not simply chasing bigger numbers.