用语义优化修复大模型代码生成错误,精准定位并修复问题神经元。
A Semantic-based Optimization Approach for Repairing LLMs: Case Study on Code Generation
- 基于语义分析的优化方法,通过解析神经元变化与输出差异的关系来定位缺陷神经元。
- 在多个代码生成任务中表现优于现有最优方法,修复效率更高且副作用更小。
- 适合资源有限或安全要求高的场景,尤其适合需要高精度修复的工业级应用。
语言模型(LMs)广泛用于软件工程中的代码生成,但可能产生错误代码。与其修复输出,不如从根本上解决模型缺陷。模型修复是一种轻量级方案:数据需求少、计算成本低、副作用可控。不同于完整重训练,模型修复聚焦于对特定神经元进行定制化更新,适用于资源受限、高性能或严格安全要求的场景。本文提出一种新型语义驱动的优化修复方法——语义目标分析修复(STAR)。STAR将模型修复的核心操作(如定位‘故障神经元’、求解‘神经元修补’、实施‘修补’)统一为一个优化过程。其神经元修补通过稳健的语义分析公式计算,直接连接神经元变化与输出逻辑值(logits)的差异,通过引导隐状态实现。相比先前的模型修复方法(MINT)和标准优化方法(SGD),STAR融合两者优势并缓解其局限性。通过将模型修复重构为优化问题,STAR可同时解决多个故障,显著提升实用性。在主流代码生成模型上的编码任务评估表明,STAR在效果上优于当前最先进水平,且具有更高的效率。在副作用方面(即泛化与特异性之间的平衡),其表现远超已有工作。此外,我们评估了模型修复的过拟合风险及累积影响,并分析了与流水线式方法的差异,解释了为何STAR更优及其如何克服模型修复的常见瓶颈。
原文摘要 · Abstract (English)
Language Models (LMs) are widely used in software engineering for code generation, but they may produce erroneous code. Rather than repairing outputs, a more thorough remedy is to address underlying model failures. LM repair offers a lightweight solution: it requires minimal data, lowers computational cost, and limits side effects. Unlike full retraining, LM repair focuses on applying tailored updates to targeted neurons, making it suitable for limited resources, high-performance demands, or strict safety requirements. In this paper, we propose Semantic Targeting for Analytical Repair (STAR), a novel semantic-based optimization method for repairing LLMs. STAR realizes the main operations of repairing LMs in an optimization process, including locating ``buggy neurons'', solving ``neuron patches'', and patching ``buggy neurons''. The neuron patches are computed with a solid semantic-based analytical formula, which directly bridges the changes to logits with the deltas of neurons, by steering latent representations. Compared to the prior work of LM repair (MINT) and standard optimization methods (SGD), STAR integrates their strengths while mitigating their limitations. By reformulating LM repair as an optimization process, STAR may solve multiple failures together, significantly improving the usefulness. Evaluated on coding tasks using popular code LMs, STAR demonstrates superior effectiveness compared with the state-of-the-art. Besides, STAR exhibits better efficiency. In terms of side effects, namely the balance between generalization and specificity, STAR outperforms prior work by a significant margin. Additionally, we conducted assessments on the overfitting risk of LM repair as well as the cumulative impact. Further, we analyzed the differences with pipeline-based methods and explained the reason why STAR is better and how it mitigated the common limitations of LM repair.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。