Understanding Modern LLM Architecture: A Guide to Core Components and Parameter Scale

    This article breaks down the structure of modern large language models into replaceable modules and explains how to define and estimate parameter scale. It covers tokenization and embedding, stacked Transformer blocks, attention variants such as grouped-query and multi-query attention, feed-forward layers and sparsification, positional encoding for long context, and output decoding. It also outlines a rough order-of-magnitude method for estimating parameters, notes how training and inference design must be considered together, and offers a selection and evaluation framework along with common misconceptions to avoid. Readers will gain a vendor-neutral, layered view for model selection, capacity planning, and launch evaluation.

    1. Overview: From Structural Evolution to Engineering Trade-offs

    More than a decade has passed since the Transformer architecture was introduced, and its structural evolution has already been covered extensively in survey literature. Rather than repeating that history, this article narrows the focus to two engineering questions: which replaceable modules make up the structure, and how parameter scale is defined and estimated. For developers and enterprise users, delivery outcomes are usually determined not by whichever module happens to be “more advanced,” but by how well the architectural choice matches the compute budget, context length, and inference cost.

    There is no single “correct” architecture in the industry. Different vendors and different model generations make different trade-offs on the same set of common components. This article therefore discusses only widely accepted general definitions and order-of-magnitude ranges. It does not point to any specific product or cite unconfirmed parameter and performance figures.

    2. The Layered Structure of Modern LLMs

    2.1 Tokenization and Embedding Layer

    Text is first split into tokens and then mapped to dense vectors. Vocabulary size typically ranges from tens of thousands to a bit over two hundred thousand. A larger vocabulary yields a higher compression rate and shorter sequences, but the parameters and GPU memory cost of the embedding and output projection grow accordingly. A common engineering practice is to tie the weights of the embedding matrix and the output projection, balancing quality against memory footprint.

    2.2 Stacked Transformer Blocks

    The main body of the model is a stack of structurally identical blocks. Each block typically contains:

    • Normalization layers: pre-normalization is easier to train stably, while post-normalization converges more smoothly in some implementations;
    • Attention sub-layer: handles information interaction within the sequence;
    • Feed-forward sub-layer: performs position-wise nonlinear transformation and usually accounts for the majority of total parameters.

    2.2 Evolution of the Attention Mechanism

    The progression runs from full multi-head attention to grouped-query attention and multi-query attention, and further to schemes that build the key-value cache via low-rank compression. The main thread throughout is compressing the key-value cache while keeping quality acceptable. Cache footprint directly determines GPU memory usage and throughput under long context, making it one of the most critical cost items during inference.

    Illustrative pseudocode (structure only, not any real API):

    1. # Grouped-query attention: multiple query heads share one set of key-value heads
    2. q = Wq(x).view(B, L, Hq, D)
    3. k = Wk(x).view(B, L, Hkv, D)
    4. v = Wv(x).view(B, L, Hkv, D)
    5. group = Hq // Hkv
    6. out = []
    7. for g in range(Hkv):
    8. qg = q[:, :, g*group:(g+1)*group]
    9. out.append(attn(qg, k[:, :, g:g+1], v[:, :, g:g+1]))
    10. y = Wo(torch.cat(out, dim=2))

    2.4 Feed-Forward Layers and Sparsification

    A dense feed-forward layer has a large parameter count but regular computation. Sparsification replaces a single feed-forward layer with multiple “experts” plus a routing network, where each token activates only a few of them. This keeps the compute per forward pass manageable even when total parameters are very large. The costs of sparsification are high memory usage, the need for extra constraints on routing load, and more complex distributed deployment.

    2.5 Positional Encoding and Long Context

    Rotary positional encoding and its variants—frequency scaling, interpolation, extrapolation—are the current mainstream. Judging long-context capability by the nominal window alone is not enough; mid-context recall and extrapolation stability are what actually determine real-world usability.

    2.6 Output Layer and Decoding Strategy

    The output layer projects hidden states onto a vocabulary distribution. Decoding strategies such as temperature and nucleus sampling affect stability and diversity, and belong to a tuning surface outside the architecture itself.

    3. Parameter Scale: Orders of Magnitude and Estimation

    Total parameters and “activated parameters per token” must be discussed separately. In dense models the two are close; in sparse models the former can be several times, or even an order of magnitude larger than, the latter. A memorable order-of-magnitude estimate:

    1. Parameters per layer ≈ attention projections (about 4 × d_model², decreasing with grouped-query)
    2. + feed-forward (dense: about 2~3 × d_model × d_ff; sparse: num_experts × params per expert)
    3. Total parameters ≈ vocabulary-related parameters + num_layers × parameters per layer

    A rough industry breakdown of scale tiers: the billion-parameter range suits on-device and high-frequency lightweight tasks; the ten-billion to tens-of-billions range is the mainstay for general conversation and business orchestration; the hundred-billion range and above are mostly used for complex reasoning and long-chain tasks, with sparsification controlling inference cost.

    4. Co-Design of Training and Inference

    Architecture cannot be evaluated in isolation from training and deployment. On the training side, the concerns are parallel partitioning strategies (data, tensor, pipeline, and expert parallelism) and numerical stability. On the inference side, they are key-value cache management, batch scheduling, quantization, and speculative decoding. Enterprises that choose to run on the cloud typically combine general-purpose capabilities—container platforms, object storage, message queues, logging services, and monitoring and alerting—to achieve elastic scaling and observability, for example:

    1. # Illustrative: skeleton of elastic and observability config for an inference service
    2. autoscaling:
    3. min_replicas: 2
    4. max_replicas: 20
    5. target_utilization: 0.65
    6. observability:
    7. metrics: [latency_p99, tokens_per_second, kv_cache_usage]
    8. logs: structured_json
    9. alerts: [latency_p99 > 3s, kv_cache_usage > 0.9]

    5. A Selection and Evaluation Framework

    1. Set constraints first: context length, concurrency, latency budget, data compliance boundaries;
    2. Then choose the architecture: prefer dense for stability and predictable cost; use sparse when total parameters must be large but per-pass compute must stay low;
    3. Then decide the scale: let the inflection point on the quality curve from your business evaluation set determine scale, rather than simply going bigger;
    4. Measure continuously: bring throughput, time-to-first-token, cache hit rate, and recall accuracy onto the same dashboard.

    6. Common Misconceptions

    • Judging capability by total parameters while ignoring activated parameters and data quality;
    • Judging long-text capability by the nominal window while ignoring mid-context recall;
    • Looking only at training cost while ignoring the long-term spend from inference-side cache and memory;
    • Equating architectural novelty with quality gains, without a reproducible evaluation baseline.

    7. Conclusion

    Understanding modern LLMs comes down to weighing four things on the same table: architecture modules, parameter scale, compute budget, and evaluation metrics. With the layered view and estimation method above, you can use general-purpose product capabilities as a foundation in a compliant cloud environment such as Baidu AI Cloud to carry out model selection, capacity planning, and launch evaluation soundly.