LLM Architecture Evolution: A Technical Breakdown of Attention, MoE, and Positional Encoding

    This article breaks down the core structure shared by modern large language models and examines where real architectural differences emerge. It walks through four high-leverage axes—attention mechanisms, positional encoding, feed-forward layers, and numerical precision—then provides a six-point checklist for evaluating a new architecture and three practical recommendations for enterprise deployment, with cost per token rather than novelty as the primary selection criterion.

    ## 1. Setting Up a Coordinate System for the Architecture

    Before discussing any fine-grained module, it helps to reduce the model to a single panoramic view. Whether it is an early autoregressive language model with only billions of parameters or today’s sparse models at the tens-of-billions to trillions scale, the backbone can be abstracted into the same skeleton:

    1. input tokens
    2. → token embedding layer (optionally tied to output weights)
    3. → N × Transformer Block
    4. ├─ normalization (pre or post)
    5. ├─ self-attention sub-layer (with positional information injected)
    6. └─ feed-forward sub-layer (dense or sparsely routed)
    7. → final normalization
    8. → linear projection to vocabulary → probability distribution → sampling

    On first contact, many people find nothing novel in this structure compared with models from the past year or two: still decoder-only, still residual connections plus normalization, still next-token prediction as the training objective. This sense of familiarity is precisely a signal that the architecture has matured—the backbone is stable, and the real differences have been compressed into a few high-leverage modules. So the value of a new architecture generation should not be judged by whether it overturns the backbone, but by what trade-offs it makes along four axes: attention, the feed-forward layer, positional encoding, and numerical precision.

    2. Attention: From “Everyone Talks to Everyone” to “Grouped Conversations”

    The computational complexity of self-attention grows quadratically with sequence length, and the key-value cache (KV Cache) is often the main consumer of GPU memory during long-context inference. The evolution can be summarized in three steps:

    1. Multi-head attention: each head independently models a different semantic subspace; expressive but large in cache size.
    2. Grouped-query attention: multiple query heads share one group of key-value heads, and cache size drops roughly in proportion to the sharing ratio—the key engineering compromise for serving long context.
    3. More aggressive sharing: further reducing the number of key-value heads, trading memory for throughput.

    Illustrative comparison (structure only, not a specific implementation):

    1. # Whether each query head owns its own KV group determines cache size
    2. num_kv_groups = num_heads // num_kv_heads
    3. # num_kv_heads == num_heads → traditional multi-head
    4. # num_kv_heads == 1 → multi-query style sharing
    5. # 1 < num_kv_heads < num_heads → grouped sharing (common engineering range)

    It is worth stressing that such changes barely alter the upper bound of the model’s conditional distribution expressiveness, yet they significantly change how many concurrent requests a given amount of memory can carry. For teams building inference services, this often matters more to actual cost than parameter count does.

    3. Positional Encoding: Extrapolation Ability Matters More Than Fitting Ability

    The gap between the training context length and the length the business actually needs is the most common pain point at deployment time. Positional information injection has evolved from early learnable embeddings, to sinusoidal encoding, to the currently mainstream rotary positional encoding. The core advantage of the latter is that it folds relative position into the inner product of queries and keys in the form of a rotation phase, making the model naturally sensitive to relative distance and allowing a degree of length extrapolation by adjusting the rotary base frequency.

    In engineering practice it is usually combined with two strategies: first, adopt a longer window during training to avoid the distribution drift caused by ad-hoc extrapolation at inference time; second, perform context chunking and summary compression at the inference serving layer, turning an “infinitely long document” into several controllable windows. Combining the two is more stable than relying on positional encoding extrapolation alone.

    4. The Feed-Forward Layer: The Critical Leap from Dense to Sparse

    If attention determines how information flows, the feed-forward layer determines how knowledge is stored and retrieved. Early models generally used dense feed-forward layers, where all parameters participate in computation for every token; contemporary large models have largely moved to sparse mixture-of-experts structures, whose key points include:

    • A routing network selects a few experts for each token, so activated parameters are far fewer than total parameters;
    • Load-balancing loss and a capacity factor are used to suppress expert collapse and token overflow;
    • Shared experts carry general capabilities while routed experts carry differentiated knowledge;
    • Communication overhead becomes the new bottleneck and must be designed together with the parallelism strategy.

    The essence of this shift is decoupling “model capacity” from “compute per pass.” Total parameters determine the knowledge ceiling, activated parameters determine inference cost, and the two are no longer forcibly bound. The price is lower training stability and higher distributed communication complexity, so the routing strategy, expert granularity, and parallel partitioning must be tuned jointly rather than optimized independently.

    5. Numerical Precision and Training Stability

    The introduction of low-precision numeric formats (such as 8-bit floating point) makes it possible to train at larger scale on the same hardware; but attention scores, normalization statistics, and routing scores are more sensitive to precision and usually need higher-precision accumulation. Stable practices include: low precision for the backbone, high-precision accumulation for sensitive operators, clipping of routing logits, and more conservative learning rates with warmup early in training. Such details do not show up on the architecture diagram, yet they directly determine whether a large-scale training run converges.

    6. How to Evaluate a New Architecture

    Here is an actionable checklist that avoids being misled by the single metric of “parameter scale”:

    1. Structure: whether the backbone is decoder-only, the normalization position, the ratio of attention heads to key-value heads;
    2. Capacity: the ratio of total to activated parameters, the number of experts and routing granularity;
    3. Context: training window length, positional encoding scheme, extrapolation validation method;
    4. Numerics: precision strategy for training and inference, protection schemes for sensitive operators;
    5. Serving: memory footprint, concurrency, batching and cache reuse efficiency;
    6. Evaluation: whether long-text, multi-turn dialogue, and structured output have been validated on the business’s own data.

    7. Three Recommendations for Enterprise Deployment

    First, do not make architectural novelty the primary selection criterion; make the combined cost per token (compute plus memory plus operations) the core metric. Second, if the business centers on long documents and knowledge-base question answering, prioritize the engineering maturity of KV cache optimization and context extrapolation; if the business centers on high-concurrency short requests, a dense small model paired with elastic scaling on a container platform is often more economical. Third, wire logging services and monitoring alerts into the inference path, and establish baselines for first-token latency, throughput, and memory watermark, so you can tell whether an architecture upgrade actually pays off. In the general capability组合 offered by cloud platforms such as Baidu AI Cloud, object storage, container platforms, logging services, and monitoring alerts can be assembled into a complete training and inference engineering loop, while the choice of model architecture itself should still be verified item by item against the six-point checklist above.