Long-Context Inference Cost Reduction: Asymmetric Compute, KV Cache Compression, and Measurement Caveats
Long-context agent and deep-research workloads repeatedly read tool outputs, terminal logs, and code repositories, so prefill computation and KV cache memory grow with input length. This article separates prefill cost into linear and attention terms, explains why halving activated parameters in asymmetric compute does not halve total FLOPs, and reviews cross-layer KV reuse and FP4 quantization with their trade-offs and measurement caveats.
Why Long Context Becomes Expensive
Agent and deep-research tasks repeatedly read tool outputs, terminal logs, and code repositories. A single software engineering task may involve hundreds of tool calls and hundreds of thousands of output tokens, so input length keeps growing. Inference cost mainly comes from two places: computation over the full prompt during prefill, and the memory and bandwidth occupied by the KV cache.
Prefill computation can be split into two parts. The linear part is proportional to the number of input tokens N and the number of activated parameters per token P_act, approximately 2 × N × P_act floating-point operations. The attention part scales with N² and does not decrease just because MoE reduces activated parameters. The longer the input, the higher the share of attention computation. Many materials summarize prefill complexity as O(NL). That helps explain the linear part, but it is incomplete; estimates should consider the two parts separately.
The KV cache is a different problem. Every token must store Key and Value at every layer, so memory usage grows with context length. The context length that a single GPU can hold is directly determined by the number of KV bytes per token.
Public technical analyses provide several key figures: a backbone parameter scale of 552B, activated parameters per token during prefill reduced from 16B to 8B, and global KV cache reduced from about 3,514 bytes/token to 890 bytes/token. This article has not independently reproduced these numbers; the discussion below notes which measurement conditions are missing for each figure.
Asymmetric Compute: Reducing Prefill Work
According to public descriptions, most prompt tokens during prefill mainly pass through the first half of the network rather than through all layers. This reduces activated parameters per token from 16B to 8B.
Halving activated parameters does not mean halving total FLOPs. The linear part does approximately halve with activated parameters, but the N² attention term remains unchanged. Total FLOPs can be approximated as: total FLOPs ≈ 2 × N × P_act + attention computation. The benefit of halving depends on the linear part’s share of total computation. The longer the input, the higher the attention share, and the smaller the overall reduction. If the model also uses sparse attention or other optimizations, this estimate must be recalculated.
Asymmetric compute also has a boundary issue: public materials do not specify which tokens are exceptions, meaning which tokens must pass through all layers. If critical tokens such as the end of a user question or instruction only go through the first half of the network, output quality may degrade. In deployment, exception rules should be defined and quality changes should be measured with controlled experiments.
When measuring TTFT (time to first token), input length, batch size, concurrency, and cache state must be fixed, and prefill computation time must be recorded separately from queueing time; otherwise the two will be mixed together.
KV Cache: Cross-Layer Reuse and FP4 Quantization
This part involves two techniques.
The first is cross-layer reuse. Public materials mention reusing Main KV, Indexer K, and Top-K selection results to reduce duplicate KV storage and repeated index computation across layers. There are three common sharing approaches: group sharing, where every k layers share one KV; layer-mapping sharing, where specified layers read another layer’s cache; and sharing only index results. The mapping rules must match the model’s training design; otherwise the historical information read will be incorrect. The higher the sharing ratio, the greater the memory benefit and the greater the loss in expressiveness, so quality evaluation is needed to confirm the trade-off.
The second is FP4 quantization. BF16 uses 2 bytes per value, while FP4 uses 0.5 bytes, giving a theoretical compression ratio of 4×. However, FP4 requires accompanying scale parameters, usually stored per block. Quantization must also handle outliers; if outliers are handled improperly, errors can accumulate over long contexts.
The table below compares several approaches.
| Approach | KV composition | Precision | Memory benefit | Main risk | Applicable boundary |
|---|---|---|---|---|---|
| Traditional per-layer KV | K and V stored independently per layer | BF16/FP16 | Baseline | Memory and bandwidth grow linearly with context | Short context |
| Cross-layer sharing | K and V shared by group | BF16 | Increases with sharing ratio | Limited expressiveness, mapping errors | High attention similarity between adjacent layers |
| FP4 quantization | Stored independently per layer | FP4 plus scale | About 4× theoretical | Outlier errors, accuracy drop in long context | Representative calibration data |
