LongCodeZip: コード言語モデルのための長文脈圧縮
LongCodeZip: Compress Long Context for Code Language Models
October 1, 2025
著者: Yuling Shi, Yichun Qian, Hongyu Zhang, Beijun Shen, Xiaodong Gu
cs.AI
要旨
長文脈下でのコード生成は、大規模言語モデル(LLMs)がコードベース内の広範な情報を推論する必要があるため、ますます重要になっています。最近の進歩により、コードLLMが長い入力を処理できるようになりましたが、高いAPIコストと生成遅延は依然として大きなボトルネックです。既存の文脈プルーニング技術(例:LLMLingua)は、一般的なテキストでは有望な結果を達成していますが、コード固有の構造や依存関係を見落としており、プログラミングタスクでは最適な性能を発揮できません。本論文では、コードLLMに特化した新しいプラグアンドプレイ型コード圧縮フレームワークであるLongCodeZipを提案します。LongCodeZipは、二段階の戦略を採用しています:(1)粗粒度圧縮では、命令に対する条件付きパープレキシティを使用して関数レベルのチャンクを識別し、ランク付けし、最も関連性の高い関数のみを保持します;(2)細粒度圧縮では、保持された関数をパープレキシティに基づいてブロックに分割し、適応的なトークン予算の下で最適なサブセットを選択して関連性を最大化します。コード補完、要約、質問応答を含む複数のタスクでの評価により、LongCodeZipはベースライン手法を一貫して上回り、タスク性能を低下させることなく最大5.6倍の圧縮率を達成することが示されました。LongCodeZipは、必要な情報を保持しながらコンテキストサイズを効果的に削減することで、LLMが現実世界の大規模なコードシナリオに適応できるようにし、コードインテリジェンスアプリケーションの効率と能力を向上させます。
English
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.