LLM Architecture Evolution: Sparse Experts and Efficient Attention Mechanisms

    This article explores the evolution of large language model (LLM) architectures, focusing on how structural changes address the trade-offs between training cost, inference latency, and VRAM usage. It analyzes efficient attention mechanisms for long contexts, deep layer stability via residual path optimizations, and Mixture of Experts (MoE) routing in latent space to reduce communication overhead. Readers will gain insights into the engineering trade-offs and implementation details of modern LLM architectures.

    Why Architectural Changes Matter

    In recent years, the advancement of Large Language Models (LLMs) has increasingly relied on structural design rather than merely scaling parameters and training data. Three critical factors—training cost, inference latency, and VRAM usage—are deeply intertwined. An architectural change typically impacts all three simultaneously, so they must be evaluated together.

    When selecting models, engineering teams often face three primary challenges: rapid VRAM exhaustion as context length increases, training instability in deeper models, and escalating inference costs as parameter counts grow. The following sections address these issues by examining common improvement strategies and their associated trade-offs.

    Attention Computation for Long Contexts

    Standard scaled dot-product attention scales quadratically with sequence length, denoted as O(n^2). Meanwhile, the Key-Value (KV) cache grows linearly. When the context reaches hundreds of thousands of tokens, the VRAM occupied by the KV cache often exceeds that of the model weights, becoming the primary bottleneck for long-text inference.

    To address this, the industry has explored several directions:

    • Sparse Attention: Computes attention only for specific pairs of positions, such as using sliding windows or block selection. The trade-off is the potential omission of long-range dependencies, which requires global tokens or retrieval mechanisms to compensate.
    • Linear Attention: Replaces the softmax function with a recurrent kernel form, reducing computational complexity to O(n). The state size during inference remains fixed, but performance on exact retrieval tasks is typically weaker than with standard attention.
    • Hybrid Structures: Uses full attention in some layers and linear or sparse attention in others, striking a balance between accuracy and efficiency.

    The core of linear attention is maintaining a fixed-size state matrix, which is updated for each new token. The following pseudocode illustrates a recurrent form with a decay factor, intended solely to explain the concept rather than represent a specific implementation:

    1. # Illustration: Recurrent state update in linear attention (pseudocode)
    2. state = zeros(d_k, d_v) # Fixed-size state, independent of sequence length
    3. for t in range(seq_len):
    4. k_t, v_t, q_t = keys[t], values[t], queries[t]
    5. decay = gate(x_t) # Forget gate with values between 0 and 1
    6. state = decay * state + outer(k_t, v_t)
    7. out[t] = q_t @ state

    This structure keeps inference state memory constant. However, because it compresses historical information into a limited capacity, the gating design and state dimension directly determine the model’s ability to retain long-range information. In practice, teams should measure retrieval accuracy on target tasks rather than relying solely on perplexity.

    Residual Paths and Deep Layer Stability

    Every layer in a Transformer uses residual connections, adding the input back to the output. As the number of layers increases, the magnitude of the residual stream may grow continuously, diluting information from earlier layers and making it difficult to control the scale of deep gradients.

    Common mitigation strategies include:

    1. Normalization Position: Pre-Norm structures are generally easier to train than Post-Norm, though the output variance in deep layers still tends to increase with depth.
    2. Residual Scaling: Multiplies the sublayer output by a depth-dependent coefficient to control the growth rate of the residual stream.
    3. Attention Residuals: Mixes attention output with previous layer representations in a learnable manner, rather than through simple addition. This makes inter-layer information flow more controllable but introduces a small amount of extra parameters and computation, requiring ablation studies to confirm the benefits.

    To determine if these changes are effective, three comparisons are recommended: whether the training loss curve is smoother, whether validation metrics improve under the same compute budget, and whether the norm distribution of deep-layer activations converges. If only the final metrics improve while the training curve fluctuates wildly, the gains might be due to randomness and should be verified using multiple random seeds.

    Mixture of Experts in Latent Space

    Mixture of Experts (MoE) architectures activate only a few experts per token, controlling per-token computation while maintaining a large total parameter count. The typical workflow involves three steps: router scoring, top-k expert selection, and weighted output merging.

    The overhead of this standard workflow comes primarily from two areas: the VRAM occupied by expert parameters, and the communication volume of token dispatch across devices in multi-GPU scenarios. Since communication volume is proportional to the hidden dimension, reducing the dimension of the vectors involved in routing and dispatching directly decreases communication overhead.

    The latent space MoE approach projects the hidden state into a lower-dimensional latent space, performs routing and expert computation there, and then projects it back to the original dimension. The cost is the additional parameters and potential information loss introduced by the projection layers, while the benefit depends on the choice of the latent dimension.

    1. # Illustration: Top-k routing in latent space (pseudocode)
    2. z = down_proj(h) # Compress hidden dim d to latent dim r, where r < d
    3. logits = router(z) # A score for each expert
    4. weights, idx = topk(softmax(logits), k)
    5. out_latent = sum(w * expert_i(z) for w, i in zip(weights, idx))
    6. out = up_proj(out_latent) # Project back to original dimension

    Load balancing is another challenge in MoE. If the router consistently selects a few experts, some experts barely train, while others experience capacity overflow. Common solutions include auxiliary balancing loss, expert capacity limits, and routing noise. During design, the token ratio received by each expert should be monitored and treated as a training health metric.