arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2603.04428cs.LGcs.AI
收藏

代理记忆低于提示:持久化Q4 KV缓存用于边缘设备上的多代理LLM推理

Agent Memory Below the Prompt: Persistent Q4 KV Cache for Multi-Agent LLM Inference on Edge Devices

Yakov Pyotr Shkolnikov

AI总结:

本文提出了一种持久化Q4 KV缓存的方法,用于在边缘设备上提高多代理LLM推理效率,通过减少缓存恢复时间,提升模型性能。

摘要:

在边缘设备上运行的多代理LLM系统面临内存管理问题:设备的RAM太小,无法同时容纳每个代理的KV缓存。在Apple M4 Pro上,拥有10.2GB的缓存预算时,仅能同时容纳3个代理在8K上下文长度的FP16环境下。一个10个代理的工作流程必须不断驱逐和重新加载缓存。如果没有持久化,每次驱逐都会迫使模型进行完整的重新填充,4K上下文长度的每个代理需要15.7秒。我们通过将每个代理的KV缓存持久化到磁盘,以4位量化格式存储,并直接加载到注意力层中,从而消除通过直接缓存恢复而产生的冗余O(n)预填充计算。该系统由三个组件组成:一个块池,提供安全张量格式的每个代理隔离的Q4 KV缓存;一个BatchQuantizedKVCache,用于在多个代理的量化缓存上进行并发推理;以及跨阶段的上下文注入,它在对话阶段之间积累注意力状态,而无需重新计算。在三个架构(Gemma 3 12B,密集GQA,48层;DeepSeek-Coder-V2-Lite 16B,MoE MLA,27层;Llama 3.1 8B,密集GQA,32层)上进行评估,缓存恢复将时间到第一个标记的时间减少高达136倍(Gemma:在4K-32K上下文长度上为22-136倍;DeepSeek:在4K-32K上下文长度上为11-76倍;Llama:在4K-16K上下文长度上为24-111倍;在1K上下文长度上为3-10倍)。Q4量化在固定设备内存中可以容纳四倍于FP16的代理上下文。使用实际的Q4 KV缓存测量的困惑度显示,Gemma为-0.7%,Llama为+2.8%,DeepSeek为+3.0%。开源地址为https://github.com/yshk-mxim/agent-memory

英文摘要:

Multi-agent LLM systems on edge devices face a memory management problem: device RAM is too small to hold every agent's KV cache simultaneously. On Apple M4 Pro with 10.2 GB of cache budget, only 3 agents fit at 8K context in FP16. A 10-agent workflow must constantly evict and reload caches. Without persistence, every eviction forces a full re-prefill through the model -- 15.7 seconds per agent at 4K context. We address this by persisting each agent's KV cache to disk in 4-bit quantized format and reloading it directly into the attention layer, eliminating redundant O(n) prefill computation via direct cache restoration. The system comprises three components: a block pool providing per-agent isolated Q4 KV caches in safetensors format, a BatchQuantizedKVCache for concurrent inference over multiple agents' quantized caches, and cross-phase context injection that accumulates attention state across conversation phases without re-computation. Evaluated on three architectures (Gemma 3 12B, dense GQA, 48 layers; DeepSeek-Coder-V2-Lite 16B, MoE MLA, 27 layers; Llama 3.1 8B, dense GQA, 32 layers), cache restoration reduces time-to-first-token by up to 136x (Gemma: 22--136x at 4K--32K; DeepSeek: 11--76x at 4K--32K; Llama: 24--111x at 4K--16K; 3--10x at 1K). Q4 quantization fits 4x more agent contexts into fixed device memory than FP16. Perplexity measured with actual Q4 KV caches shows -0.7% for Gemma, +2.8% for Llama, and +3.0% for DeepSeek. Open-source at https://github.com/yshk-mxim/agent-memory

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑