Why Long Context Decoding Slows Down: Bandwidth vs. Sparse Reading Trade-offs

    Long context decoding is often incorrectly blamed on insufficient compute. This article analyzes the true bottleneck—memory bandwidth—and explores why batching and prefix caching offer limited relief. It further examines the trade-offs between block-level and token-level sparse attention, introduces a conceptual joint subspace sparse attention mechanism, and provides engineering guidelines and measurement criteria for optimizing long-context inference.

    First, Determine if the Bottleneck is Memory Access

    Slow decoding for long contexts is often attributed to insufficient compute power. However, this assumption is only valid for certain scenarios. Before concluding, three factors must be verified: whether full attention is used, the batch size and context length, and the kernel’s efficiency in reading the KV cache.

    During decoding, generating each token requires every layer and KV head to read all K and V tensors from the beginning of the sequence to the current position. Take Llama-2-7B as an example: it does not use Grouped-Query Attention (GQA) and has 32 layers, 32 KV heads, and a head dimension of 128. When stored in FP16, the KV cache per token is 2 × 32 × 128 × 32 × 2 bytes, or 512 KiB. At a context length of 128K, the KV cache for a single request is about 64 GiB. On an 80 GB GPU, adding about 13 GB of FP16 weights, the memory is near or exceeds capacity.

    The compute intensity here is very low. According to public specs for the NVIDIA H100 SXM, the BF16 dense compute is about 989 TFLOPS and memory bandwidth is about 3.35 TB/s, yielding a ratio of about 300 FLOP/byte. A single query head reading one FP16 element performs only one multiply-add, resulting in a compute intensity of about 1 to 2 FLOP/byte. There is a two-order-of-magnitude difference between the two, meaning single-request full attention decoding is almost always bandwidth-bound.

    This conclusion has boundaries. GQA allows a group of query heads to share a single KV head, increasing compute intensity with group size. Speculative decoding or processing multiple queries simultaneously also increases intensity. Therefore, the specific model architecture and decoding mode must be evaluated.

    Why Batching Cannot Amortize KV Reads

    Batched decoding can amortize the reading of model weights because the same set of weights can serve all requests in the batch. The KV cache is different. Each request typically holds its own KV cache, so when the batch size increases from 1 to 32, weight reads are amortized, but each request still reads its entire history. The total KV read volume scales almost linearly with the batch size.

    Prefix caching allows multiple requests to share KV blocks with identical prefixes. This saves memory capacity. Whether the read volume decreases depends on the kernel implementation. If each request still independently reads the shared blocks, the bandwidth pressure remains unchanged. Only if the kernel supports reading the shared prefix once and serving multiple queries will the read volume drop. Some inference engines provide shared prefix attention implementations; its support scope should be verified before use.

    Read Costs of Block-level vs. Token-level Sparsity

    The idea behind sparse attention is to read only the history relevant to the current query. The difficulty lies in two questions: how to select, and how to read after selection.

    Block-level methods pack several consecutive tokens into a block, score the entire block using a block summary, and retain only the highest-scoring blocks. For instance, public methods like Quest save the minimum and maximum values of the key vectors for each page to estimate the highest attention score for that page. Because summaries are stored contiguously, read efficiency is high. The trade-off is that irrelevant tokens within the same block are read entirely, and selection precision is limited by block granularity.

    Token-level methods score each token individually and keep the top-scoring positions. This offers higher precision but comes with two extra overheads. First, scoring all tokens requires reading all K tensors unless a cheap estimator is used. Second, selected positions are non-contiguous in memory, requiring indexing and gather operations before reading, and the indices themselves consume storage and bandwidth.

    The table below summarizes the differences between the two methods.

    Dimension Block-level Sparse Token-level Sparse
    Selection granularity Fixed-size contiguous blocks Individual tokens
    Reads required for scoring Block summary, roughly 1/block_size of full K Requires reading full K for per-token scoring
    Read pattern Contiguous memory, fewer access transactions Discrete positions, requires gather
    Extra storage Summary vectors per block Index list per step
    Primary risk Irrelevant tokens in block are read entirely Index and gather overheads offset gains

    The scoring read volume for block-level methods is only about 1/block_size of the full K, which is why it is fast. The advantage of token-level methods lies in precision. The trade-off is that coarse granularity reads faster, while fine granularity selects more accurately.

    Mechanism of Joint Subspace Sparse Attention

    The original text uses the term “Joint Subspace Sparse Attention,” which this article adopts to refer to the combined mechanism described below. This is a conceptual summary and does not correspond to a confirmed paper or open-source implementation; its source should be verified before citation.

    This mechanism involves the following steps:

    1. Low-dimensional scoring: Perform Principal Component Analysis (PCA) or Singular Value Decomposition (SVD) on the key vectors for each layer and KV head, taking the top r directions as the subspace basis. During decoding, project the query and keys into the r-dimensional space for scoring. This step only reads a proportion of r/d of the key data. For example, with head dimension d = 128 and r = 32, the read volume is about 25% of the full keys.
    2. Block scoring: Aggregate the subspace scores of tokens within a block into a block score, such as a weighted sum of the block’s maximum and mean values.
    3. Budget allocation: Given a token budget T and block size b, select the top T/b scoring blocks.
    4. Intensive reading: Read the full-dimension K and V only for the selected blocks and perform standard attention.
    5. Index compression: Selected results are represented by block numbers. Each head only needs to save T/b integers per step, rather than a per-token position list.

    Steps 1 and 3 use the same scores, so there is no need to maintain two separate indices for “which blocks to select” and “what intensity to use within the block.” This is the source of the mechanism’s ability to eliminate index overhead.

    Taking context length N = 131072, r/d = 0.25, and T = 4096 as an example, the estimated total read volume is as follows. Dense attention requires reading N Ks and N Vs, totaling 2N units. The sparse scheme reads 0.25N K units for scoring, and T Ks and T Vs for intensive reading, totaling 2T units. The total is 0.25 × 131072 + 2 × 4096 = 40960 units, about 16% of the dense read volume. This is a theoretical estimate; actual gains require real-world testing and must account for summary and index storage.

    Additionally, two common mandatory selections should be retained. First is a small number of “sink tokens” at the beginning, typically the first few tokens in practice. Second is a recent local window to ensure local context integrity. These can either be excluded from or included in the dynamic selection budget, which should be determined experimentally.

    Attention entropy can be used to assist in budget allocation. The more concentrated the estimated attention distribution, the more the information within a block is concentrated in a few positions, making it more worthwhile for intensive reading. High-entropy blocks can retain only summaries. The computation required to estimate entropy is on the same order of magnitude as subspace scoring. This heuristic rule must be validated on the target task and should not be assumed effective directly.

    Engineering Trade-offs and Parameter Starting Points

    Block size is the most critical parameter. Larger blocks mean fewer summaries and more contiguous reads, but more irrelevant tokens mixed within the block, reducing precision. Smaller blocks mean finer selection, but summary storage and index overheads increase.

    Summary storage can be estimated. Each block saves two vectors, minimum and maximum, each of length d, stored in FP16. With N = 131072 and d = 128, at a block size of 16, the summary per head per layer is about 4 MiB. For a model with 32 layers and 32 heads, this totals about 4 GiB, roughly 6% of the 64 GiB KV cache. At a block size of 64, the summary is about 1.6% of the KV cache. Summary usage is inversely proportional to block size, with its ratio relative to K and V being about 1/b.

    The table below provides starting parameters, for experimental setup reference only and not representing any benchmark results.

    Scenario Block size Token budget T Subspace rank r Precision risk Latency characteristics
    Ultra-long document QA, needs locating scattered details 16 4K to 8K 32 to 64 Lower Higher summary and index overhead
    General long-context tasks 32 2K to 4K 32 Medium Compromise between the two
    Streaming dialogue, latency priority 64 1K to 2K 16 to 32 Higher Contiguous reads, lower latency

    The principles for selecting these values are as follows. A block size between 16 and 64 is common; outside this range, summary quality or read efficiency usually degrades noticeably. The budget T should adjust with context length but should not grow linearly with N, otherwise the sparse benefits disappear. The rank r determines scoring precision; a curve of precision vs. r should be plotted on the target model to find the elbow point.

    Aligning block boundaries with prefix caching is also crucial. If block boundaries do not match cache block boundaries, shared prefixes may not be hit as full blocks, leading to redundant computation. Therefore, the block size should ideally be a multiple of the cache block size, or identical to it.

    Measurement Criteria

    Before comparing sparse schemes, measurement conditions must be fixed, otherwise results are incomparable.

    1. Baseline: Use full attention decoding with the same model, batch size, and output length as a control.
    2. Latency: Report the average time per output token (TPOT), and provide the P50 and P90 statistics.