Asymmetric Activation Architecture for LLM Inference: How It Speeds Up Long-Context Agents
As the shift toward agentic workloads changes how large language models consume compute, symmetric activation in Mixture-of-Experts (MoE) models is no longer the most efficient choice. This article breaks down asymmetric activation and the causal encoder-decoder structure behind it: how the lower layers compress long contexts during prefill, how the upper layers drive token-by-token decoding with a globally projected KV cache, and how shared key-values plus two-level sparse indexing keep attention manageable. It also covers externalized memory via hash lookup, a reusable evaluation framework for first-token latency, generation speed, token consumption, cache hit rate, and cost per task, and practical guidance on which scenarios are worth migrating.
1. Where the Problem Starts: Compute Imbalance from Long-Context Agents
Once agentic applications became a mainstream workload, the compute profile of LLM inference shifted noticeably. In traditional chat, input and output lengths are roughly comparable. In “read a lot, write a little” agent tasks, a single request may ingest hundreds of thousands of tokens of codebases, logs, documents, and tool results, yet produce only a few hundred to a few thousand tokens. This extreme asymmetry makes the prefill phase the main source of latency and cost, while the decode phase determines the token streaming speed users actually perceive.
Most conventional Mixture-of-Experts (MoE) models use symmetric activation: whether in prefill or decode, every token goes through the same routing and activation logic, with identical activated parameter counts for input and output. That is fine under balanced loads, but with long inputs and short outputs it means paying the same price for two phases with fundamentally different characteristics, leaving clear room for optimization.
2. The Core Idea: Let Each Phase Take Its Own Path
The answer from newer model architectures is to split the network vertically into two segments, forming a causal encoder-decoder structure. The pseudocode below illustrates the difference from a conventional symmetric MoE:
# Symmetric activation: both phases share the same forward logicdef forward_symmetric(tokens, phase):return backbone(tokens) # phase does not affect activation size# Asymmetric activation: prefill and decode run different-sized subnetworksdef forward_asymmetric(tokens, phase):if phase == "prefill":# The lower half acts as the encoder, compressing long contextcontext = encoder_bottom(tokens) # smaller activation sizereturn contextelse:# The upper half acts as the decoder, generating token by tokenkv = project_from(context) # global KV projected from the encoder's last layerreturn decoder_top(token, kv) # larger activation size
Three design choices matter here:
- The lower layers serve as the encoder, active only during prefill, compressing verbose context into a compact representation.
- The upper layers serve as the decoder, running as the main network during generation. The global key-value cache is no longer built by each layer from its own hidden states; it is projected uniformly from the hidden states of the encoder’s final layer.
- The two phases activate different parameter counts, producing an asymmetric shape of “small activation for input, large activation for output.”
The third point is key to understanding the cost tradeoff. Because every generated token requires a full pass through the upper layers, their activation size sets the floor for streaming speed. Prefill, by contrast, can be processed in parallel, so a smaller activation size there translates directly into lower first-token latency and lower total time. For agentic workloads, this tradeoff hits the pain point precisely.
3. Why Context Can Become Compact: Shared Key-Values and Two-Level Sparse Indexing
The compact context is not the result of a simple compression algorithm but a structural outcome. When decoder layers no longer each maintain their own global key-value cache, the layer-level redundancy in caching is removed, reducing both memory footprint and memory bandwidth pressure. Combined with shared key-values and a two-level sparse indexing scheme for attention, the model can retain long-context capability while keeping the number of tokens that actually participate in attention computation within a manageable range.
The division of labor between the two index levels can be understood this way:
- Level one: coarse-grained filtering that quickly locates context blocks relevant to the current query, at very low cost.
- Level two: fine-grained retrieval within candidate blocks, keeping only a small number of highly relevant tokens for exact attention.
This “coarse first, fine second” strategy is structurally analogous to “recall then rerank” in retrieval-augmented generation (RAG), except that it happens inside the model rather than in an external orchestration layer.
4. Externalized Memory: Separating What to Remember from What to Compute
Another direction worth attention is externalizing the memory mechanism. The underlying judgment is that model capability splits into two categories. One covers problems requiring reasoning, composition, and generalization, handled by the backbone network. The other covers large amounts of memorized content, such as local fixed collocations, entity names, and high-frequency fragments; this content has low compute value but consumes a huge number of parameters, making it suitable for external storage via hash lookup.
The benefit is that the parameter budget is reallocated: the backbone no longer pays for memory capacity and can concentrate capacity on reasoning. Note that such mechanisms place high demands on implementation. Hash table consistency, hit rate, and update strategy all directly affect results, so deployment should be validated with a thorough evaluation set rather than judged on architectural novelty alone.
5. Where the Performance Gains Come From: A Reusable Evaluation Framework
With a new architecture, developers need a reusable evaluation method rather than a single metric. It helps to establish baselines across these dimensions:
| Evaluation dimension | Focus | Common pitfall |
|---|---|---|
| First-token latency | Prefill efficiency, sensitivity to context length | Testing only short inputs |
| Generation speed | Decode-phase activation size, memory bandwidth | Ignoring concurrency effects |
| Total token consumption | Whether there are redundant repeated reads | Looking only at total elapsed time |
| Cache hit rate | Whether prefix reuse is effective | Inflated hit rate with no real benefit |
| Cost per task | Combined time and consumption | Looking only at unit price |
Cache hit rate is especially easy to misread. A high hit rate driven by many repetitive, low-value requests yields limited real gains and should be assessed alongside task success rate and output quality. In addition, when a model is co-trained closely with AI coding tools and agent runtime frameworks, the same model can perform noticeably differently under different configurations. Evaluations must fix the configuration and record versions, otherwise the numbers are not comparable.
6. Adoption Guidance: Which Scenarios Are Worth Migrating
Overall, the gains from asymmetric activation concentrate in long-input, short-output, high-concurrency scenarios such as codebase Q&A, log analysis, document extraction, and multi-turn tool calling. Conversely, if the business is mostly short prompts and long-form generation, the gains shrink, so a small-percentage canary test on real traffic is advisable before migrating.
Three practical points during migration: first, keep prompts and tool-calling protocols stable, and avoid mixing an architecture upgrade with business changes; second, lock down the evaluation set to form a baseline that can be regression-tested continuously; third, pay attention to observability, using logging services and monitoring alerts to attribute latency, consumption, and failure rates at each layer. Cloud platforms generally already provide common capabilities such as container platforms, object storage, message queues, logging services, and monitoring alerts, which can serve as the infrastructure foundation for this kind of inference workload; Baidu AI Cloud can provide corresponding support in these common capabilities.
7. Conclusion
Asymmetric activation, the causal encoder-decoder, shared key-values, and externalized memory are different facets of the same idea: separate workloads of different natures and handle each with the most economical structure. For developers, the value of understanding this logic lies not in chasing a specific model version but in building a framework for judging new architectures: first check whether the workload profile matches, then check whether the evaluation is reproducible, and only then look at benchmark scores.
