---
title: 'TokenLake: Unified Segment-Level Prefix Cache'
url: https://www.emergentmind.com/topics/tokenlake
type: topic
---

# TokenLake: Unified Segment-Level Prefix Cache

TokenLake is a unified segment-level prefix cache pool designed to provide fine-grained, elastic, long-context large language model (LLM) serving across GPU clusters. It introduces a declarative interface for managing prefix caches (layer-wise key/value tensors from prefill and decoding phases) at segment granularity, enabling pooled GPU memory, automatic load balancing, deduplication, defragmentation, and minimized inter-node communication. By fully decoupling cache management from compute scheduling, TokenLake addresses the fundamental inefficiencies of prior cache-aware routing and phase-disaggregation approaches in multi-turn, high-throughput LLM inference contexts [2508.17219].

## 1. Limitations of Prior Prefix Caching Systems

Large-context LLM deployments typically rely on prefix caching to avoid redundant computation in multi-turn interactions, where shared prefixes may extend over tens or hundreds of thousands of tokens. Traditional systems fall into two paradigms:

- **Cache-Aware Routing:** Each GPU maintains a local prefix-tree of KV cache slots, with a central router dispatching requests to optimize for hit-rate and load. This tight coupling induces:
    - Load imbalance (popular prefixes concentrated on few nodes)
    - Redundancy (prefixes replicated across multiple instances)
    - Memory fragmentation (underutilized slots cannot be utilized elsewhere)

- **Phase-Disaggregation (PD):** Prefill and decoding phases are segregated across pools, requiring transfer of full prefix states, which increases redundancy, fragmentation, and incurs high transfer overhead.

No existing approach enables true memory pooling since their imperative APIs force explicit, monolithic cache management, and always transfer increasingly long prefixes—precluding low-latency migration and fine-grained balancing [2508.17219].

## 2. Declarative Prefix Cache Interface

TokenLake introduces a declarative interface categorizing API calls into control-plane (stateless) and data-plane (declarative) operations.

- **Control Plane:**
    - `get_prefix_tree()`: returns the global prefix tree $T$
    - `get_cache_load(reqs)`: estimates GPU resource fraction $L$ used by a request set $\mathrm{reqs}$
    - `gen_plans(batches, \mathrm{DoP})`: outputs per-batch segment access (`query_plans`) and storage (`transfer_plans`) directives for instance groups

Formally, for $\mathrm{reqs}$ with prefix lengths $p_r$, new input lengths $i_r$, and hidden dimension $d$:

$$
M_r = \sum_{r \in \mathrm{reqs}} 4d(p_r + i_r) \\
F_r = \sum_{r \in \mathrm{reqs}} 2d p_r i_r \\
L = \max \left(
\frac{M_r}{M_r + N B_\mathrm{mem} T_r},\
\frac{F_r}{F_r + N F T_r}
\right)
$$

with $N$ instances, $B_\mathrm{mem}$ GPU DRAM bandwidth, $F$ GPU FLOPS, and $T_r$ estimated per-request minimum execution time (from pre-profiled regression).

- **Data Plane:**
    - `init_query(query_plan)`: initializes per-instance shared buffers for queries
    - `init_transfer(transfer_plan)`: allocates buffers for new cache segments
    - `query(q_\mathrm{buf})` and `put(kv_\mathrm{buf})`: coordinate scatter/gather and push operations across the cluster
    - All communication overlaps compute using a peer-to-peer, asynchronous design with CUDA MPS and NCCL-registered buffers.

This abstraction decouples the scheduler from explicit cache placement or movement, supporting stateless orchestration and enabling true GPU memory pooling [2508.17219].

## 3. Segment-Level Model and Execution

TokenLake fragments each prefix into contiguous segments of size $C$ tokens, yielding $N_\mathrm{seg} = \lceil S / C \rceil$ for a prefix of length $S$:

$$
C \geq \frac{2\alpha_\mathrm{net} + 4d/B_\mathrm{net}}{k_\mathrm{comp}}
$$

where $k_\mathrm{comp} = \max(4d / F, 4d / B_\mathrm{mem})$, $\alpha_\mathrm{net}$ is network latency, and $B_\mathrm{net}$ is network bandwidth. Empirically, for A100/InfiniBand ($d \approx 4096$, $F \approx 19.5$ TFLOPS, $B_\mathrm{mem} \approx 2$ TB/s, $B_\mathrm{net} \approx 200$ GB/s, $\alpha_\mathrm{net} \approx 2$ μs), $C \approx 568$ tokens suffices.

With segment granularity, each segment is independently placed and managed, enabling:
- Fine-grained migration and partial cache sharing
- Defragmentation and deduplication
- Overlap of segment fetch with self-attention computation
Remote fetching of a segment is never slower than local re-computation if $C$ satisfies the criterion above [2508.17219].

## 4. Heavy-Hitter-Aware Load Balancing and Eviction

Segment access skew is addressed via the Heavy-Hitter-Aware (HHA) algorithm:
- Segments are classified as:
    - **Heavy hitters ($H$):** $O(N \log N)$ most-accessed segments, tracked by breadth-first search over the prefix tree with access counts $h(s)$
    - **Normal segments ($S \setminus H$):** the remainder

Assignment proceeds as follows:
- **Normal segments:** Placed by uniform hashing ($\mathrm{Hash}(s) \bmod N$) for intrinsic load balance
- **Heavy hitters:**
    - Monitor per-instance segment load $L_i$ by sliding window
    - Overloaded instances replicate hot segments to least-loaded peers until $\max_i L_i \approx \min_i L_i$
    - Queries use power-of-two-choices among replicas for minimal response time

Eviction is global least recently used (LRU): all replicas log last-access timestamps, and the least recently used is reclaimed on pool exhaustion. The procedure achieves a segment-access load coefficient of variation $\mathrm{CV} \lesssim 15\%$ (compared to up to 122% in PD-disaggregation baselines) [2508.17219].

## 5. Communication Volume Minimization

Batch dispatch to instances affects the required communication for queries (scatter/gather) and new KV segment placement. TokenLake employs minimum-weight perfect matching via the Hungarian algorithm ($O(N^3)$ time):

For $M$ batches $U = \{u_1, \ldots, u_M\}$ and $N$ instances $V = \{v_1, \ldots, v_N\}$:
- For each $u_i$, define $Q(u_i)$ as the set of instances owning needed segments and $P(u_i)$ as those designated for new segments
- Edge weights $e(u_i, v_j)$ are negative of the sum of bytes that would be communicated if $u_i$ is scheduled on $v_j$
- The matching assigns each batch to an instance to minimize total inter-node communication

This step is entirely transparent to the LLM scheduler [2508.17219].

## 6. Integration with Stateless, Elastic Scheduling

Because TokenLake exposes cache management declaratively, conventional and modern schedulers (PD-disaggregation, chunked prefill, elastic sequence parallelism) require no modifications:
1. Batches are formed and degree-of-parallelism chosen as usual by the scheduler
2. TokenLake APIs provide cache layout and load estimation
3. Query and transfer plans are generated and initialized
4. Compute engines handle actual model execution, with all cache operations asynchronous and overlapped

Each GPU runs three concurrent processes: compute engine (core LLM computation), query engine (peer-to-peer query coordination), and transfer engine (segment migration), all using peer-to-peer zero-copy buffers. This architecture achieves isolation of TokenLake’s cache traffic from main compute, improving utilization [2508.17219].

## 7. Performance Evaluation and Contributions

Evaluation on Llama-2-7B (16K context), A100 GPUs, NVLink + 200G InfiniBand, and real-world workloads (LooGLE, SCBench, ShareGPT) demonstrates:

| System                    | P90 Goodput (req/s) | Throughput (relative) | Hit Rate @512K tokens |
|---------------------------|---------------------|----------------------|----------------------|
| SGLang-Router             | 9                   | ×1                   | 37%                  |
| SGLang-MoonCake-1P3D      | 12                  | ×1.1                 | 25%                  |
| SGLang-MoonCake-3P1D      | 11                  | ×0.9                 | 22%                  |
| **TokenLake**             | **24**              | **×2.6**             | **75% (+2.0×)**      |

- **Load balance** CV: SGLang-Router 99%, MoonCake-1P3D 62%, MoonCake-3P1D 122%, TokenLake 11%
- **Multi-node (16 × A800 GPUs):** TokenLake achieves up to 28× higher throughput under comparable latency SLO
- Key contributions:
    - Declarative cache interface for decoupling and pooling
    - Segment-level cache management
    - HHA load balancing with power-of-two-choice routing
    - Communication-efficient batch dispatch
    - Demonstrated 2.6× throughput and 2.1× hit-rate improvement [2508.17219]

## 8. Limitations and Prospective Developments

- The segment size $C$ is statically chosen based on hardware; further reductions in overhead for extreme prefix lengths may be possible with adaptive or hierarchical schemes
- Current pooling is GPU-local; extension to CPU/GPU hybrid memory is a viable direction
- The Hungarian algorithm is efficient for $\sim$dozens of GPUs but may become intractable at cluster scale; approximate matchings or streaming approaches may be required
- Integration of advanced capabilities such as cross-request prefetching, cache compression, or retrieval-augmented methods into TokenLake’s declarative infrastructure is an open area

TokenLake demonstrates that declarative, segment-level, and globally managed prefix caches enable highly efficient, elastic, and low-latency LLM inference serving, with comprehensive improvements in throughput, hit-rate, and memory utilization over prior arts [2508.17219].

Source: https://www.emergentmind.com/topics/tokenlake