用轻量微调提升代码大模型安全性,效果显著且通用。
A Systematic Evaluation of Parameter-Efficient Fine-Tuning Methods for the Security of Code LLMs
- 对比七种轻量微调法,发现提示调优最有效。
- 代码安全率最高达87.65%,每百万减少20多万漏洞代码。
- 对恶意攻击有更强防御力,适用于多语言开发场景。
生成代码的大语言模型虽大幅提升开发效率,但常产生不安全代码,带来严重风险。本文系统评估了七种参数高效微调(PEFT)技术,发现提示调优(prompt-tuning)在CodeGen2 16B上实现80.86%的整体安全率,较基线67.28%提升13.5个百分点;通过优化采样温度,安全率进一步提升至87.65%,相当于每百万生成代码减少约203,700个漏洞片段。该方法在TrojanPuzzle测试中对中毒攻击具更高鲁棒性,对CWE-79和CWE-502攻击向量表现良好。结果在Python与Java上均具一致性,为构建更可靠的软件系统提供了实用指导。
原文摘要 · Abstract (English)
Code-generating Large Language Models (LLMs) significantly accelerate software development. However, their frequent generation of insecure code presents serious risks. We present a comprehensive evaluation of seven parameter-efficient fine-tuning (PEFT) techniques, demonstrating substantial gains in secure code generation without compromising functionality. Our research identifies prompt-tuning as the most effective PEFT method, achieving an 80.86% Overall-Secure-Rate on CodeGen2 16B, a 13.5-point improvement over the 67.28% baseline. Optimizing decoding strategies through sampling temperature further elevated security to 87.65%. This equates to a reduction of approximately 203,700 vulnerable code snippets per million generated. Moreover, prompt and prefix tuning increase robustness against poisoning attacks in our TrojanPuzzle evaluation, with strong performance against CWE-79 and CWE-502 attack vectors. Our findings generalize across Python and Java, confirming prompt-tuning's consistent effectiveness. This study provides essential insights and practical guidance for building more resilient software systems with LLMs.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。