English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

FlashPrefill: Near-Zero-Cost Sparsity Discovery for Ultra-Fast Long-Context Prefilling

Forum topic · ✨步子哥 · 2026-03-13

Summary

FlashPrefill is a long-context prefilling acceleration method from WeChat and the Institute of Automation, Chinese Academy of Sciences (arXiv:2603.06199) that attacks the O(L^2) KV-cache bottleneck that inflates time-to-first-token (TTFT) in large language model inference. It addresses three pain points of prior sparse attention approaches: expensive pattern discovery, hard-to-parallelize Top-k/Top-p selection, and incomplete sparsity caused by long-tail score distributions. FlashPrefill combines three ideas: (1) instantaneous pattern discovery via block-level approximation, pooling keys/queries and reweighting globally, cutting data movement from L x L/B to (L/B)^2; (2) dynamic threshold pruning (Threshold = alpha x max(Score)) that discards the low-score long tail with only one max-reduction, while safeguarding attention sinks (first 256 blocks) and a local window (last 512); and (3) index compaction that turns logical skipping into physical jumps in the kernel. On Qwen3-30B at 256K context it achieves a 27.78x prefill operator speedup while retaining only 3.5% of blocks (vs. 8.4% for FlexPrefill and 18.5% for XAttention), with minimal accuracy loss: RULER 92.68 vs. 93.28 full attention, and InfiniteBench 24.93 vs. 23.87, plus near-lossless needle-in-a-haystack retrieval from 2K to 256K.

FlashPrefill: Instantaneous Pattern Discovery and Thresholding for Ultra-Fast Long-Context Prefilling

  • Authors: WeChat · Institute of Automation, Chinese Academy of Sciences
  • arXiv:2603.06199 | GitHub: qhfan/FlashPrefill
  • Core Idea

    FlashPrefill makes "finding important blocks" and "selection strategy" nearly zero-cost, uses dynamic thresholds to prune the attention long tail, and compacts indices to enable physical jumps — achieving a 27.78x operator speedup at 256K context.

    Motivation

  • Prefill must traverse the whole prompt to build the KV cache with \(O(L^2)\) complexity.
  • Long contexts cause explosive growth in time-to-first-token (TTFT) and a poor user experience.
  • Pain points of existing sparse-attention methods:

    1. High pattern-discovery latency — estimating block importance is itself compute-heavy. 2. Expensive selection strategies — Top-k sorting and Top-p accumulation are hard to parallelize. 3. Incomplete sparsity — under long-tail distributions,凑 enough K blocks / P probability introduces many useless blocks.

    Method

    1. Instantaneous Pattern Discovery

  • Block-level approximation with mean-proxy ranking, under a low-variance assumption (blocks are semantically similar internally).
  • Key/Query pooling plus global reweighting produces a global "attention map".
  • Data movement drops from \(L \times L/B\) to \((L/B)^2\).
  • 2. Dynamic Threshold Pruning

    Threshold = α × max(Score)

  • Extremely light: only one max-reduction needed.
  • Prunes the long tail entirely instead of padding to a fixed count.
  • Safety net: always keep Attention Sinks (first 256 blocks) and the Local Window (last 512).
  • 3. Index Compaction → Physical Jumps

  • Problem: logical skipping (if mask=0) still iterates all blocks with heavy branch overhead.
  • Solution: compact valid block indices into a contiguous list; the kernel's inner loop only visits valid indices. Logical skipping becomes physical jumping, with more concentrated memory access and far fewer loop iterations.
  • Results

  • Speed: 27.78x prefill operator speedup (Qwen3-30B @ 256K).
  • Sparsity at 256K (blocks retained): FlashPrefill 3.5% vs. FlexPrefill 8.4% vs. XAttention 18.5%.
  • Accuracy:
  • RULER (Qwen3-30B): 92.68 vs. 93.28 full attention (minor drop)
  • InfiniteBench (Qwen2.5-7B): 24.93 vs. 23.87 (slightly better)
  • Needle-in-a-Haystack: retrieval capability from 2K to 256K is nearly lossless.
  • End-to-end TTFT is significantly reduced when integrated into vLLM.

Summary

FlashPrefill achieves near-zero-cost sparsification for long-context prefilling through approximate computation, dynamic thresholds, and physical jumps, greatly improving inference efficiency.

Tags

#llm-inference#sparse-attention#long-context#prefilling#kv-cache#flashprefill#vllm#ttft-optimization

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/177168820