As large language models (LLMs) take on complex tasks, their inputs are supplemented with longer contexts that incorporate domain knowledge or user-specific information. Yet using long contexts poses a challenge for responsive LLM systems, as nothing can be generated until the whole context is processed by the LLM. . CacheGen is a fast context-loading module for LLM systems. First, CacheGen uses a custom tensor encoder, which embraces KV cache's distributional properties, to encode a KV cache into more compact bitstream representations with negligible encoding/decoding overhead. This reduces the bandwidth demand to fetch the KV cache. Second, to maintain low context-loading delay and high generation quality, CacheGen adapts the streaming strategies to cope with changes in available bandwidth. When available bandwidth drops, CacheGen may raise the compression level for a part of the context or choose to recompute its KV cache on the fly. We test CacheGen on four popular LLMs of various sizes and four datasets (662 contexts in total). Compared to the recent systems that reuse the KV cache, CacheGen reduces the KV cache size by 3.5-4.3x and the total delay in fetching and processing contexts by 3.2-3.7x while having negligible impact on the LLM response quality in accuracy or perplexity.
翻译:随着大语言模型(LLMs)承担复杂任务,其输入会补充更长的上下文,以融入领域知识或用户特定信息。然而,使用长上下文对响应式LLM系统构成挑战,因为LLM必须处理完整个上下文后才能生成任何内容。CacheGen是一种专为LLM系统设计的快速上下文加载模块。首先,CacheGen利用自定义张量编码器,该编码器契合KV缓存的分布特性,将KV缓存编码为更紧凑的比特流表示形式,且编码/解码开销可忽略不计。这降低了对KV缓存的带宽需求。其次,为保持低上下文加载延迟和高生成质量,CacheGen自适应调整流式传输策略以应对可用带宽的变化。当可用带宽下降时,CacheGen可对部分上下文提高压缩级别,或选择实时重新计算其KV缓存。我们在四种不同规模的主流LLM和四个数据集(共662个上下文)上测试了CacheGen。与近期重用KV缓存的系统相比,CacheGen将KV缓存大小降低3.5-4.3倍,将获取和处理上下文的总体延迟降低3.2-3.7倍,同时对LLM在准确率或困惑度方面的响应质量产生可忽略的影响。