Chunked State Caching for Hybrid LLM Architectures: FlashStates' Approach

    Hybrid models combine full attention with linear attention or SSM layers, which makes prefix caching harder because hidden states cannot be concatenated like KV entries. This article explains the caching problem, compares common workarounds, describes FlashStates' chunk-based state storage and offload design, examines the reported 3x prefill throughput claim, and outlines production engineering and block-size calibration considerations for Agent workloads.

    Why Hybrid Architectures Make Caching Harder

    Large language model architectures are becoming more hybrid. Models combine full attention layers with linear attention layers or state space model (SSM) layers. Full attention layers are good at capturing long-range semantic dependencies, while linear layers require less computation for long sequences, reduce the KV cache memory footprint during inference, and speed up decoding.

    This combination creates new problems in multi-turn, long-context Agent scenarios. A pure Transformer prefix cache only needs to store the Key and Value for each layer, and new input can be directly appended to the old KV sequence. The linear layers and SSM layers in a hybrid model also maintain a hidden state. This state is updated step by step with the input. Once saved, it cannot be directly concatenated like KV when new content arrives; computation can only continue from a certain point. Therefore, prefix caching strategies need to be redesigned.

    Three Common Approaches to Existing Caching

    1. Reuse KV Only and Ignore Hidden State

    This approach follows the pure Transformer idea and saves the full KV for each layer. In a hybrid model, if only KV is reused and the hidden state is not handled, the state of a new request may be inconsistent with the prefix, and the generated result may deviate from expectations.

    2. Recompute State from Scratch for Every Request

    To save memory, some systems do not cache state and compute from the initial state for every request. This reduces memory pressure, but the prefill computation grows with the number of dialogue turns. Once an Agent makes multiple rounds of tool calls or code iterations, first-token latency increases noticeably.

    3. Truncate State with a Sliding Window

    Other approaches keep only the state from the most recent steps and discard earlier information. This controls memory usage but loses long-range dependencies. Code generation and complex reasoning are sensitive to early context, so the risk of accuracy degradation is relatively high.

    The table below lists the main differences between the three approaches and the chunked scheme.

    Scheme Recompute scope after a prefix hit Memory or storage overhead Main risk
    Reuse KV only State must be recomputed Medium State inconsistent with prefix
    Recompute state per request Full segment recomputation Low Prefill latency grows with turns
    Sliding-window state Incremental computation within the window Low Loss of long-range dependencies
    Chunked state caching Recompute increment from the nearest block boundary Medium; adjustable via offload Complex implementation; block size needs calibration

    FlashStates’ Core Design

    The source introduced FlashStates but did not provide a paper, version, or code source. This article summarizes its approach based on the original description and does not independently verify it. For specific data, refer to the original paper or official materials.

    FlashStates’ idea is to handle state management separately from KV caching and organize both by sequence blocks. State cannot be snapshotted as a whole, but it can be saved at block boundaries.

    Chunked State Storage

    The system divides long sequences into fixed-length blocks. Each block stores two types of content: the KV pairs produced by attention layers within the block, and the output state of linear layers or SSM layers at the end of the block. In this way, any prefix can be represented as a combination of several consecutive blocks. After a new request hits a prefix, the system starts computing the increment from the nearest block boundary instead of starting from scratch.

    State can be saved, but after new input arrives it cannot be directly concatenated and reused. The system must recompute the new part from the block boundary, and the chunked scheme relies on this premise.

    Offload and Prefetch Based on Access Locality

    GPU memory is limited, so the system needs to decide which blocks remain in GPU memory. Frequently accessed prefix blocks are kept in memory, while less frequently accessed blocks are moved to CPU memory or NVMe storage. In Agent scenarios, multiple parallel sessions switch frequently, and the system can preload the next block while computing the current block, thereby reducing waiting.

    About the Claim of “3x Prefill Throughput Improvement”

    The source states that FlashStates can improve prefill throughput by about 3x and that prefill computation in real Agent trajectories is reduced by about 70% to 80%. The source does not specify the test conditions, including model size, block size, sequence length, comparison baseline, or hardware platform, nor does it describe the measurement method.

    Therefore, this article does not treat the 3x figure as a conclusion that can be directly applied. A reasonable interpretation is that when the prefix hit rate is high and repeated prefixes are long, the proportion of repeated prefill that can be skipped is large, and the throughput improvement will be more noticeable. When the hit rate is low, the benefit will be much smaller. A reliable way to judge the benefit is to measure the prefix reuse length in your own workload and test on real traffic, rather than directly adopting official numbers.

    Production Engineering Considerations

    State Storage Format

    Hidden states are high-dimensional floating-point tensors, and compressed storage can reduce I/O overhead. One approach is to quantize blocks, for example using an 8-bit floating-point format. Quantization introduces precision loss, so it needs to be validated before launch. The following steps are recommended:

    1. Compare output quality with full precision and quantized storage on a representative task set, such as code pass rate and factual accuracy.
    2. Set an error threshold for each block or layer, and keep critical blocks that exceed the threshold in full precision.
    3. Record fallback counts after launch. If quality metrics for a certain type of request decline, automatically switch back to full-precision storage.

    Scheduler Coordination

    The scheduler needs to understand block granularity. Allocating consecutive free blocks to the same request helps spatial locality. The scheduler also needs to decide when to offload and prefetch, avoiding prefetched blocks being evicted before use.

    Integrating with an Existing Paged KV System

    For systems that already use paged KV caching, chunked state management can be added as an upper-layer logic and connected to the existing page table through an adapter layer. This keeps changes to the underlying memory allocator relatively small.

    Consistency Validation and Rollback

    The state of each block should carry version information and an input hash. During loading, the system checks whether the hash is consistent with the current prefix. If not, it discards the block and recomputes from an earlier boundary. Validation failures should be logged, and the system should be allowed to switch to a computation path without caching to ensure correct results.

    How to Choose Caching for Hybrid Architectures

    First look at the business workload. If multi-turn long-context requests account for a low proportion and single-turn question answering dominates, KV caching plus ordinary prefix reuse is usually sufficient, and the complexity of chunked state caching may not be worth the investment. If an Agent needs multiple rounds of tool calls and repeated code modifications, and the prefix reuse rate is high, a chunked scheme is more likely to bring benefits.

    What to Watch in Chunked State Caching

    Block size is the parameter that most needs tuning. If the block is too large, the amount of recomputation at boundaries increases. If the block is too small, state storage and management overhead increase. The following steps are recommended for calibration:

    1. Collect online requests and measure the distribution of prefix reuse lengths.
    2. Set an acceptable recomputation overhead threshold, such as a latency budget for a single recomputation.
    3. Run a grid search over several candidate block sizes, comparing first-token latency, throughput, and memory usage.
    4. Choose the block size that meets the threshold and has the highest throughput, and review it periodically after traffic changes.

    Common Mistakes in Agent Multi-Turn Caching

    • Looking only at average throughput and ignoring tail latency. A small number of long-context requests may slow down the overall experience.
    • Including only a text hash in the cache key, without the prompt template, system prompt, and tool definitions. After the prompt changes, old states may be incorrectly hit.
    • Treating offload as a free operation. When offloading to NVMe, I/O bandwidth may become a bottleneck, and prefetch without sufficient lead time can still increase waiting.
    • Skipping accuracy validation and going directly to quantization, only to discover quality degradation after launch.
    • Having no fallback path. When caching fails, the system should be able to bypass the cache and ensure correct results.