perf: replace paged KV cache with contiguous ContiguousCache, decode all groups

- Add KVCache/CacheView abstract base classes in cache.py
- Add ContiguousCache (contiguous per-slot buffer, default) alongside PageCache (paged, renamed from old KVCache)
- Merge make_table_tensor + bind into bind_tasks on KVCache interface
- Remove task_cached/task_record_hashes from base class (PageCache-only)
- Scheduler: decode all position groups instead of just the largest (eliminates 63% group skip rate)
- Scheduler: accept optional cache param for swapping implementations
- Model layer type hints use CacheView base class
- Batch 1-32: 1-7% speedup from eliminating Storage.gather overhead
- All 183 inference tests pass
This commit is contained in:
2026-07-05 11:34:36 +08:00
parent 599a51f4f7
commit 5416c2e8fb
9 changed files with 215 additions and 62 deletions
+3 -3
View File
@@ -4,7 +4,7 @@ import torch
from astrai.inference import (
Allocator,
KVCache,
PageCache,
PagePool,
PrefixCache,
Storage,
@@ -161,7 +161,7 @@ def test_task_table_pop():
def test_kv_cache_task_extend_allocates():
cache = KVCache(
cache = PageCache(
n_layers=1,
n_pages=8,
page_size=64,
@@ -177,7 +177,7 @@ def test_kv_cache_task_extend_allocates():
def test_kv_cache_task_extend_fails_when_pool_full():
cache = KVCache(
cache = PageCache(
n_layers=1,
n_pages=2,
page_size=64,