|
1 | | -# ADR 0015 — Kakeya Attention as an attention algorithm + engine substrate roadmap |
| 1 | +# ADR 0015 — Kakeya Inference Engine: a product-grade vLLM replacement, Kakeya Attention native |
2 | 2 |
|
3 | | -- Status: Accepted (definition); substrate = roadmap |
4 | | -- Date: 2026-06-15 |
| 3 | +- Status: Accepted (north star + algorithm definition); engine = in design |
| 4 | +- Date: 2026-06-15 (rev. 2026-06-15) |
5 | 5 | - Supersedes/extends: the "Kakeya Attention vs PagedAttention/RadixAttention" |
6 | | - framing in README and ADR 0014 §3.4 (MLX serial-only / CUDA batched). |
| 6 | + framing in README; ADR 0014 §3.4. |
| 7 | + |
| 8 | +## North star (highest goal — this governs everything below) |
| 9 | + |
| 10 | +The **Kakeya Inference Engine is a product-grade inference engine whose goal is |
| 11 | +to replace vLLM.** It is **not** a research script, **not** a technique bolted |
| 12 | +onto HuggingFace transformers, and **not** "vLLM with a different cache". Its |
| 13 | +**native, first-class attention algorithm is Kakeya Attention** — sink+window |
| 14 | +bound + f_θ KV-projection + dLLM-proposer restoration, as **one primitive**. The |
| 15 | +whole engine (prefill, KV management, admission/scheduling, kernels) is designed |
| 16 | +**around bounded-KV + on-demand restoration as the default invariant**, exactly |
| 17 | +the way vLLM is designed around full-KV PagedAttention. |
| 18 | + |
| 19 | +Everything else in this ADR serves that objective. Explicitly: |
| 20 | + |
| 21 | +- The product target is measured against vLLM by the **engine**, never by the |
| 22 | + research bench. The bench (`k3_cuda_multitenant_parallel_bench.py`, eager HF |
| 23 | + transformers) is **only a correctness/feasibility probe** and is not a thing we |
| 24 | + ship or benchmark as "Kakeya". |
| 25 | +- "Parity → win" with vLLM is an engine deliverable, not a roadmap of vLLM |
| 26 | + features to copy. |
| 27 | + |
| 28 | +## Why "borrow vLLM's pipeline" is the wrong plan (rejected) |
| 29 | + |
| 30 | +vLLM's architecture is **full-KV-centric**: paged blocks store the *whole* |
| 31 | +history; chunked prefill and flash masking are optimizations for *processing and |
| 32 | +storing the full KV*. Porting Kakeya's bounded cache onto that pipeline inherits |
| 33 | +a full-KV-shaped engine and caps the advantage at whatever the cache layout |
| 34 | +saves — i.e. it makes Kakeya a vLLM feature, not a replacement. |
| 35 | + |
| 36 | +A product Kakeya engine instead makes **bounded-KV the native invariant**: |
| 37 | + |
| 38 | +- the **full history is never resident**; evicted context is reconstructed by |
| 39 | + the proposer on demand (Kakeya Attention); |
| 40 | +- **prefill** produces the bounded resident set **+** the restoration path in one |
| 41 | + pass — it must never materialize the O(N·T²) attention mask or full-vocab |
| 42 | + logits that sink the research bench; |
| 43 | +- **admission/scheduling** sizes sessions by their **peak window**, not their |
| 44 | + total token count — this is the structural source of the concurrency win; |
| 45 | +- graph-captured decode, fused-MoE, efficient masking are **table stakes** any |
| 46 | + product engine needs, implemented *in service of* the Kakeya-native design — |
| 47 | + not as a port of vLLM's full-KV pipeline. |
| 48 | + |
| 49 | +## Kakeya Attention — the native algorithm |
| 50 | + |
| 51 | +**Kakeya Attention** = sink+window bound + f_θ KV-projection + dLLM-proposer |
| 52 | +restoration, taken as one primitive. Peer of, and replacement for, the attention |
| 53 | +layer in current engines: |
7 | 54 |
|
8 | | -## Context |
| 55 | +| Algorithm | Replaces | Keeps full KV? | |
| 56 | +| --- | --- | --- | |
| 57 | +| eager / **FlashAttention** | the **compute** layer | yes | |
| 58 | +| vLLM **PagedAttention** / SGLang **RadixAttention** | the **storage** layer | yes | |
| 59 | +| **Kakeya Attention** | **compute + storage** | **no — bounded; evicted KV reconstructed on demand** | |
9 | 60 |
|
10 | | -Kakeya's KV-restoration work (AR verifier + dLLM proposer + f_θ + S5 sink/window) |
11 | | -has been described as a *technique inside* the engine. A same-H200 benchmark vs |
12 | | -vLLM (`docs/reports/kakeya-vs-vllm-multitenant-h200.md`) and a long-context probe |
13 | | -(`docs/reports/kakeya-vs-vllm-longcontext-h200.md`) forced two clarifications: |
| 61 | +FlashAttention makes attention compute cheaper; Paged/Radix make the same *total* |
| 62 | +KV cheaper to allocate/share. **Kakeya Attention makes the total itself bounded.** |
14 | 63 |
|
15 | | -1. The throughput gap to vLLM (~8–14×) is a **substrate** gap (eager HF |
16 | | - transformers decode loop, O(T²) eager prefill), **not** an algorithmic one. |
17 | | -2. The bounded-KV memory advantage is **architecture-dependent** and is a |
18 | | - **decode-time** property that the eager prefill currently masks (OOM at 32k). |
| 64 | +## Where the win is real (model architecture matters) |
19 | 65 |
|
20 | | -This ADR fixes the vocabulary and the roadmap. |
| 66 | +Resident KV is dominated by the **full-attention** layers (they hold full context |
| 67 | +in any engine). So the engine's advantage over vLLM scales with the model's |
| 68 | +full-attention fraction: |
21 | 69 |
|
22 | | -## Decision |
| 70 | +- **gemma-4-26B-A4B** is 25/30 **natively sliding** → vLLM already bounds those |
| 71 | + layers, and gemma-4 keeps recall 1.0 at `sliding_window=68` *with no |
| 72 | + restoration at all* → **no Kakeya moat on gemma-4** (probed; see below). It is |
| 73 | + the wrong showcase model. |
| 74 | +- **Full-attention models** (Qwen/Llama, no native sliding): shrinking the window |
| 75 | + without restoration **destroys recall**, so f_θ+proposer restoration is the |
| 76 | + *only* way to bound memory at full recall — and vLLM, having no restoration, |
| 77 | + **must keep full KV and cannot match it**. This is the engine's target regime. |
23 | 78 |
|
24 | | -### 1. Kakeya Attention is a first-class attention algorithm |
| 79 | +## Feasibility probes so far (informed the design — NOT the product) |
25 | 80 |
|
26 | | -Define **Kakeya Attention** = **sink+window bound + f_θ KV-projection + |
27 | | -dLLM-proposer restoration, as one primitive**. It is a peer of, and a drop-in |
28 | | -replacement for, the attention layer in current engines: |
| 81 | +These ran on the eager-transformers research bench; they validate correctness and |
| 82 | +locate the engine's required invariants. They are not the product engine. |
29 | 83 |
|
30 | | -| Algorithm | Replaces | Keeps full KV? | |
31 | | -| --- | --- | --- | |
32 | | -| eager / **FlashAttention** | the **compute** layer | yes | |
33 | | -| vLLM **PagedAttention** / SGLang **RadixAttention** | the **storage** layer | yes | |
34 | | -| **Kakeya Attention** | **compute + storage** | **no — bounded; evicted KV reconstructed on demand** | |
| 84 | +- **Restoration prefill, memory-efficient (SDPA + chunked logits + bf16 K/V)** — |
| 85 | + unblocked long-context execution at recall 1.0 (16k N=1-only→N=4, 32k OOM→N=2, |
| 86 | + 62k OOM→N=1). Confirms the engine must avoid O(N·T²) masks / full-vocab logits. |
| 87 | +- **gemma-4 bounded decode** — recall 1.0 at `sliding_window=68` natively (no |
| 88 | + restoration); native bounded decode still fits only N=2 @62k vs vLLM's 15.5 |
| 89 | + because the bench does non-chunked prefill. Confirms (a) gemma-4 is the wrong |
| 90 | + showcase, (b) the engine — not bench retrofits — is what must beat vLLM. |
35 | 91 |
|
36 | | -FlashAttention makes attention compute cheaper; Paged/Radix make the same *total* |
37 | | -KV cheaper to allocate/share. **Kakeya Attention makes the total itself bounded**, |
38 | | -and is **composable** with all of them (a flash kernel can compute a Kakeya |
39 | | -window; a paged/radix store can hold it). |
40 | | - |
41 | | -### 2. The engine substrate is Kakeya Attention + CUDA graphs + fused MoE |
42 | | - |
43 | | -The **Kakeya Inference Engine** = Kakeya Attention on a production substrate |
44 | | -(**CUDA graphs + fused-MoE kernels + memory-efficient prefill**), targeting vLLM |
45 | | -on absolute throughput. This is a **build target**, not yet shipped. The current |
46 | | -research path runs the algorithm on **eager HF transformers**, which is correct |
47 | | -and recall-preserving but (a) ~8–14× slower than vLLM at ctx-1238 and (b) OOMs on |
48 | | -long prefills (N=1-only at 16k, OOM at 32k) due to O(T²) eager scores + |
49 | | -full-vocab logits + a redundant `capture_verifier_own_kv` forward. |
50 | | - |
51 | | -**Substrate work items (ordered):** |
52 | | -1. ✅ **Memory-efficient restoration prefill** — patched forward routes to |
53 | | - **SDPA** (`--attn-impl sdpa`), LM-head logits chunked (`logits_to_keep=1` on |
54 | | - the restored forward + `capture_verifier_own_kv`), restored K/V held in bf16. |
55 | | - **Unblocked long context** (recall 1.0): 16k went N=1-only→N=4, 32k OOM→N=2, |
56 | | - 62k OOM→N=1; 16k N=1 peak 138.8→74.5 GB. (`docs/reports/kakeya-vs-vllm-longcontext-h200.md`.) |
57 | | -2. **Bounded decode cache as the native KV layout** — resident sink+window + |
58 | | - 5 exact full-attention layers; no Python per-step `DynamicCache`. **Probed on |
59 | | - gemma-4 and found NOT to beat vLLM there (by architecture):** (a) gemma-4 |
60 | | - keeps recall 1.0 at `sliding_window=68` *natively, with no restoration* (5/30 |
61 | | - full-attn layers carry recall) — so bounded decode is just a native window |
62 | | - shrink that vLLM can match; (b) even native bounded decode fits only N=2 @62k |
63 | | - vs vLLM's 15.5, because the bottleneck is **non-chunked prefill activations**, |
64 | | - not the KV bound — vLLM wins on **chunked-prefill + paged-KV engineering**. |
65 | | - **Conclusion: the Kakeya bounded-KV win must be demonstrated on a |
66 | | - full-attention model** (Qwen/Llama), where shrinking the window without |
67 | | - restoration destroys recall and only f_θ+proposer restoration bounds memory at |
68 | | - full recall — vLLM, lacking restoration, must keep full KV. |
69 | | - (`docs/reports/kakeya-vs-vllm-longcontext-h200.md` Update 2.) |
70 | | -3. **CUDA graphs** for the decode step; **fused-MoE** kernels for the verifier. |
71 | | -4. (Optional) integrate Kakeya Attention as a **vLLM attention backend** so the |
72 | | - bounded window rides vLLM's paged store + scheduler. |
73 | | - |
74 | | -### 3. The bounded-KV win is architecture-dependent |
75 | | - |
76 | | -Resident KV is dominated by the **full-attention** layers (they hold full |
77 | | -context in any engine). gemma-4-26B-A4B is 25/30 **natively sliding** → vLLM |
78 | | -already bounds 25 layers → Kakeya's resident-KV edge is **~7 % at 62k**. On a |
79 | | -**full-attention** model (no native sliding) the edge is **~6×**. Long-context |
80 | | -concurrency "sweet spots" must be claimed **per model architecture**, not |
81 | | -universally. (Consistent with the recorded "S5 free-lunch" caveat: on gemma-4 the |
82 | | -5-exact-layer S5 shortcut already covers recall, so the proposer/f_θ restoration |
83 | | -is *replaced* by S5 on this model.) |
| 92 | +(`docs/reports/kakeya-vs-vllm-longcontext-h200.md`.) |
84 | 93 |
|
85 | 94 | ## Consequences |
86 | 95 |
|
87 | | -- README and docs now present Kakeya Attention as an algorithm peer to |
88 | | - Flash/Paged/Radix, with the substrate explicitly a roadmap. |
89 | | -- Throughput parity with vLLM is gated on the substrate work items above, not on |
90 | | - the algorithm. |
91 | | -- Memory/sweet-spot claims are scoped by full-attention fraction; the strong |
92 | | - long-context demonstration should be run on a full-attention verifier. |
| 96 | +- The repo's highest engineering goal is the **product Kakeya Inference Engine |
| 97 | + replacing vLLM**, with Kakeya Attention as its native algorithm; the eager |
| 98 | + research bench is a probe only and is never reported as "Kakeya performance". |
| 99 | +- The engine is designed bounded-KV-native (admission by peak window; restoration |
| 100 | + fused into prefill/decode), not as a port of vLLM's full-KV pipeline. |
| 101 | +- The vLLM-beating demonstration is to be run on a **full-attention** verifier, |
| 102 | + where restoration is load-bearing. |
93 | 103 |
|
94 | 104 | ## Evidence |
95 | 105 |
|
96 | 106 | - `docs/reports/kakeya-vs-vllm-multitenant-h200.md` (ctx-1238, same H200) |
97 | | -- `docs/reports/kakeya-vs-vllm-longcontext-h200.md` (16k–62k, OOM ceiling + KV model) |
98 | | -- `results/research/{k3_cuda_multitenant_parallel,vllm_multitenant_parallel}_h200nvl_*.json` |
| 107 | +- `docs/reports/kakeya-vs-vllm-longcontext-h200.md` (16k–62k probes + KV model) |
| 108 | +- `results/research/{k3_cuda_multitenant_parallel,vllm_multitenant_parallel,gemma_bounded_decode}_h200nvl_*.{json,log}` |
0 commit comments