Skip to main content
Back

Cyber Monday Deal: Get 20% off all AlphaSignal Pro subscriptions. Ends soon.

Baidu's ProxyAttn Cuts Long-Context AI Processing 10x Without Retraining

A training-free sparse attention method uses a handful of representative attention heads as proxies, delivering 10.3x attention speedup on long contexts.

Pro

  • ProxyAttn is a training-free sparse attention method using representative heads as proxies for block importance scoring.
  • Delivers up to 10.3x attention speedup and 2.4x prefill speedup at 128K context with minimal accuracy loss.
  • Based on finding that attention heads agree on token focus but differ in sparsity on long inputs.
  • Beats MInference, FlexPrefill, XAttention, and SeerAttention on RULER with Llama 3.1 and Qwen2.5.
  • Scales to Llama 3.1-70B with 64 heads, achieving 2.08x end-to-end prefill speedup at 128K.
  • Code and HuggingFace integration available at github.com/wyxstriker/ProxyAttn.

Self-attention becomes expensive as prompts grow because each token can interact with every other token. Its compute and memory costs scale quadratically with sequence length, so doubling the context can roughly quadruple the work. Sparse attention reduces that cost by dividing the attention map into blocks and computing only the blocks likely to contain useful token relationships.

ProxyAttn, a training-free method from researchers at Harbin Institute of Technology and Baidu, selects those blocks using exact token-level scores from one or more representative attention heads. The selected rankings are shared with other heads, which avoids estimating importance from heavily compressed token summaries. The paper reports speedups of up to 10.3× for the attention kernel and 2.4× for prompt prefill, with little accuracy loss in its evaluations. The implementation is available on GitHub.

Block selection is the expensive guess

Sparse systems such as MInference, FlexPrefill, XAttention, and SeerAttention split attention maps into blocks, estimate each block’s importance, and compute the highest-ranked candidates. Accurate selection matters because skipped blocks cannot contribute to the output, while retaining too many blocks erodes the performance benefit.

Many selectors pool queries and keys along the sequence dimension before scoring them. Pooling is cheap, but it can average away a small number of high-scoring token pairs. The error becomes more damaging at aggressive sparsity levels, when the selector has little room to retain missed blocks. Computing every token-level dot product would provide better rankings while recreating the quadratic workload.

Heads often agree on token rankings

Experiments on Llama 3.1-8B with 8,000-token inputs from RULER identified two properties that make a head-based proxy practical:

  • Token rankings overlap across heads. The top 1,024 tokens selected by one head frequently appear among the high-ranked tokens of other heads in the same layer.
  • Heads require different budgets. Some heads concentrate probability on a small set of tokens, while others distribute it across a wider region.
Heatmap showing overlap in token importance across attention heads
ProxyAttn’s diagnostic shows substantial agreement in token importance across heads within a layer.

Cross-head agreement allows one representative map to rank blocks for several heads. Separate per-head budgets preserve differences in concentration, letting narrow heads compute fewer blocks and broad heads retain more.

One proxy map, separate head budgets

ProxyAttn partitions attention heads into groups, aligning them with key-value groups when the model uses Grouped-Query Attention, or GQA. Within each group, it averages the queries and keys across heads to create a proxy head. That proxy performs a token-level softmax dot product, and max pooling converts the resulting map into block scores shared by the group.

A stride of four lowers the proxy calculation’s cost by sampling one token from each four-token window. The selector still evaluates token-level relationships, but over fewer positions than a complete attention map.

Each original head receives an independent block budget derived from queries in the final block. The algorithm estimates how many blocks are needed to cover a target share of the head’s cumulative attention probability, represented by γ. The experiments use values of 0.90 and 0.95. A higher value retains more blocks and generally trades additional computation for a more conservative approximation.

  1. Group related attention heads.
  2. Build one or more proxy heads by averaging queries and keys across each group.
  3. Compute strided token-level attention for the proxies.
  4. Max-pool the proxy maps into shared block rankings.
  5. Estimate a separate block budget for every original head.
  6. Run sparse attention on each head’s highest-ranked blocks.

For a 7-billion-parameter model under the paper’s typical settings, the authors estimate that proxy scoring costs about 1% of full attention.

Speedups arrive at long context

On the RULER benchmark, a suite of long-context retrieval and reasoning tasks, ProxyAttn with γ set to 0.95 reached a weighted average score of 87.43 on Llama 3.1-8B-Instruct. Full attention scored 86.49, while ProxyAttn skipped 69% of attention blocks. The sparse result also exceeded the reported scores for MInference, FlexPrefill, XAttention, and the trained SeerAttention baseline at comparable sparsity.

Evaluation Reported result
Llama 3.1-8B-Instruct on RULER 87.43 weighted score at 69% sparsity
Full-attention RULER baseline 86.49 weighted score
Llama 3.1-70B at 128K context 2.08× end-to-end prefill speedup
Peak reported prefill result at 128K 2.4× speedup
Attention kernel at 256K About 10× faster than FlashAttention

Results on Qwen2.5-7B-Instruct-1M followed the same pattern. The 70-billion-parameter evaluation used a 128,000-token context and preserved higher accuracy than the reported MInference and XAttention configurations.

Chart comparing ProxyAttn and FlashAttention kernel speed across input lengths
Kernel-level gains increase with sequence length as the avoided attention work outweighs proxy selection overhead.

Kernel speedups appeared only beyond 32,000 tokens in the tested setup. End-to-end gains were smaller because feed-forward layers and other model operations still consume part of prefill time. Prefill processes the prompt before generation begins, so reducing it lowers time to first token for long-input workloads.

The useful deployment range

ProxyAttn accelerates prefill while continuing to use full attention during decoding. Its strongest use cases therefore involve large prompts and comparatively short outputs, including document question answering, repository-scale code analysis, retrieval over large inputs, and book-length summarization.

Developers can apply the method to supported Llama and Qwen checkpoints without fine-tuning. The repository exposes a proxy_attention operation and a helper that patches a Hugging Face model in place:

load_llama(model, "proxyattn", gamma=0.95)

Operational limits

  • Short contexts: Below roughly 32K tokens in the reported tests, proxy construction and block selection erased the benefit over a tuned FlashAttention kernel. The crossover point will depend on model shape, hardware, and kernel implementation.
  • Wide GQA groups: Qwen2.5 uses seven query heads per key-value head and needed about four proxy heads per group to recover full accuracy. Additional proxies reduce the available compute savings.
  • Long generation: Decoding still uses full attention, so workloads dominated by output generation receive less benefit.
  • Task coverage: The reported quality results cover specific models and long-context benchmarks. Production deployments should measure accuracy, latency, and memory use on their own prompts and hardware.