High-Throughput Memory Resident Strategies for LLM Inference: Keep Data in VRAM

    This article explains why memory bandwidth, not compute, limits throughput during the autoregressive decoding stage of large language model inference. It introduces the "data never leaves memory" principle and compares two practical residency strategies: keeping tensors resident until VRAM is full, and prefetching blocks so they remain available when needed. It also covers selection criteria, implementation details, and common pitfalls for achieving higher token generation rates under limited VRAM.

    1. The Bottleneck in Decoding Is Bandwidth, Not Compute

    In large language model inference, the prefill stage is compute-intensive. The autoregressive decoding stage, however, processes only one or a few tokens per step, resulting in very low arithmetic intensity. Performance is therefore almost entirely determined by memory bandwidth. A common industry observation is that the upper bound of decoding throughput is roughly equal to available memory bandwidth divided by the number of bytes that must be moved per step. If intermediate tensors are repeatedly written back and read from slower storage, precious bandwidth is wasted on data movement, leading to the typical pattern of idle compute and saturated bandwidth.

    The idea of “data never leaving memory” means keeping frequently reused tensors resident in high-bandwidth VRAM, avoiding round-trip transfers on the inference hot path. Two common strategies are used to achieve this.

    2. Strategy One: Do Not Evict Until VRAM Is Full

    The core logic is to make residency the default behavior: as long as the VRAM usage level has not reached its limit, data is never proactively swapped out to lower-tier storage.

    • Applicable scenarios: online services with predictable model and cache sizes and relatively stable concurrency.
    • Advantages: simple to implement, no prefetch scheduling overhead, and the shortest hit path.
    • Risks: burst traffic or long contexts can quickly raise the usage level; once the limit is reached, concentrated eviction occurs, causing tail latency jitter.

    In engineering practice, watermarks and a reserved area should be configured to make eviction a controlled event rather than a passive result:

    1. if used + incoming <= high_watermark:
    2. keep_resident() # Do not evict
    3. else:
    4. evict_by_policy() # LRU / reference counting / priority

    3. Strategy Two: Prefetch So Data Is Still There When Needed

    The second approach trades time for hit rate: blocks that will be used soon are moved into the high-bandwidth tier in advance, so the data has not yet been evicted when the application actually reads it, appearing as continuous hits.

    • The key is matching prefetch timing with residency duration: prefetching too early gets the data evicted, while prefetching too late leaves insufficient time.
    • A simple queuing model should be built based on decoding step size, block granularity, and bandwidth budget to estimate the time window between “move in” and “use.”
    • This strategy is more robust to bursts and long contexts, but requires an additional scheduler and hit rate monitoring.

    A minimal example of a prefetch decision:

    1. def should_prefetch(block, now):
    2. eta = estimate_arrival(block) # Estimated time when available
    3. ttl = estimate_resident_time(block) # Estimated residency duration
    4. return eta + transfer_cost <= next_use_time(block) < eta + ttl

    4. Comparison and Selection

    Dimension No Eviction Until Full Prefetch to Maintain Hits
    Implementation complexity Low Medium-high
    Steady-state throughput High High
    Burst resistance Weak Strong
    Additional overhead Almost none Scheduling and bandwidth usage
    Tuning focus Watermark Timing and granularity

    Practical recommendation: prioritize the first strategy for steady-state online services; for mixed workloads, long contexts, or multi-tenant environments, primarily use the second strategy while keeping the first as a watermark safety net.

    5. Implementation Points and Common Pitfalls

    1. Keep block granularity moderate: too fine increases scheduling overhead, while too coarse reduces hit flexibility.
    2. Use a unified memory pool: reduce fragmentation and implicit copies to make residency controllable and observable.
    3. Metrics first: continuously collect hit rate, eviction count, bytes moved per step, and tail latency, and use data to drive tuning.
    4. Avoid two pitfalls: treating cache hit rate as the sole goal while ignoring bandwidth budget; and blindly increasing the residency ratio, leading to insufficient available VRAM and frequent jitter.

    6. Conclusion

    The essence of high-throughput decoding is bandwidth management. “Data never leaving memory” provides the direction, while “no eviction until full” and “prefetch to maintain hits” provide two composable implementation paths. Combined with Baidu AI Cloud’s practices in general capabilities such as container platforms, monitoring and alerting, and log services, teams can incorporate watermarks, timing, and hit rate into a unified observability system, steadily approaching higher token generation rates under limited VRAM.