Fast State Restoration in LLM Serving with HCache

Shiwei Gao,Youmin Chen,Jiwu Shu
2024-10-07
Abstract:The growing complexity of LLM usage today, e.g., multi-round conversation and retrieval-augmented generation (RAG), makes contextual states (i.e., KV cache) reusable across user requests. Given the capacity constraints of GPU memory, only a limited number of contexts can be cached on GPU for reusing. Existing inference systems typically evict part of the KV cache and restore it by recomputing it from the original tokens or offloading it to host storage for later retrieval, both of which introduce substantial computational or I/O overheads. We propose HCache, a novel LLM state restoration method. Its key idea is to restore LLM states from intermediate activations and thus utilize computational and I/O resources with low overhead. We enhance HCache with two techniques, including i) a bubble-free restoration scheduler that integrates resource-complementary methods to optimize the balance between computation and IO tasks; and ii) a chunk-based storage manager to address the layout mismatch issue (i.e., layer-before-token saving versus token-before-layer restoration). Our evaluations, conducted using real-world tasks, show that HCache reduces the TTFT by up to 1.93X compared to KV offload while consuming 1.92-2.40X less storage space; compared to token recomputation, HCache achieves up to 5.73X reduction in TTFT.
Distributed, Parallel, and Cluster Computing
What problem does this paper attempt to address?
The problem that this paper attempts to solve is that in large - language - model (LLM) services, due to the limitation of GPU memory capacity, the historical context states (i.e., KV caches) cannot be all stored on the GPU. As a result, when processing new user requests, these states need to be restored from host storage, causing significant computational or I/O overheads. Specifically, existing inference systems usually restore states through two methods: one is recomputation, that is, regenerating KV caches from the original tokens; the other is KV offload, that is, saving KV caches to host storage and reloading them into GPU memory when needed. Both of these methods have obvious performance degradation problems. The former has high computational complexity, and the latter has a large I/O transfer volume. To overcome these problems, the paper proposes HCache, a new LLM state - restoration method. The core idea of HCache is to restore LLM states from intermediate activations (i.e., hidden states), thereby utilizing computational and I/O resources to achieve state restoration with lower overheads. The paper enhances HCache through the following two key techniques: 1. **Bubble - Free Restoration Scheduler**: This scheduler combines resource - complementary methods to optimize the balance between computational and I/O tasks, eliminate bubbles in the pipeline, and improve the restoration speed. 2. **Chunk - Based Storage Manager**: This manager solves the problem of storage - layout mismatch, that is, the inconsistency between saving layers before tokens and restoring tokens before layers, thereby optimizing the storage format and reducing state - restoration time. Through these techniques, HCache performs excellently on mainstream platforms, significantly reducing the time - to - first - token (TTFT) and storage - space consumption, and has a significant performance improvement compared with existing methods (such as KV offload and token recomputation).