New LLM Architectures Explained: Attention Optimization and Sparse Expert Routing
This article examines recent architectural improvements in large language models, focusing on three directions: reducing the computational complexity of attention, improving information flow in deep networks, and replacing dense computation with sparse computation. It covers linear attention, gated recurrence, hybrid architectures, learnable cross-layer aggregation, and latent-space routing for mixture-of-experts models, with pseudocode illustrating the core ideas and engineering trade-offs of each approach.
1. Why Revisit LLM Architectures
The capabilities of large language models have long been driven by parameter count and training data volume, but inference cost and memory footprint have grown just as quickly. Once context lengths reach hundreds of thousands of tokens or more, the cost of attention computation and the size of the key-value cache (KV cache) become the dominant bottlenecks. Recent architectural improvements cluster around three directions: reducing the computational complexity of attention, improving information flow in deep networks, and replacing dense computation with sparse computation.
To understand these directions, it helps to separate two classes of problems. The first is expressiveness during training—for example, whether a model can learn long-range dependencies. The second is engineering efficiency during inference—for example, how many requests can be served per unit of time, or how long a context a single accelerator can hold. An architectural proposal may only improve one of the two, so evaluations must treat them separately.
2. Attention Efficiency and the Linearization Approach
Standard scaled dot-product attention computes an n×n correlation matrix for a sequence of length n, giving O(n²) time complexity, while the cached key-value pairs grow linearly with sequence length. Common improvement paths fall into three categories:
- Linear attention: uses kernel functions to approximate the effect of softmax, reducing complexity to O(n). The trade-off is degraded exact retrieval capability, which is especially noticeable on tasks that require precisely locating information.
- Gated recurrence and state compression: compresses history into a fixed-size state vector, which suits streaming over very long inputs. Because state capacity is limited, the forgetting strategy is a central design concern.
- Hybrid architectures: most layers use linear or sparse attention, while a small number of layers retain full attention. This balances long-sequence efficiency with precise recall of critical information and is currently a common compromise.
The following pseudocode illustrates the core idea of linear attention. It omits the causal mask and is only meant to show the order of computation:
function linear_attention(Q, K, V):Q' = feature_map(Q) # e.g., elu(x) + 1, ensuring non-negative outputsK' = feature_map(K)S = Σ_j outer(K'_j, V_j) # aggregate a global state first; cost is linear in sequence lengthz = Σ_j K'_j # normalization termfor each position i:out_i = (Q'_i · S) / (Q'_i · z)return out
The key point is the order of operations. K and V are first aggregated into a fixed-size state, and each query vector then multiplies against that state, so the explicit n×n matrix is never materialized.
3. Residual Connections and Cross-Layer Information Aggregation in Deep Networks
A standard residual connection adds each layer’s output directly to the backbone representation. As depth increases, information from early layers is gradually diluted in the backbone, and the contribution weight of each layer cannot be adjusted independently.
One improvement replaces “fixed-weight addition” with “learnable weighted aggregation.” Layer l no longer reads only the output of layer l-1; instead, it selects the information it needs from the outputs of all preceding layers based on relevance. This lets deep layers access shallow features directly, reducing information decay.
function aggregate_history(layer_outputs, query_vector):# layer_outputs: list of outputs from previous layers, each of shape [hidden]scores = [dot(query_vector, h) for h in layer_outputs]weights = softmax(scores)return Σ_i weights[i] * layer_outputs[i]
This kind of aggregation adds memory traffic and extra computation. Two points need engineering evaluation: first, the storage cost of the history cache grows with the number of layers; second, whether the aggregation weights remain stable—during early training it is easy for some layers to be attended to excessively.
4. Sparse Expert Models and Latent-Space Routing
In mixture-of-experts (MoE) models, each token activates only a small number of experts, so total parameter count can be very large while per-token inference compute stays manageable. A typical router consists of a linear layer followed by top-k selection, assigning each token to the k experts with the highest scores.
As the number of experts grows, the cost of routing computation and cross-device communication rises accordingly. One improvement is to first project token representations into a low-dimensional latent space, make routing decisions—and even part of the expert computation—in that space, and then map the results back to the original dimension. This reduces routing parameters and communication volume, but the projection introduces information loss that must be controlled through training.
class LatentRouter:down_proj: hidden_dim -> latent_dimgate: latent_dim -> num_expertsfunction forward(x):z = down_proj(x)p = softmax(gate(z))weights, experts = top_k(p, k)return weights, experts
When evaluating this type of design, three metrics deserve attention simultaneously: whether expert load is balanced, whether routing decisions are stable, and whether inter-expert communication is
