Prefix Cache Hit Validation Under Heterogeneous Hybrid Attention

    This article explains why a high prefix cache hit rate does not guarantee correct inference once a model mixes different attention patterns across layers. It covers the five cache object types and their recovery conditions, why allocators and matchers must be decoupled, the four layers of hit validation, and four consistency checks teams should enforce to keep both throughput and correctness in long-context, high-reuse serving.

    1. The Starting Problem: Hit Rate Is Not Correctness

    In large model inference serving, prefix caching is almost a standard optimization. Token history that has already been computed is split into fixed-size pages, a page table maps those pages to physical GPU memory blocks, and later requests reuse the existing blocks whenever the prefix hash matches, skipping redundant computation. This mechanism has run reliably in mainstream inference frameworks for a long time and delivers meaningful throughput gains.

    But one fact is often overlooked: the prefix cache hit rate is a performance metric, not a correctness metric. A high hit rate only means “the lookup found something.” It does not guarantee that what is read back is correct, complete, and usable for continued computation. In traditional homogeneous attention models, these two things happen to overlap almost completely, which hides the problem. Once different layers inside a model mix different attention forms, the two separate.

    2. How Hybrid Attention Breaks the Old Assumption

    Hybrid attention means different layers of the same model use different strategies: some layers build a compressed representation over the full history, some only look at a fixed-length sliding window, and some use sparse routing to attend to a small number of key positions. Three input scenarios push cache state into situations that no single rule can cover:

    • Mixed forms across layers: the same token span must be stored in different forms at different layers;
    • Contexts too long for GPU memory capacity: history must be spilled in tiers or kept resident in compressed form;
    • Cross-request reuse: different requests share a prefix but have different lifetimes and recovery conditions.

    An analogy: in a traditional model, finding a block is like finding a shelf number in a library, and you simply go get the book. Under hybrid attention, after finding the number you must confirm five things: whether the book is still on the shelf (whether the compressed keys and values have been generated), whether the latest pages are bound (whether the tail has settled), whether the borrowing card has expired (whether the sliding window still covers that position), whether the index catalog is synchronized (whether the routing state is updated), and whether the book has been sent to a suburban warehouse and not yet returned (whether the cold prefix has been promoted back). Only when all five are confirmed recoverable can you actually continue reading.

    3. Five Cache Object Types: Lifetimes and Recovery Conditions

    Engineering practice should explicitly track the following five object types, each with its own state determination and recovery path:

    1. Compressed KV: derived by compressing the full history; once generated it can be reused for a long time, but the compressed block must be confirmed fully written;
    2. Uncompressed tail: the most recent tokens that have not yet been compressed; it must exist and be contiguous, otherwise the prefix “hits” but is missing its tail;
    3. SWA window: valid only within a fixed window; positions outside the window cannot be reused directly;
    4. Indexer state: the index or routing table that sparse routing depends on; it must be synchronized with the current prefix;
    5. On-disk prefix: already sunk to external storage; it must be promoted back to GPU memory before it can participate in computation.

    Illustrative pseudocode:

    1. def can_resume(prefix_id, page_table):
    2. checks = {
    3. "compressed": is_complete(page_table.compressed_blocks),
    4. "tail": has_contiguous_tail(page_table.tail_tokens),
    5. "swa": window_covers(page_table.swa_range, prefix_id),
    6. "indexer": indexer_synced(page_table.index_state),
    7. "ondisk": promoted_to_device(page_table.cold_prefix),
    8. }
    9. return all(checks.values()) # if any check is false, do not resume computation directly

    4. The Allocator and the Matcher Must Be Decoupled

    A traditional allocation step only picks a free GPU memory block for new tokens to be written into, while the matching step reports hits in parallel by hash. Once cache objects become heterogeneous, the allocator can no longer just “find a free block”; it must also record the current form and state version for each token span. Otherwise the matcher reports a hit by hash, but at read time the tail, the window, or the routing is missing, and generation output is simply wrong.

    The recommended approach is to maintain a state descriptor for each page (a form enum plus a version number plus a promotion flag) and to have match results carry a state summary that is validated uniformly before reading.

    5. Four Layers of Hit Validation

    Deciding whether a prefix hit can “really be resumed directly” requires at least four layers of validation:

    • Whole-block alignment (lcm blocks): page size, compressed block size, and window granularity must be aligned by least common multiple to avoid reusing half a block;
    • Kernel ABI consistency: the read path and the compute kernels must agree on the state layout convention;
    • State intersection across multiple cache groups: when several cache groups hit at the same time, take the intersection of their states and fall back if any one is unsatisfied;
    • Byte-level hardware alignment: cross-device or cross-precision reuse must be validated on byte alignment to prevent hidden misalignment.

    6. Four Consistency Checks (Not Negotiable)

    1. Admission cap: limit the number of concurrently resident cache states to prevent state explosion;
    2. Five-state routing: route recovery separately for the five object types, and forbid one-size-fits-all reuse;
    3. TOCTOU and state pointers: state can change between validation and use, so pin the state pointer or add a version lock to avoid a mismatch between the check time and the use time;
    4. Static topology constraints: in static graph execution mode, the cache topology must stay static, and dynamic promotion should go through an explicit update rather than implicit reshaping.

    7. Conclusion

    Hybrid attention does not mean “caching no longer works”; it means hit determination must be upgraded from hash equality to state recoverability. By making the lifetimes of the five object types clear, decoupling allocation from matching, and putting the four validation layers and four consistency checks into code, teams can obtain both performance and correctness in long-context, high-reuse scenarios. For teams using general cloud capabilities such as container platforms, object storage, and monitoring and alerting, it is advisable to bring both the state hit rate and the fallback rate into monitoring, and to keep calibrating the caching strategy with observability.