Long Context in LLMs: A Breakdown of Attention Compression Paradigms

    This article examines why paradigm-level architecture changes matter more than benchmark scores for open-source LLMs, and why long context has become core infrastructure for long-horizon agent workflows. It covers the quadratic complexity constraint of standard self-attention, three key paradigms—folding long sequences into million-token context, co-designing training and inference, and evaluating task completion rather than single-point accuracy—along with practical engineering guidance.

    1. Why Paradigm Shifts Matter More Than Benchmarks

    Over the past year or so, open-source LLM releases have accelerated noticeably. If you only look at public leaderboards, new models and the previous flagship generation trade wins, often by just a few percentage points—hardly enough to tell whether real progress has been made. A more reliable approach is to check whether a paradigm-level change has appeared at the architecture level: does it change where the ceiling of model capability comes from, and does it change the cost structure of training and inference?

    A typical signal is that the industry’s focus is shifting from “getting a single question right” to “finishing a long-horizon task.” Agent workflows, cross-document analysis, and repository-level code changes all require a model to maintain a very long context within a single session and to repeatedly retrieve, compare, and revise within it. In these cases, the marginal return on leaderboard scores declines, while context efficiency becomes the decisive variable.

    2. Why Long Context Is Becoming Infrastructure

    2.1 Complexity Is a Hard Constraint

    Standard self-attention has quadratic complexity with respect to sequence length: double the sequence, and attention computation and memory usage roughly quadruple. When the inference stage needs to generate a very long chain of thought, or load a large amount of material at once, costs can spiral out of control quickly.

    Schematically, the resource usage of a naive implementation is approximately:

    1. # Illustrates the complexity relationship only; not a concrete implementation
    2. cost = n_heads * seq_len * seq_len * head_dim
    3. # Increasing seq_len from 32K to 128K increases cost by roughly 16x

    2.2 The Economics of Long-Horizon Tasks

    If the cost per task is too high to scale, even strong capability lacks commercial value. Long context is therefore not a feature item but a prerequisite for making test-time scaling and long-horizon agents actually viable.

    3. Paradigm One: Folding to a Million-Token Context

    3.1 From “Thinner” to “Shorter”

    A common compression approach in the industry is to reduce the channel dimension or prune token importance—essentially making the representation thinner. Another path is to restructure how attention is organized: merge a large number of tokens into fewer representation units so that the sequence is “folded” shorter before participating in global interaction, compressing the quadratic term into a manageable range. Such approaches typically combine compressed block representations with sparse or hierarchical attention.

    3.2 How Hierarchical and Sparse Attention Work Together

    • Local layers handle fine-grained neighboring information, preserving nearby details;
    • Global layers perform interaction only on the compressed representations, carrying long-distance dependencies;
    • Sparse routing lets each query attend to only a few highly relevant blocks, avoiding a full scan.

    3.3 Engineering Considerations

    • The compressed block size must match the task granularity: too small yields limited gains, too large loses detail;
    • Position encoding must adapt to the hierarchical structure after folding to avoid distorted long-range position extrapolation;
    • Training and inference must use the same attention semantics, otherwise long-context capability cannot transfer.

    4. Paradigm Two: Co-Designing Training and Inference

    Long-context capability is not an inference-time switch; it must be injected during both pre-training and post-training. This means including enough long samples in the corpus, adding long-horizon tasks such as retrieval, comparison, and revision during post-training, and using online post-training to let the model self-correct on real long trajectories. Combined with cache reuse, chunked prefill, and streaming decoding, this can significantly reduce repeated computation.

    5. Paradigm Three: Evaluating Capability by Task Completion

    Evaluation should shift from “single-point accuracy” to “long-horizon completion rate”: given very long material, assess cross-section citation accuracy, resolution of conflicting information, success rate of multi-step tool calls, and the growth curve of cost with length. It is also advisable to record time to first token, cost per task, and context utilization to form a comparable engineering baseline.

    6. Implementation Guidance

    On cloud platforms such as Baidu AI Cloud, long-text and vector retrieval capabilities can be combined with object storage, container platforms, log services, and monitoring and alerting into a complete pipeline: raw material goes into object storage, the retrieval layer performs coarse filtering, the model performs inference within the folded long context, and metrics from the entire process feed into the logging and monitoring system. This makes it easier to locate performance bottlenecks in long-context scenarios and to keep tuning.