We propose the In-context Autoencoder (ICAE) for context compression in a large language model (LLM). The ICAE has two modules: a learnable encoder adapted with LoRA from an LLM for compressing a long context into a limited number of memory slots, and a fixed decoder which is the target LLM that can condition on the memory slots for various purposes. We first pretrain the ICAE using both autoencoding and language modeling objectives on massive text data, enabling it to generate memory slots that accurately and comprehensively represent the original context. Then, we fine-tune the pretrained ICAE on a small amount of instruct data to enhance its interaction with various prompts for producing desirable responses. Our experimental results demonstrate that the ICAE learned with our proposed pretraining and fine-tuning paradigm can effectively produce memory slots with $4\times$ context compression, which can be well conditioned on by the target LLM to respond to various prompts. The promising results demonstrate significant implications of the ICAE for its novel approach to the long context problem and its potential to reduce computation and memory overheads for LLM inference in practice, suggesting further research effort in context management for an LLM. Our code and data will be released shortly.
翻译:我们提出上下文自编码器(ICAE)用于大型语言模型(LLM)中的上下文压缩。ICAE包含两个模块:一个可学习的编码器,通过LoRA从LLM中适配,用于将长上下文压缩为有限数量的记忆槽;以及一个固定的解码器,即目标LLM,它可以根据记忆槽进行各种任务。我们首先在大规模文本数据上,使用自编码和语言建模目标对ICAE进行预训练,使其能够生成准确且全面表示原始上下文的记忆槽。随后,我们在少量指令数据上微调预训练的ICAE,以增强其与各种提示的交互能力,从而生成理想的响应。实验结果表明,通过我们提出的预训练和微调范式学习的ICAE,能够有效生成具有4倍上下文压缩的记忆槽,且目标LLM可以很好地基于这些记忆槽对各种提示做出响应。这些令人鼓舞的结果展示了ICAE在解决长上下文问题方面的创新方法及其在实践中有望减少LLM推理时的计算和内存开销,从而推动了对LLM上下文管理的进一步研究。我们的代码和数据将很快发布。