Reproduce “Teaching an Old LLM Secure Coding: Localized Preference Optimization on Distilled Preferences” on OpenResearch

Run Claude Code, Codex or any coding agent as a research agent: literature, hypotheses and experiments on your laptop, cluster or cloud GPUs.

Universal app for Apple silicon and Intel. Requires macOS 11 or later.

About this paper

Mohammad Saqib Hasan, Saikat Chakraborty, Santu Karmaker, Niranjan Balasubramanian

A method is developed to train large language models (LLMs) for generating secure code. It features DiSCo, a dataset of secure and insecure code preferences distilled with frontier LLMs and static analysis, and Localized Preference Optimization (LPO), an algorithm focusing training on security-relevant code differences. This approach enables smaller LLMs to produce code with substantially fewer vulnerabilities while improving overall code utility, surpassing the security performance of larger, general-purpose models.

Key insights

  • High-quality, specialized preference data for secure coding can be effectively distilled from powerful frontier LLMs and external security tools, overcoming the limitations of manual curation and noisy automatic extraction.
  • Focusing LLM alignment on localized, security-relevant code changes, rather than applying a uniform loss, is crucial for efficiently and effectively reducing code vulnerabilities.
  • Specialized data generation and a fine-grained, localized alignment strategy can enable smaller, resource-efficient LLMs to achieve superior secure coding performance compared to larger, general-purpose models.

Summary by alphaXiv.

Tip: change arxiv.org to autoarxiv.org in any arXiv abstract link to open the paper here.