Declarative sparse attention for production LLM inference: define the pattern once, compile it into executable attention paths, and carry the same spec through prefill, decode, KV cache policy, quantization, and serving integration.
Reported H100 benchmark highlights:
| Area | Result |
|---|---|
| Backend speedup, sink32+win128 | 31.1x at 8K |
| Decode speedup, sparse gather+SDPA | 14.14x at 128K KV |
| Decode memory traffic reduction | 98.3% at 128K KV |
| Prefill speedup, sink64+win512 | 3.98x at 32K |
| Dynamic routing quality | 0.984 cosine similarity at 8K with top8 routing |
Full evidence pack: github_showcase/






No system currently does: Declarative pattern spec → Compiled kernel → Deployed in serving → KV cache co-design
| Existing Tool | What it does | What it doesn't |
|---|---|---|
| FlexAttention | Pattern → efficient kernel (Triton/FA4) | No serving integration, no KV cache |
| FlashInfer | JIT kernels → serving (vLLM, SGLang) | No declarative pattern API |
| vLLM/SGLang | Production serving | Fixed menu of patterns, can't define new ones |
| AttentionEngine (MSFT) | Cross-platform compilation | No serving, no cache, research-only |
| ThunderKittens | Low-level kernel DSL | Not declarative, no serving |
A system where you write:
from attn_engine import AttentionSpec, compile_and_deploy
spec = AttentionSpec(
# Pattern definition
pattern="block_sparse",
sink_tokens=32,
local_window=512,
# KV cache policy
cache_budget=1024,
eviction="heavy_hitter", # or "attention_score", "recency", custom
# Phase-aware
prefill_kernel="flash", # use FlashAttention for prefill
decode_kernel="sparse_gather", # custom sparse kernel for decode
# Per-head config (optional)
head_policy="auto", # analyze model to assign per-head budgets
)
# Compile to efficient kernels for both phases
engine = spec.compile(model_config="llama-70b", hardware="h100")
# Deploy into serving stack
engine.register_backend("vllm") # or "sglang", "tgi"
┌─────────────────────────────────────────────────────┐
│ Layer 1: Declarative Spec (Python DSL) │
│ - Pattern types (sparse, sliding, coarse-to-fine) │
│ - KV cache policy (budget, eviction, compression) │
│ - Per-head/per-layer configuration │
│ - Phase annotations (prefill vs decode) │
└─────────────────┬───────────────────────────────────┘
│
┌─────────────────▼───────────────────────────────────┐
│ Layer 2: Compiler (generates phase-aware kernels) │
│ - Prefill: block-sparse Triton/FlexAttention │
│ - Decode: gather-based sparse KV kernel │
│ - Validates correctness (reference impl) │
│ - Hardware-specific optimization (H100/A100/MI300) │
└─────────────────┬───────────────────────────────────┘
│
┌─────────────────▼───────────────────────────────────┐
│ Layer 3: Runtime (integrates with serving stacks) │
│ - vLLM backend plugin │
│ - SGLang backend plugin │
│ - KV cache lifecycle management │
│ - Continuous batching compatibility │
│ - PagedAttention-compatible memory layout │
└─────────────────────────────────────────────────────┘
Existing frameworks assume patterns are known at compile time (positional masks). We support runtime token-content-dependent routing:
spec = AttentionSpec(
pattern="dynamic_routing",
router=lambda q, k_blocks: top_k_blocks(q @ mean(k_blocks), k=16),
# Router runs at block granularity (cheap)
# Selected blocks get full fine-grained attention
)
This is the coarse-to-fine approach (like DeepSeek NSA) but:
We're the glue layer — not competing with any single tool, bridging them.
| Paper/System | What to reuse |
|---|---|
| FlexAttention (PyTorch) | score_mod/mask_mod API design, Triton codegen |
| FlashInfer (UW) | JIT template system, PagedAttention layout |
| DeepSeek NSA | Coarse-to-fine block selection algorithm |
| SpargeAttention | Training-free block importance scoring |
| Ada-KV / DuoAttention | Per-head budget allocation strategies |
| SnapKV / H2O | KV eviction policies |
2 commits
Python
100.0%
Declarative sparse attention for production LLM inference: define the pattern once, compile it into executable attention paths, and carry the same spec through prefill, decode, KV cache policy, quantization, and serving integration.
Reported H100 benchmark highlights:
| Area | Result |
|---|---|
| Backend speedup, sink32+win128 | 31.1x at 8K |
| Decode speedup, sparse gather+SDPA | 14.14x at 128K KV |
| Decode memory traffic reduction | 98.3% at 128K KV |
| Prefill speedup, sink64+win512 | 3.98x at 32K |
| Dynamic routing quality | 0.984 cosine similarity at 8K with top8 routing |
Full evidence pack: github_showcase/






No system currently does: Declarative pattern spec → Compiled kernel → Deployed in serving → KV cache co-design
| Existing Tool | What it does | What it doesn't |
|---|---|---|
| FlexAttention | Pattern → efficient kernel (Triton/FA4) | No serving integration, no KV cache |
| FlashInfer | JIT kernels → serving (vLLM, SGLang) | No declarative pattern API |
| vLLM/SGLang | Production serving | Fixed menu of patterns, can't define new ones |
| AttentionEngine (MSFT) | Cross-platform compilation | No serving, no cache, research-only |
| ThunderKittens | Low-level kernel DSL | Not declarative, no serving |
A system where you write:
from attn_engine import AttentionSpec, compile_and_deploy
spec = AttentionSpec(
# Pattern definition
pattern="block_sparse",
sink_tokens=32,
local_window=512,
# KV cache policy
cache_budget=1024,
eviction="heavy_hitter", # or "attention_score", "recency", custom
# Phase-aware
prefill_kernel="flash", # use FlashAttention for prefill
decode_kernel="sparse_gather", # custom sparse kernel for decode
# Per-head config (optional)
head_policy="auto", # analyze model to assign per-head budgets
)
# Compile to efficient kernels for both phases
engine = spec.compile(model_config="llama-70b", hardware="h100")
# Deploy into serving stack
engine.register_backend("vllm") # or "sglang", "tgi"
┌─────────────────────────────────────────────────────┐
│ Layer 1: Declarative Spec (Python DSL) │
│ - Pattern types (sparse, sliding, coarse-to-fine) │
│ - KV cache policy (budget, eviction, compression) │
│ - Per-head/per-layer configuration │
│ - Phase annotations (prefill vs decode) │
└─────────────────┬───────────────────────────────────┘
│
┌─────────────────▼───────────────────────────────────┐
│ Layer 2: Compiler (generates phase-aware kernels) │
│ - Prefill: block-sparse Triton/FlexAttention │
│ - Decode: gather-based sparse KV kernel │
│ - Validates correctness (reference impl) │
│ - Hardware-specific optimization (H100/A100/MI300) │
└─────────────────┬───────────────────────────────────┘
│
┌─────────────────▼───────────────────────────────────┐
│ Layer 3: Runtime (integrates with serving stacks) │
│ - vLLM backend plugin │
│ - SGLang backend plugin │
│ - KV cache lifecycle management │
│ - Continuous batching compatibility │
│ - PagedAttention-compatible memory layout │
└─────────────────────────────────────────────────────┘
Existing frameworks assume patterns are known at compile time (positional masks). We support runtime token-content-dependent routing:
spec = AttentionSpec(
pattern="dynamic_routing",
router=lambda q, k_blocks: top_k_blocks(q @ mean(k_blocks), k=16),
# Router runs at block granularity (cheap)
# Selected blocks get full fine-grained attention
)
This is the coarse-to-fine approach (like DeepSeek NSA) but:
We're the glue layer — not competing with any single tool, bridging them.
| Paper/System | What to reuse |
|---|---|
| FlexAttention (PyTorch) | score_mod/mask_mod API design, Triton codegen |
| FlashInfer (UW) | JIT template system, PagedAttention layout |
| DeepSeek NSA | Coarse-to-fine block selection algorithm |
| SpargeAttention | Training-free block importance scoring |
| Ada-KV / DuoAttention | Per-head budget allocation strategies |
| SnapKV / H2O | KV eviction policies |
2 commits
Python
100.0%