arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2510.00446cs.CLcs.SE
收藏

LongCodeZip: 为代码语言模型压缩长上下文

LongCodeZip: Compress Long Context for Code Language Models

Shanghai Jiao Tong University(上海交通大学);Stanford University(斯坦福大学);Chongqing University(重庆大学)

Yuling Shi, Yichun Qian, Hongyu Zhang, Beijun Shen, Xiaodong Gu

AI总结:

针对长上下文代码生成成本高、延迟大且现有通用压缩技术忽略代码结构的问题,提出即插即用的两阶段代码压缩框架LongCodeZip,在多任务上实现最高5.6倍压缩比且不降低性能,助力LLM适配大规模代码场景。

摘要:

随着大型语言模型(LLM)需要基于代码库中的大量信息进行推理,长上下文下的代码生成正变得愈发关键。尽管近期的进展让代码LLM能够处理长输入,但高昂的API成本和生成延迟仍是显著瓶颈。现有的上下文剪枝技术(如LLMLingua)在通用文本上取得了不错的效果,但忽略了代码特有的结构与依赖关系,导致在编程任务中表现欠佳。本文提出LongCodeZip——一款专为代码LLM设计的新型即插即用代码压缩框架。LongCodeZip采用两阶段策略:(1)粗粒度压缩:利用相对于指令的条件困惑度对函数级块进行识别和排序,仅保留相关性最高的函数;(2)细粒度压缩:基于困惑度将保留的函数分割为块,并在自适应token预算下选择最优子集以最大化相关性。在代码补全、摘要生成和问答等多个任务上的评估表明,LongCodeZip的表现始终优于基线方法,在不降低任务性能的前提下实现了最高5.6倍的压缩比。通过在保留关键信息的同时有效缩减上下文规模,LongCodeZip让LLM能更好地适配真实世界的大规模代码场景,提升了代码智能应用的效率与能力。

英文摘要:

Code generation under long contexts is becoming increasingly critical as Large Language Models (LLMs) are required to reason over extensive information in the codebase. While recent advances enable code LLMs to process long inputs, high API costs and generation latency remain substantial bottlenecks. Existing context pruning techniques, such as LLMLingua, achieve promising results for general text but overlook code-specific structures and dependencies, leading to suboptimal performance in programming tasks. In this paper, we propose LongCodeZip, a novel plug-and-play code compression framework designed specifically for code LLMs. LongCodeZip employs a dual-stage strategy: (1) coarse-grained compression, which identifies and ranks function-level chunks using conditional perplexity with respect to the instruction, retaining only the most relevant functions; and (2) fine-grained compression, which segments retained functions into blocks based on perplexity and selects an optimal subset under an adaptive token budget to maximize relevance. Evaluations across multiple tasks, including code completion, summarization, and question answering, show that LongCodeZip consistently outperforms baseline methods, achieving up to a 5.6x compression ratio without degrading task performance. By effectively reducing context size while preserving essential information, LongCodeZip enables LLMs to better scale to real-world, large-scale code scenarios, advancing the efficiency and capability of code intelligence applications.

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

↑