用对比反馈提升大模型生成代码的效率,无需微调。
EffiPair: Improving the Efficiency of LLM-generated Code with Relative Contrastive Feedback
- 生成多组相似代码,对比效率差异提供优化指引
- 相比无反馈生成快1.5倍,令牌使用减少90%以上
- 适合需要高效代码但不想改模型的研究者
大语言模型生成的代码虽功能正确,但运行效率和内存占用常不理想。以往方法依赖单个程序的绝对执行反馈(如性能分析),成本高且指导性弱。本文提出相对对比反馈(RCF),一种无需模型微调或参数更新的推理时反馈机制。RCF通过比较同一任务下结构相似的两个程序,突出体现更优效率的差异部分。基于此,我们构建了EffiPair:一个完全在测试阶段运行的迭代优化框架。该框架生成多个候选解,识别效率差距大的程序对,将执行差异总结为轻量级反馈信号,并利用该信号生成更高效的代码。相比孤立的标量反馈,成对对比提供更直接的指导,同时降低性能分析与提示开销。在代码效率基准测试中,EffiPair持续提升效率并保持正确性。例如,使用DeepSeek-Chat V3.2时,相比无反馈生成,最大提速1.5倍,且相比先前方法令牌消耗减少超90%。
原文摘要 · Abstract (English)
Large language models (LLMs) often generate code that is functionally correct but inefficient in runtime and memory. Prior approaches to improving code efficiency typically rely on absolute execution feedback, such as profiling a single program's runtime or memory usage, which is costly and provides weak guidance for refinement. We propose Relative Contrastive Feedback (RCF), an inference-time feedback mechanism that requires no model fine-tuning or parameter updates. RCF compares two structurally similar programs for the same task and highlights the differences associated with better efficiency. Building on this idea, we introduce EffiPair, an inference-time iterative refinement framework that operates entirely at test time by generating multiple candidate solutions, identifying informative program pairs with large efficiency gaps, summarizing their execution differences into lightweight feedback, and using this signal to produce more efficient solutions. By replacing isolated scalar feedback with pairwise contrastive comparisons, EffiPair provides more direct guidance while reducing profiling and prompting overhead. Experiments on code-efficiency benchmarks show that EffiPair consistently improves efficiency while preserving correctness. For instance, with DeepSeek-Chat V3.2, EffiPair achieves up to 1.5x speedup over generation without performance feedback, while reducing token usage by more than 90% compared to prior work.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。