Trillion-Parameter LLMs: Breaking Down Hybrid Attention and MoE Architectures

    This article breaks down why trillion-parameter models require sparsification, how hybrid attention reduces KV cache growth, and the trade-offs among four MoE routing strategies. It also covers key dimensions for model selection and deployment, including activation size, total parameters, cache strategy, and routing balance.

    1. Why Trillion-Parameter Models Must Be Sparse

    Growing the parameter count is not the hard part. The real bottlenecks are memory bandwidth pressure during training and inference, and the fact that the KV cache grows linearly with sequence length in long-context scenarios.

    The common industry approach is to replace dense feed-forward layers with a Mixture of Experts (MoE) structure, so each token activates only a tiny fraction of the parameters. Attention is also redesigned so that cache usage no longer scales in direct proportion to context length.

    Here is a simple way to estimate capacity:

    1. # Illustrative: order-of-magnitude estimate of KV cache size (not any specific product)
    2. def kv_cache_bytes(layers, kv_heads, head_dim, seq_len, dtype_bytes=2):
    3. # One copy each for K and V
    4. return 2 * layers * kv_heads * head_dim * seq_len * dtype_bytes
    5. # A 10x longer sequence means a 10x larger cache — the cost of linear growth
    6. print(kv_cache_bytes(60, 8, 128, 1_000_000) / 1e9, "GB")

    The conclusion is straightforward: as long as the cache scales linearly with sequence length, million-token contexts will require tens of gigabytes of memory, making single-machine deployment nearly impossible.

    2. Hybrid Attention: Turning Linear Growth into Controllable Growth

    The core idea of hybrid attention is layered division of labor, not simply cutting attention away.

    The first layer is Compressed Shared Attention (CSA). It handles global responsibilities in the shallow layers, aggregating long sequences into fixed-length summary representations. Multiple heads share the same compressed key-values, decoupling cache size from sequence length. It shares the same origin as the global-token idea in early sparse attention, but adds two engineering advances: the compression ratio can be adjusted dynamically based on input complexity; and hierarchical objectives are introduced during pretraining to explicitly constrain the model to learn what information can be compressed and what must be preserved precisely.

    The second layer is Hierarchical Context Attention (HCA). It performs fine-grained local retrieval in the deeper layers, computing full attention only on the selected relevant segments, so detail recall is not swallowed by compression loss.

    The engineering benefit is a substantial reduction in cache usage (public industry practice typically reports around 90%), making million-token contexts runnable in a multi-GPU single-machine environment. Three points matter in practice: the compression module must participate in end-to-end training rather than being bolted on as post-processing; the boundary between the local window and the compressed summary must match the task type (long-document QA leans global, code repository understanding leans local); and on the inference side, paged cache management and prefix reuse are needed to turn theoretical gains into real throughput.

    3. Trade-Offs Among Four MoE Routing Strategies

    The first type is the “routed experts + shared expert” structure. The shared expert is always active and carries general knowledge, while a small number of routed experts are selected dynamically per token with Top-2 activation. The advantage is stable training and more balanced expert load; the drawback is slower total capacity expansion.

    The second type is pure MoE with full-size matrices. A single training framework produces multiple tiers ranging from two billion to hundreds of billions of parameters, all using Top-2 gating, with a permissive license and a complete ecosystem, making it easy to choose a tier based on hardware.

    The third type has higher sparsity and larger total capacity, and introduces domain-aware bias into routing so that some experts focus on code semantics. This design usually performs better on code generation and repository-level bug-fixing benchmarks, at the cost of requiring extra regularization for routing balance.

    The fourth type follows an extremely low activation ratio: nearly three hundred billion total parameters with only about twenty billion activated, roughly a 7% activation ratio. It has the lowest inference cost but the highest demands on routing accuracy and expert specialization; once routing is off, the capacity advantage cannot be realized.

    Illustrative routing implementation:

    1. # Illustrative: Top-k gating + load-balancing auxiliary loss
    2. gates = softmax(router(x)) # [tokens, num_experts]
    3. topk_val, topk_idx = topk(gates, k=2)
    4. y = sum(expert_i(x) * g for i, g in zip(topk_idx, topk_val))
    5. load = gates.mean(dim=0) # Average gating weight per expert
    6. aux_loss = num_experts * (load * load).sum()

    4. Selection and Deployment Recommendations

    When evaluating sparse models, fix four dimensions: activated parameters determine compute per request, total parameters determine memory and parallelism strategy, cache strategy determines long-context feasibility, and routing balance determines training stability. On the deployment side, container platforms can handle elastic scaling, object storage can hold model weights, and logging and monitoring with alerts can track time to first token, throughput, and cache hit rate. If an enterprise wants to validate quickly, the general compute and model services offered by Baidu AI Cloud can serve as a stress-testing and canary environment, running regression on real business data before deciding on a specification tier.