Block-Filtered Long-Context Attention (BFLA)
BFLA is the first training-free sparse attention that is competitive with learned sparse attention in quality and speed in real long-context serving.
- Block selection. During prefill, each query tile scores pooled FP8 index keys and selects a shared set of KV blocks. Each query/head row in the tile computes its own causal attention over the selected BF16 keys and values.
- Default budget. Ratio-K targets one third of visible tokens, with a 2K floor and a 32K cap. Protected tail queries attend to the full causal history.
Usage
This build targets Hopper SM90 on Linux x86-64 with PyTorch 2.13 and CUDA 13.0. The example requires Triton and the Hugging Face kernels client.
import torch
from kernels import get_kernel
repo = "Arepse/bfla"
bfla = get_kernel(repo, version=1, trust_remote_code=[repo])
heads = bfla.HeadLayout.create(hq=24, hkv=4, d=256)
n = 8192
q = torch.randn(n, 24, 256, device="cuda", dtype=torch.bfloat16)
k = torch.randn(n, 4, 256, device="cuda", dtype=torch.bfloat16)
v = torch.randn_like(k)
plan = bfla.BFLAPrefillPlan(q, k, v, 256**-0.5, request_lengths=(n,), head_layout=heads)
out = plan.run(q, k, v)
The CUDA extensions are precompiled, and Triton specializes the indexing kernels on first use. Packed and paged inputs use the same selection policy. See the operator interface for supported D256 and D512 head layouts.
For model serving, the separately installed vLLM adapter applies BFLA during prefill and preserves the model's native decoding.
LongBench-v2 with a 1M-token context window
On Qwen3.8-Flash-Next-FP8, all three prefill methods used native QSA decoding. BFLA reduced mean time to first token (TTFT) from 18.557 s with dense FA3 to 7.432 s, a 2.50× speedup.
| Prefill method | Accuracy | Mean TTFT (s) | Mean E2E (s) |
|---|---|---|---|
| Dense (FA3) | 57.85% (291/503) | 18.557 | 21.156 |
| QSA | 58.25% (293/503) | 7.491 | 10.480 |
| BFLA | 58.05% (292/503) | 7.432 | 10.193 |
Serving. We ran vLLM 0.31 on two NVIDIA H200 GPUs (SM90, TP2, batch size 1). All three methods used a 1,000,000-token context window with 4× YaRN scaling and a 16,384-token budget per chunked-prefill step. Prefix caching was disabled. BFLA used its default Ratio-K policy (1/3, minimum 2K, maximum 32K).
Evaluation. We evaluated all 503 questions using the official zero-shot, non-CoT prompt, greedy decoding, thinking disabled, and a 2,048-token output limit. For the 33 prompts exceeding the resulting 997,952-token input limit, we retained the beginning and end.
For RULER, InfiniteBench, Terminal Bench 2.1, and operator-level latency comparisons, see the BFLA paper.
- Downloads last month
- -
- Torch
- 2.13
- OS
- linux
- Arch
- x86_64

