Modern Large Language Model Architecture and Parameter Scale Explained

    This article explains how modern large language models are built around the decoder-only Transformer, and why total parameter count alone does not describe a model's cost or capability. It covers the typical Transformer block and its common engineering choices, how attention variants affect KV cache memory, how total, active, and effective parameters differ between dense and mixture-of-experts models, how to estimate parameter count and memory, and practical guidance for developers on model selection and deployment.

    1. Overall Structure: Decoder-Only Transformers Remain the Mainstream

    Modern large language models (LLMs) typically use a decoder-only autoregressive structure. Input text is converted into a sequence of tokens by a tokenizer, then mapped to word embedding vectors. These vectors pass through a stack of Transformer blocks. Finally, an output head maps the result to the vocabulary dimension, and the model predicts the next token autoregressively.

    A typical Transformer block contains two core sublayers:

    1. Self-attention sublayer: Models the dependencies between tokens. It usually uses a causal mask, so each position can only attend to itself and earlier positions.
    2. Feed-forward network sublayer: Applies a nonlinear transformation to each token representation. This sublayer holds a large share of the parameters and compute.

    Common engineering details in modern implementations include:

    • Pre-Norm structure: Normalization is applied before each sublayer’s input, which makes training more stable.
    • RMSNorm: A simpler alternative to LayerNorm, often used in large models.
    • Gated activations such as SwiGLU: These improve the expressive power of the feed-forward network.
    • Rotary position embeddings such as RoPE: These support extrapolation to long contexts and model relative positions.
    • Grouped-query attention: This reduces the memory cost of the KV cache.
    • Mixture-of-experts (MoE) feed-forward layers: These use sparse activation to scale the total parameter count.

    The pseudocode below abstracts the forward pass:

    1. x = embedding(tokens)
    2. for block in blocks:
    3. h = rms_norm(x)
    4. x = x + attention(h, causal_mask=True)
    5. h = rms_norm(x)
    6. x = x + feed_forward_or_moe(h)
    7. x = final_norm(x)
    8. logits = lm_head(x)

    The parameters mainly consist of the word embeddings, attention projection matrices, feed-forward weight matrices, normalization parameters, and the output head. If the input and output embeddings share weights, the total parameter count drops. If they do not share weights, the output head adds a significant number of parameters, especially when the vocabulary is large.

    2. Attention Mechanism: Structural Choices Directly Affect Inference Cost

    An attention layer typically includes query, key, and value projections, along with an output projection. In traditional multi-head attention, each head has its own independent Q, K, and V projections. To reduce KV cache usage during inference, modern models often use multi-query attention or grouped-query attention, in which several query heads share a smaller number of key-value heads.

    Attention variants have a limited effect on total parameter count, but they have a direct effect on inference memory and throughput. In long-context and high-concurrency workloads, the KV cache can become the largest consumer of GPU memory. It can be estimated approximately as:

    1. KV cache ≈ 2 × number of layers × number of KV heads × head dimension × sequence length × batch size × bytes per element

    Here, the factor 2 accounts for keys and values. With FP16, each element takes about 2 bytes. INT8 or lower precision reduces this further, but introduces trade-offs in accuracy and engineering complexity. When the context grows from 4K to 32K or 128K tokens, KV cache size grows roughly linearly. For this reason, grouped-query attention, paged cache management, prefix caching, and batching strategies are all important.

    3. Dense and Mixture-of-Experts Models: Total Parameters Are Not Active Parameters

    Feed-forward networks account for most of the parameters. In a dense model, every token passes through the same feed-forward network. A mixture-of-experts model splits the feed-forward layer into multiple experts, and a router selects the Top-k experts for each token. This design allows a large total parameter capacity to improve model capability, while each token activates only a subset of the parameters.

    When discussing parameter scale, it is therefore necessary to define three terms clearly:

    • Total parameters: The total number of model weights. They determine storage and loading costs.
    • Active parameters: The parameters actually used in the forward pass for a single token. They determine the compute per token.
    • Effective parameters: A capability measure that considers routing, shared experts, training strategy, and related factors. In engineering practice, it should not be treated as equal to total parameters.

    A simplified parameter estimation is shown below:

    1. Dense model parameters ≈ vocabulary × hidden dimension + layers × (4 × hidden dimension² + 3 × hidden dimension × feed-forward dimension)
    2. MoE total parameters ≈ vocabulary × hidden dimension + layers × (4 × hidden dimension² + number of experts × 3 × hidden dimension × feed-forward dimension + router parameters)
    3. MoE active parameters ≈ vocabulary × hidden dimension + layers × (4 × hidden dimension² + Top-k × 3 × hidden dimension × feed-forward dimension + router parameters)

    Key engineering issues in MoE architectures include router load balancing, expert parallel communication, capacity factor, shared expert design, and training stability. As total parameters grow, GPU memory capacity and expert communication can become bottlenecks. A smaller number of active parameters lowers the compute per token, but the system is more complex to build and operate.

    4. Parameter Scale Ranges and Model Selection

    In general, modern LLMs fall into several rough size ranges:

    Scale Common form Typical use cases
    1B–7B Dense small models Edge inference, lightweight Q&A, classification and extraction
    7B–30B Dense mid-sized models Enterprise knowledge Q&A, code assistance, text generation
    30B–100B Large dense models or small-scale MoE Complex reasoning, long-document processing, multi-task workloads
    100B–1T+ Mainly large-scale MoE High-difficulty general tasks, multimodal extension, cloud services

    These ranges are not strict boundaries. They help illustrate the trade-off between parameter count, capability, and cost. Small models are easier to deploy privately and offer lower-latency inference. Large models and MoE models are more capable, but they place higher demands on memory, communication, batch scheduling, and operational observability.

    Memory for model weights can be estimated as:

    1. Weight memory ≈ parameter count × bytes per parameter
    2. FP16: about 2 bytes per parameter
    3. INT8: about 1 byte per parameter
    4. INT4: about 0.5 bytes per parameter

    Actual inference also needs memory for the KV cache, activations, framework overhead, and batching headroom. Training requires additional memory for gradients, optimizer states, and activation recomputation, so training memory is typically much higher than inference memory.

    5. Deployment and Selection Recommendations

    When selecting a model, developers should evaluate the following factors in this order:

    1. Task complexity: For simple extraction and classification, start with a small model. For complex reasoning and long-document understanding, consider a larger model or an MoE model.
    2. Context requirements: Long contexts increase KV cache costs, so attention variants and cache management need attention.
    3. Latency and throughput: For online, low-latency services, focus on active parameters and batching. For offline batch processing, focus on total throughput and cost.
    4. Deployment conditions: Define the GPU memory limit, quantization strategy, concurrency level, and acceptable accuracy loss.
    5. Observability: Track token throughput, time to first token, KV cache hit rate, error rate, and resource utilization.

    On general-purpose cloud platforms, object storage can hold training corpora and model files, container platforms can run inference services, and logging and monitoring services can support observability. Platforms such as Baidu AI Cloud offer general-purpose cloud capabilities that can support this kind of engineering work. The specific architecture should still be designed around business metrics and a cost model. For details, refer to the relevant API documentation of each platform.

    6. Summary

    The core structure of modern LLMs is still the decoder-only Transformer, but engineering implementations keep evolving around normalization, position encoding, attention variants, gated feed-forward layers, and mixture-of-experts designs. Parameter scale cannot be judged by total parameters alone. A dense model should be assessed by total parameters and compute. An MoE model must be assessed by total parameters, active parameters, expert routing, and communication cost together. Model selection and deployment decisions are sound only when architecture, parameter definitions, memory estimates, and business metrics are considered together.