atlas

Research map / Large language models / Instruction and fine-tuning

Instruction Tuning for Secure Code Generation

ICML 2024 · Large language models › Instruction and fine-tuning · approach: Instruction data selection · 3 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Proposes SafeCoder, a security-centric instruction tuning method that mixes a CodeQL-verified secure/insecure code dataset (collected automatically from GitHub commits) with standard instruction tuning, using masked likelihood and unlikelihood losses.

Problem

Instruction-tuned language models frequently generate insecure code, and existing instruction tuning schemes do not address code security while preserving utility.

Approach

Joint instruction tuning that combines standard NLL loss on general instruction data with a masked NLL loss on secure code and a masked unlikelihood loss on vulnerable code, with masks restricted to security-related tokens identified by difflib; security dataset built by an automated GitHub commit pipeline verified with CodeQL and GPT-4-generated instructions.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
add SafeCoder joint security tuningStarCoder-1B · Code security, 60 scenariossecure generations (%): 62.9 -> 92.1Helped
add SafeCoder joint security tuningStarCoder-3B · Code security, 60 scenariossecure generations (%): 68.3 -> 93.0Helped
add SafeCoder joint security tuningCodeLlama-7B · Code security, 60 scenariossecure generations (%): 66.6 -> 91.2Helped
add SafeCoder joint security tuningPhi-2-2.7B · Code security, 60 scenariossecure generations (%): 69.9 -> 90.9Helped
add SafeCoder joint security tuningLlama2-7B · Code security, 60 scenariossecure generations (%): 59.2 -> 89.2Helped
add SafeCoder joint security tuningMistral-7B · Code security, 60 scenariossecure generations (%): 63.1 -> 89.6Helped
add SafeCoder joint security tuninginstruction-tuned code models · HumanEvalPass@1: 20.4 -> 19.4; 30.7 -> 28.0; 36.8 -> 35.9Hurt
add SafeCoder joint security tuninggeneral-purpose instruction-tuned models · HumanEvalPass@1: 48.3 -> 46.1; 13.3 -> 11.8; 35.2 -> 33.7Hurt
remove the security dataset collected by the authors (use only the other security training data) (ablation)SafeCoder · Code securitysecure generations (%): about 20% less secureHurt
add security-token masks to the secure-code and unsafe-code losses (ablation)SafeCoder · Code securitysecure generations (%): about 10%Helped
add unlikelihood loss on insecure programs (ablation)SafeCoder on StarCoder-1B · Code securitysecure generations (%): 5.1%Helped
add unlikelihood loss on insecure programs (ablation)SafeCoder on Phi-2-2.7B · Code securitysecure generations (%): 10.6%Helped

Surprising findings

Limitations

Experimental setup

Datasets: Code Evol-Instruct (decontaminated, 33K) LMSYS-Chat-1M (18K subset) SVEN security dataset

Benchmarks: HumanEval MBPP MMLU TruthfulQA CodeQL-based security scenarios (60)

Metrics: secure code rate pass@1 pass@10

Baselines: SVEN standard instruction tuning (w/o SafeCoder) pretrained LM (n/a)

Builds on: SVEN unlikelihood training LoRA Code Evol-Instruct

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy