每天早上一封邮件,把昨天的 AI 梳理好订阅邮件

METAL LAB

FlashPrefill V2: Block-Sparse Prefill Attention for Long-Context LLM Serving

arXiv:2608.197582026-08-21

把稀疏注意力从论文原型变成能真正上线服务的加速方案

FlashPrefill V2针对长文本大模型处理提示词的耗时阶段,通过跳过不重要的计算块来提速,同时加入一种低成本的补偿机制防止精度大幅下滑。它按照最新Hopper GPU优化技术和FP8低精度运算重写了计算核心,并可直接接入SGLang的分页显存管理与批处理系统。在H20 GPU上,128K上下文长度下相比FlashAttention-2最高提速47.26倍,精度损失很小。

他们做了什么

  1. 问题所在:注意力计算量随上下文长度呈平方级增长,其中在模型开始生成第一个词之前需要先处理整段输入提示词的预填充阶段计算量最大。此前的FlashPrefill通过跳过不重要的计算块来提速,但稀疏程度越高精度损失越难控制,而且不适配实际的推理服务框架。
  2. 改进一(精度):不再直接丢弃被跳过的块,而是引入均值补偿,把每个被跳过块的键值统计信息压缩成一个平均值重新加回到softmax计算中,几乎不增加额外计算就能找回大部分被丢弃的概率质量。
  3. 改进二(速度):借鉴FlashAttention-3/4的技术(PackGQA显存访问方式、warp专职化、乒乓流水线),针对Hopper架构GPU重新设计了计算核心,并支持FP8这种8比特低精度推理以进一步提速。
  4. 改进三(可部署性):原生支持分页KV缓存(vLLM推广的按固定大小分页管理显存的方式)和连续批处理(混合处理多个请求),因此无需改动模型即可作为注意力后端直接接入SGLang等现代推理框架。
  5. 结果:在NVIDIA H20 GPU上,128K上下文长度下FP8精度相比FlashAttention-2最高提速47.26倍,BF16精度提速27.19倍,相比对齐FlashAttention-3/4的稠密基线也提速30.49倍;在真实SGLang服务中首个词输出时间最高缩短4.8倍,同时在RULER和LongBench评测中相比完整注意力的精度损失约为1到2分。
Figure 1: FlashPrefill V2 evolves FlashPrefill [8] from an algorithmic prototype toward practical long-context serving along three dimensions: (1) a mean correction term that preserves model accuracy under extreme sparsity; (2) an FA3/4-aligned sparse attention kernel with PackGQA memory access, warp specialization, pingpong pipelining, and FP8 support; and (3) native compatibility with paged KV cache and continuous batching for integration as an attention backend in modern serving frameworks such as SGLang [42].
Figure 1: FlashPrefill V2 evolves FlashPrefill [8] from an algorithmic prototype toward practical long-context serving along three dimensions: (1) a mean correction term that preserves model accuracy under extreme sparsity; (2) an FA3/4-aligned sparse attention kernel with PackGQA memory access, warp specialization, pingpong pipelining, and FP8 support; and (3) native compatibility with paged KV cache and continuous batching for integration as an attention backend in modern serving frameworks such as SGLang [42].
Table 1: RULER scores (left) and attention operator speedups over FlashAttention-2 (right) at sequence lengths from 4K to 128K. The speedups are measured end-to-end on needle-in-a-haystack inputs, including pattern discovery, thresholding, and mean correction. Results marked with ∗ (in gray) are measured with direct online FP8 quantization without corrected weights.
MethodRULER ScoreOperator Speedup over FA2
4K8K16K32K64K128KAvg.4K8K16K32K64K128K
Llama-3.1-8B-Instruct
Full95.9894.7493.0789.0686.2773.8288.821.00×1.00×1.00×1.00×1.00×1.00×
MInference95.0694.2392.1887.6883.0171.6187.300.12×0.18×0.46×0.83×1.34×2.45×
FlexPrefill95.1894.0992.3586.7984.0872.0187.420.12×0.33×0.98×2.21×4.16×5.18×
XAttention95.2494.3791.6187.0383.6572.3387.370.79×1.29×1.83×2.34×3.19×3.48×
FlashPrefill95.1694.2992.1187.4984.1870.9187.361.21×2.38×4.31×7.46×13.62×22.67×
FlashPrefill V295.5294.6592.9588.4883.0772.0887.791.66×2.62×4.28×7.63×14.39×27.21×
FlashPrefill V2-FP8∗95.2894.4892.7888.8080.2867.7886.572.67×4.56×7.79×13.89×25.76×47.33×
Qwen3-4B-Instruct-2507
Full94.8292.9891.6888.8682.8171.2287.061.00×1.00×1.00×1.00×1.00×1.00×
MInference94.0692.1891.0988.0782.0868.0185.920.11×0.15×0.42×0.83×1.32×2.53×
FlexPrefill93.8190.9691.4187.6281.3767.2485.400.12×0.33×0.99×2.28×4.01×5.27×
XAttention94.4291.4991.4287.3181.5668.2485.740.81×1.35×1.92×2.38×3.07×3.43×
FlashPrefill94.7192.0491.2887.2981.0869.0285.901.21×2.40×4.36×6.91×11.54×19.26×
FlashPrefill V294.4992.4291.5687.4881.6769.7686.231.72×2.82×4.63×7.92×13.93×27.45×
FlashPrefill V2-FP894.1392.3791.3687.4780.5968.9785.822.75×4.87×8.40×14.44×25.06×47.59×
Qwen3-30B-A3B-Instruct-2507
Full95.7895.2394.3692.7290.1184.1292.051.00×1.00×1.00×1.00×1.00×1.00×
MInference95.7194.3393.8192.0189.0282.0991.160.11×0.17×0.46×0.83×1.43×2.76×
FlexPrefill95.3294.7193.5291.8188.0983.1191.090.12×0.34×0.98×2.31×3.92×5.43×
XAttention95.4394.1292.7891.0688.3982.2390.670.86×1.44×2.01×2.42×2.95×3.42×
FlashPrefill95.6294.4793.2892.1788.1482.9691.111.22×2.43×4.36×6.92×11.45×18.67×
FlashPrefill V295.3594.8594.1992.4889.8883.8391.761.75×2.95×4.62×8.21×14.11×27.19×
FlashPrefill V2-FP895.2894.5394.1292.3489.5482.5591.392.78×5.12×8.41×14.93×25.36×47.26×
Figure 2: Speedup of various attention operators relative to FlashAttention-2 [5] on NVIDIA H20 GPUs, including an FA3/4-aligned dense baseline [22, 38]. All results are measured with a batch size of 4. FlashPrefill V2 exhibits a dominant advantage, particularly in long-context scenarios, and its FP8 variant further amplifies the gains.
Figure 2: Speedup of various attention operators relative to FlashAttention-2 [5] on NVIDIA H20 GPUs, including an FA3/4-aligned dense baseline [22, 38]. All results are measured with a batch size of 4. FlashPrefill V2 exhibits a dominant advantage, particularly in long-context scenarios, and its FP8 variant further amplifies the gains.
Table 2: Performance comparison on all 21 tasks of LongBench [2], grouped by task category. Results marked with ∗ (in gray) are measured with direct online FP8 quantization without corrected weights.
MethodSingle-Document QAMulti-Document QASummarizationFew-shot LearningSyntheticCodeAvg.
NarrQAQasperMF-enMF-zhHotpot2WikiMuSiQueDuReadGovRepQMSumMNewsVCSumTRECTQASAMSumLSHTCountPR-enPR-zhLCC
Llama-3.1-8B-Instruct
Full29.3944.6156.3463.6357.4848.0832.2834.4334.5125.2926.8017.3772.5091.4843.5946.5011.10100.0090.45
MInference28.1342.3653.6762.0856.2846.7232.0133.4133.2825.1627.0216.8469.5090.8342.8743.006.0096.0084.00
FlexPrefill27.6242.6752.9862.3457.1445.3230.9733.7233.8724.5826.3417.0267.5090.3644.7243.006.0094.0083.33
XAttention28.5243.1254.0160.1956.7345.9832.1733.1534.5525.3727.2117.4171.0091.3744.0544.006.8895.5085.68
FlashPrefill28.3142.8954.2361.9757.0145.7631.9633.6034.0224.8326.4717.1371.0091.1244.2146.507.0095.5083.45
FlashPrefill V230.2144.5655.9762.3758.0248.8432.5733.7834.9025.2427.1317.3772.5091.4544.7645.507.3997.0089.47
FlashPrefill V2-FP8∗29.0845.5154.7062.5955.4146.4032.0332.9734.7024.8826.9717.6170.0091.1644.8045.006.8896.5085.68
Qwen3-4B-Instruct-2507
Full27.9744.9851.1264.5959.3944.1824.8526.1730.6822.6223.9311.7374.0087.7445.5544.000.75100.0098.04
MInference25.8941.6948.2662.1654.1742.7622.1624.8929.1221.9823.1511.2872.0087.6244.3242.500.0091.0094.67
FlexPrefill25.2641.4848.0261.9854.9643.2122.7125.4330.9422.1524.4711.4770.5086.1845.8741.000.5094.0094.20
XAttention24.3142.6749.0163.0254.1443.1422.5625.1229.6322.4123.6811.5672.5086.4745.1341.500.0096.0093.89
FlashPrefill25.0642.7849.2262.3155.0742.9723.4225.6629.8022.0923.3211.6272.0087.9545.4242.000.0092.0094.00
FlashPrefill V227.5643.7351.0763.7256.3943.1123.1826.3630.4822.6723.8811.7674.0087.7445.7841.250.5096.0097.17
FlashPrefill V2-FP826.5542.7050.2861.7155.2141.9524.5026.0330.7422.4724.0711.4873.5088.1645.8941.250.5093.0094.67
Qwen3-30B-A3B-Instruct-2507
Full31.2944.0954.7966.4863.8656.5632.2924.6431.1021.9023.4811.0976.5091.0145.7951.0016.50100.00100.00
MInference28.6241.0853.0664.2861.2151.0131.7123.5230.5321.0722.7910.7275.0090.1644.9646.005.0095.0097.67
FlexPrefill28.0740.9652.4164.0760.7250.9131.6523.9730.0221.6223.8610.8875.5089.3746.3848.504.5097.0096.00
XAttention27.9842.8652.8363.8260.9353.1633.0123.8131.3121.2822.9310.9773.0091.1445.9247.503.0097.0099.00
FlashPrefill28.3541.1153.3464.8161.2751.0930.0824.1130.5521.7423.2111.0277.0090.6846.1246.505.0096.5099.00
FlashPrefill V229.7441.5853.8266.8063.6652.6234.1124.9431.0022.0423.4511.1377.0090.9946.5949.006.5099.5099.50
FlashPrefill V2-FP830.0341.3755.2866.3161.4051.8330.6324.5831.1921.6223.5610.9677.5089.6146.0847.508.5098.0099.00
Figure 3: The FlashPrefill V2 prefill pipeline. Stage 1 packs queries with PackGQA, pools block-mean statistics, and produces a CSR index of selected blocks in a single fused pass; Stage 2 runs the warp-specialized sparse attention kernel over the selected blocks (exact path) while the unselected blocks are compensated through the mean correction path (Sec. 3.2), and the two streams merge inside the online softmax.
Figure 3: The FlashPrefill V2 prefill pipeline. Stage 1 packs queries with PackGQA, pools block-mean statistics, and produces a CSR index of selected blocks in a single fused pass; Stage 2 runs the warp-specialized sparse attention kernel over the selected blocks (exact path) while the unselected blocks are compensated through the mean correction path (Sec. 3.2), and the two streams merge inside the online softmax.
Table 3: Attention density of FlashPrefill V2 measured on needle-in-a-haystack inputs at each sequence length.
Model4K8K16K32K64K128K
Llama-3.1-8B76.0%54.2%33.6%18.7%9.0%4.6%
Qwen3-4B72.0%48.5%29.8%17.6%9.2%4.9%
Qwen3-30B-A3B70.4%46.0%29.6%16.2%9.4%4.9%
Figure 4: Mean correction. Selected blocks (red) are computed exactly, while each pruned block is pooled into its mean statistics (k¯J,v¯J) and contributes a surrogate term |ℬJ|​es¯J​(v¯J,1) to the softmax numerator and denominator, recovering the discarded probability mass without per-token computation.
Figure 4: Mean correction. Selected blocks (red) are computed exactly, while each pruned block is pooled into its mean statistics (k¯J,v¯J) and contributes a surrogate term |ℬJ|​es¯J​(v¯J,1) to the softmax numerator and denominator, recovering the discarded probability mass without per-token computation.
Table 4: End-to-end time-to-first-token (TTFT, seconds) of Llama-3.1-8B-Instruct, Qwen3-4B-Instruct-2507, and Qwen3-30B-A3B-Instruct-2507 served by SGLang on the needle-in-a-haystack workload. Each entry is averaged over 30 repeated measurements. Parenthesized numbers are speedups over the FA3/4 backend.
BSZFA3/4FlashPrefill V2FlashPrefill V2-FP8
4K8K16K32K64K128K4K8K16K32K64K128K4K8K16K32K64K128K
Llama-3.1-8B-Instruct
10.150.290.631.493.9511.810.15 (1.02×)0.29 (1.02×)0.58 (1.09×)1.17 (1.28×)2.46 (1.60×)5.49 (2.15×)0.10 (1.53×)0.18 (1.63×)0.35 (1.81×)0.71 (2.09×)1.48 (2.66×)3.23 (3.66×)
40.581.172.545.9412.3032.940.57 (1.01×)1.14 (1.03×)2.32 (1.09×)4.79 (1.24×)7.69 (1.60×)15.39 (2.14×)0.35 (1.66×)0.68 (1.73×)1.36 (1.87×)2.80 (2.12×)4.49 (2.74×)8.84 (3.73×)
81.072.214.879.8321.2356.671.06 (1.01×)2.14 (1.03×)4.39 (1.11×)7.77 (1.27×)13.18 (1.61×)26.13 (2.17×)0.67 (1.58×)1.39 (1.59×)2.81 (1.73×)4.51 (2.18×)7.66 (2.77×)14.93 (3.80×)
162.603.858.1416.1037.12102.842.58 (1.01×)3.59 (1.07×)7.31 (1.11×)12.56 (1.28×)22.93 (1.62×)46.96 (2.19×)1.44 (1.80×)2.97 (1.30×)4.62 (1.76×)7.28 (2.21×)13.25 (2.80×)26.82 (3.83×)
Qwen3-4B-Instruct-2507
10.090.190.431.133.3511.100.09 (1.02×)0.18 (1.07×)0.36 (1.19×)0.77 (1.47×)1.71 (1.96×)4.12 (2.70×)0.07 (1.42×)0.12 (1.61×)0.23 (1.87×)0.49 (2.33×)1.08 (3.09×)2.44 (4.55×)
40.350.741.694.3510.6131.470.35 (1.01×)0.69 (1.06×)1.43 (1.18×)3.06 (1.42×)5.38 (1.97×)11.55 (2.72×)0.22 (1.59×)0.43 (1.72×)0.88 (1.93×)1.86 (2.34×)3.26 (3.25×)6.73 (4.67×)
80.641.383.257.4018.2553.840.63 (1.02×)1.29 (1.07×)2.70 (1.20×)5.05 (1.47×)9.19 (1.99×)19.35 (2.78×)0.43 (1.49×)0.87 (1.59×)1.78 (1.82×)3.06 (2.42×)5.51 (3.31×)11.28 (4.77×)
161.072.315.5312.2031.7397.261.05 (1.02×)2.15 (1.08×)4.56 (1.21×)8.18 (1.49×)15.84 (2.00×)34.48 (2.82×)0.90 (1.18×)1.83 (1.26×)2.95 (1.87×)4.92 (2.48×)9.43 (3.37×)20.13 (4.83×)
Qwen3-30B-A3B-Instruct-2507
10.100.190.451.264.0013.780.09 (1.02×)0.18 (1.09×)0.36 (1.26×)0.78 (1.61×)1.75 (2.29×)4.17 (3.30×)0.09 (1.06×)0.15 (1.24×)0.30 (1.50×)0.61 (2.07×)1.32 (3.03×)3.00 (4.59×)
40.260.731.764.8613.0540.440.24 (1.09×)0.67 (1.10×)1.42 (1.24×)3.11 (1.56×)5.70 (2.29×)12.16 (3.33×)0.22 (1.18×)0.57 (1.29×)1.15 (1.53×)2.41 (2.01×)4.21 (3.10×)8.59 (4.71×)
80.641.353.368.4722.3768.560.62 (1.03×)1.22 (1.11×)2.65 (1.27×)5.25 (1.61×)9.69 (2.31×)20.35 (3.37×)0.55 (1.15×)1.02 (1.32×)2.11 (1.59×)4.03 (2.10×)7.13 (3.14×)14.35 (4.78×)
161.163.145.9013.9838.50123.231.15 (1.01×)2.92 (1.08×)4.60 (1.28×)8.49 (1.65×)16.55 (2.33×)36.21 (3.40×)1.04 (1.12×)1.73 (1.81×)3.66 (1.61×)6.47 (2.16×)12.16 (3.17×)25.51 (4.83×)
Figure 5: Block-sparse attention latency at 64K sequence length in FP8. HPC-BSA does not support BF16, so only FP8 is compared. Both sparse operators track the theoretical bound; FlashPrefill V2 is 6 to 7% faster than HPC-BSA at every sparsity level.
Figure 5: Block-sparse attention latency at 64K sequence length in FP8. HPC-BSA does not support BF16, so only FP8 is compared. Both sparse operators track the theoretical bound; FlashPrefill V2 is 6 to 7% faster than HPC-BSA at every sparsity level.
Table 5: Open-loop serving results on Qwen3-4B-Instruct-2507 and Qwen3-30B-A3B-Instruct-2507 under Poisson arrivals with mixed prompt lengths (4K–128K RULER needle-in-a-haystack, 100 requests per cell, 64 output tokens each). Parenthesized numbers are speedups over the FA3/4 backend.
Rate (req/s)BackendTTFT (s)TPOT (ms)Throughput
P50P99P50P99(tok/s)(req/s)
Qwen3-4B-Instruct-2507
1FA3/476.73154.64419117024.00.37
FlashPrefill V217.23 (4.45x)48.73 (3.17x)258 (1.62x)601 (1.94x)45.5 (1.90x)0.71
FlashPrefill V2-FP82.79 (27.47x)17.27 (8.95x)47 (8.84x)487 (2.40x)58.4 (2.44x)0.91
4FA3/479.05161.54513110223.80.37
FlashPrefill V242.28 (1.87x)80.34 (2.01x)258 (1.99x)509 (2.16x)47.3 (1.99x)0.74
FlashPrefill V2-FP824.47 (3.23x)46.05 (3.51x)165 (3.10x)331 (3.33x)82.3 (3.46x)1.29
8FA3/479.55161.01463111023.90.37
FlashPrefill V243.83 (1.81x)80.12 (2.01x)236 (1.96x)523 (2.12x)48.3 (2.03x)0.76
FlashPrefill V2-FP825.83 (3.08x)46.24 (3.48x)152 (3.05x)302 (3.68x)82.2 (3.45x)1.28
16FA3/481.91160.99481111023.80.37
FlashPrefill V243.22 (1.90x)78.68 (2.05x)263 (1.83x)501 (2.21x)48.9 (2.05x)0.76
FlashPrefill V2-FP825.14 (3.26x)45.16 (3.56x)152 (3.17x)285 (3.89x)85.5 (3.59x)1.34
Qwen3-30B-A3B-Instruct-2507
1FA3/490.69195.43582133519.90.31
FlashPrefill V217.63 (5.14x)52.15 (3.75x)241 (2.42x)604 (2.21x)44.5 (2.24x)0.70
FlashPrefill V2-FP87.93 (11.44x)21.92 (8.91x)102 (5.69x)637 (2.10x)56.1 (2.82x)0.88
4FA3/4101.44195.33462131219.90.31
FlashPrefill V246.26 (2.19x)85.57 (2.28x)255 (1.81x)520 (2.52x)45.5 (2.29x)0.71
FlashPrefill V2-FP830.62 (3.31x)57.43 (3.40x)198 (2.33x)407 (3.22x)64.6 (3.25x)1.01
8FA3/4105.52195.34481133319.90.31
FlashPrefill V245.73 (2.31x)83.04 (2.35x)234 (2.05x)529 (2.52x)47.0 (2.36x)0.73
FlashPrefill V2-FP833.17 (3.18x)58.46 (3.34x)165 (2.92x)369 (3.62x)66.9 (3.36x)1.05
16FA3/499.68195.20547134719.90.31
FlashPrefill V245.20 (2.21x)81.95 (2.38x)266 (2.06x)514 (2.62x)47.4 (2.38x)0.74
FlashPrefill V2-FP832.47 (3.07x)57.33 (3.40x)185 (2.95x)359 (3.75x)67.7 (3.41x)1.06
Figure 6: Overhead of mean correction at 64K sequence length. The corrected variants (dashed) stay close to the uncorrected ones (solid) in both BF16 and FP8, and the absolute overhead shrinks as sparsity increases.
Figure 6: Overhead of mean correction at 64K sequence length. The corrected variants (dashed) stay close to the uncorrected ones (solid) in both BF16 and FP8, and the absolute overhead shrinks as sparsity increases.
Table 6: Open-loop serving at 16 req/s with chunked prefill at chunk sizes of 8K and 16K (same workload as Tab. 5, where chunking is disabled). Parenthesized numbers are speedups over the FA3/4 backend at the same chunk size.
Chunk sizeBackendTTFT (s)TPOT (ms)Throughput
P50P99P50P99(tok/s)(req/s)
Qwen3-4B-Instruct-2507
8KFA3/480.98165.14597122822.50.35
FlashPrefill V250.15 (1.61x)95.23 (1.73x)360 (1.66x)684 (1.80x)38.7 (1.72x)0.60
FlashPrefill V2-FP833.47 (2.42x)61.20 (2.70x)259 (2.30x)529 (2.32x)60.7 (2.70x)0.95
16KFA3/479.42161.96580120322.90.36
FlashPrefill V245.09 (1.76x)85.47 (1.89x)315 (1.84x)615 (1.96x)43.9 (1.91x)0.69
FlashPrefill V2-FP826.80 (2.96x)50.34 (3.22x)193 (3.00x)382 (3.15x)73.3 (3.20x)1.15
Qwen3-30B-A3B-Instruct-2507
8KFA3/496.61199.39693149418.70.29
FlashPrefill V279.81 (1.21x)149.52 (1.33x)574 (1.21x)1200 (1.24x)24.6 (1.32x)0.38
FlashPrefill V2-FP863.23 (1.53x)121.53 (1.64x)505 (1.37x)1009 (1.48x)29.2 (1.56x)0.46
16KFA3/494.78195.84672146619.00.30
FlashPrefill V246.47 (2.04x)88.15 (2.22x)323 (2.08x)652 (2.25x)42.1 (2.21x)0.66
FlashPrefill V2-FP833.72 (2.81x)62.19 (3.15x)250 (2.69x)464 (3.16x)57.1 (3.00x)0.89
Table 7: Design comparison with the HPC-Ops block-sparse attention kernel. Index memory is evaluated at batch size 1 with 32 query heads and 4 KV heads: the dense mask stores one byte per (query head, 128-token Q tile, 128-token KV tile) regardless of density, whereas the CSR index stores only the selected 64-token tiles as int32 at the measured needle-in-a-haystack densities (Tab. 3), is organized per KV head under PackGQA, and matches the SGLang index format. The fused correction path has no counterpart in HPC-Ops BSA.
HPC-Ops BSAFlashPrefill V2
Sparse index formatdense mask, padded, per Q headCSR of selected blocks, per KV head
Index memory @ 64K / 128K8 MB / 32 MB (any density)3 MB / 6 MB (9% / 5% density)
GEMM–softmax overlapserialintra-warpgroup pingpong
Paged KV addressingper-page TMA (page size ∣ 128)cp.async, arbitrary page size
KV splittingnonecount-balanced CSR splits
Mean correctionnonefused into the mainloop
PrecisionFP8 onlyBF16 + FP8
Table 8: Ablation of the mean correction term on RULER with Qwen3-4B-Instruct-2507, in both BF16 and FP8. Discarding unselected blocks without compensation degrades accuracy increasingly toward longer contexts, while the zero-order correction stays close to full attention at all lengths in both precisions.
Method4K8K16K32K64K128KAvg.
Full Attention94.8292.9891.6888.8682.8171.2287.06
V2 w/o correction94.3892.0691.1887.2180.9268.8685.77
FlashPrefill V294.4992.4291.5687.4881.6769.7686.23
V2-FP8 w/o correction93.7891.8290.6885.0476.8662.7883.49
FlashPrefill V2-FP894.1392.3791.3687.4780.5968.9785.82
Table 9: Ablation of the selection threshold α on RULER at 64K with Qwen3-4B-Instruct-2507 in FP8. Density is the fraction of selected attention blocks. Red numbers are the score drops of the uncorrected variant relative to the corrected pipeline at the same α. Full attention scores 82.81.
α0.20.10.050.0250.0125
Density (%)5.29.214.119.823.6
V2-FP8 w/o correction74.68(−5.44)76.86(−3.73)77.16(−3.51)77.41(−3.31)78.02(−2.73)
FlashPrefill V2-FP880.1280.5980.6780.7280.75

为什么重要

长文本大模型服务目前的瓶颈就在于处理提示词阶段的注意力计算成本,一种能把这部分成本降低数十倍且精度损失很小的计算核心,能直接降低处理长文档、长对话等应用的延迟和成本。由于它原生兼容分页KV缓存和连续批处理这类生产级推理框架的核心机制,相比停留在纸面的研究方案,它更接近工程师可以直接拿来部署使用的工具。

本文术语

  • 预填充(Prefill) · 大模型在生成第一个输出词之前,需要先处理完整输入提示词的阶段,输入越长计算量越大。
  • FlashAttention-2/3/4 · 一系列针对GPU优化的注意力计算核心,每一代都利用更新的硬件特性来提升速度。
  • FP8 · 一种8比特浮点数格式,能加快计算并减少显存占用,但会带来一定精度损失。
  • 分页KV缓存 · 由vLLM推广的显存管理方式,把注意力用到的键值数据按固定大小的页而非整块连续存储进行管理。
  • 连续批处理 · 一种服务技术,把多个并发用户请求的计算步骤混合在一起处理,以保持GPU持续满负荷运转。
  • 首词生成时间(TTFT) · 用户发出请求后,模型输出第一个词所需等待的时间。

论文原文摘要(英文)

Long-context modeling is a pivotal capability for Large Language Models, yet the quadratic complexity of attention remains a critical bottleneck, particularly during the compute-intensive prefilling phase. Our previous work, FlashPrefill, mitigates this cost through instantaneous pattern discovery and max-based dynamic thresholding; however, it remains an algorithmic prototype that is still distant from production deployment. In this paper, we present FlashPrefill V2, which evolves FlashPrefill from a prototype toward practical long-context serving along three dimensions. First, we introduce a mean correction term that effectively suppresses the approximation error, keeping performance degradation manageable even at extreme sparsity levels. Second, we redesign the sparse attention operator with PackGQA memory access, warp specialization, and pingpong pipelining, fully aligning with the latest FlashAttention-3/4 implementations and supporting FP8 inference to meet practical quantization requirements. Third, FlashPrefill V2 natively supports paged KV cache and continuous batching, allowing integration as an attention backend in modern inference frameworks such as SGLang. Extensive evaluations on NVIDIA H20 GPUs---among the most widely deployed inference accelerators---demonstrate that FlashPrefill V2 delivers up to 47.26x and 27.19x speedups over FlashAttention-2 at 128K context length under FP8 and BF16 precision, respectively, and, in FP8, still achieves a 30.49x speedup against an FA3/4-aligned dense baseline.

作者 · Qihang Fan, Huaibo Huang, Zhiying Wu, Bingning Wang, Ran He

在 arXiv 阅读

最新论文

全部论文 →

METAL LAB 最新报道

图片来源: Qihang Fan et al., arXiv:2608.19758, arxiv-nonexclusive