Repository navigation
feat(kv-cache): add distributed PagedAttention engine and speculative double-buffering prefetcher - #2461
Open
presentyourlove wants to merge 1 commit into
Conversation
… double-buffering prefetcher Introduce virtual paged KV blocks (PagedKVBlock and BlockTable) to eliminate memory fragmentation, combined with an asynchronous DoubleBufferPipeline and SpeculativePrefetchPredictor to overlap NVMe/network KV fetching with forward compute layers, achieving zero-latency perception for long context generation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR implements Frontier Dimension 2.1: Distributed PagedAttention & Speculative KV Prefetching, eliminating memory fragmentation and masking cross-node/NVMe I/O transfer latency through a pipelined double-buffering architecture.
Background & Motivation
In distributed edge inference and long-context generation (8K+ tokens), KV cache memory fragmentation severely degrades memory efficiency. Furthermore, reloading historical KV blocks from NVMe SSDs or remote peer nodes introduces noticeable multi-millisecond decoding stalls.
By decoupling contiguous KV tensors into fixed-size virtual pages (
PagedKVBlock&BlockTable) and executing speculative background prefetching concurrently with forward compute layers, I/O transfer latencies are completely hidden behind compute time, achieving "Zero-Latency Perception".Key Changes
Virtual Paged KV Types & Telemetry (
src/exo/shared/types/paged_kv.py):PagedKVBlock: Immutable page unit holding discrete KV projections with device location tracking (local_ram,nvme_ssd,remote_node).BlockTable: Manages logical token index to physical/remote page mappings.PrefetchRequest&PrefetchTelemetry: Tracks hit rates, masked I/O latency, and pipeline masking efficiency.Speculative Predictor & Double-Buffering Pipeline (
src/exo/worker/engines/paged_attention/prefetch_manager.py):SpeculativePrefetchPredictor: Predicts future blocks along sequential decoding trajectories while retaining critical initial attention sink pages.DoubleBufferPipeline: Orchestrates concurrent background I/O fetching while the main thread executes forward layer computation, enabling zero-wait handover.Paged Cache Engine (
src/exo/worker/engines/paged_attention/paged_cache_engine.py):PagedCacheEngine: High-level orchestrator handling token appending, cross-tier page eviction, speculative prefetching execution, and transparent fallback.Module Exports (
src/exo/worker/engines/paged_attention/__init__.py):PagedCacheEngine,DoubleBufferPipeline, andSpeculativePrefetchPredictor.Unit Tests (
src/exo/shared/tests/test_paged_kv_prefetch.py):Verification
.venv/Scripts/pytest.exe src/exo/shared/tests/test_paged_kv_prefetch.py # 5 passed in 0.12s.venv/Scripts/ruff.exe check src/exo/shared/types/paged_kv.py src/exo/worker/engines/paged_attention/prefetch_manager.py src/exo/worker/engines/paged_attention/paged_cache_engine.py src/exo/worker/engines/paged_attention/__init__.py src/exo/shared/tests/test_paged_kv_prefetch.py # All checks passed!Related Issues
人人都能跑llm.md(Distributed PagedAttention & Speculative KV Prefetching)