# CodeGen2: Lessons for Training LLMs on Programming and Natural Languages

Source: [CodeGen2: Lessons for Training LLMs on Programming and Natural Languages](<https://www.sota2.com/research/paper/68fa700c1e209131cea48daa>)

Collection index: [llms.txt](<https://www.sota2.com/research/llms.txt>)

Data updated: 2025-10-26T01:32:16.690Z

Authors: Erik Nijkamp, Hiroaki Hayashi, Caiming Xiong, Silvio Savarese, Yingbo Zhou

Published: 2023-05-03T17:55:25.000Z

## Abstract

Large language models (LLMs) have demonstrated remarkable abilities in representation learning for program synthesis and understanding tasks. The quality of the learned representations appears to be dictated by the neural scaling laws as a function of the number of model parameters and observations, while imposing upper bounds on the model performance by the amount of available data and compute, which is costly.   In this study, we attempt to render the training of LLMs for program synthesis more efficient by unifying four key components: (1) model architectures, (2) learning methods, (3) infill sampling, and, (4) data distributions. Specifically, for the model architecture, we attempt to unify encoder and decoder-based models into a single prefix-LM. For learning methods, (i) causal language modeling, (ii) span corruption, (iii) infilling are unified into a simple learning algorithm. For infill sampling, we explore the claim of a "free lunch" hypothesis. For data distributions, the effect of a mixture distribution and multi-epoch training of programming and natural languages on model performance is explored.   We conduct a comprehensive series of empirical experiments on 1B LLMs, for which failures and successes of this exploration are distilled into five lessons. We will provide a final recipe for training and release CodeGen2 models in size 1B, 3.7B, 7B, and, 16B parameters, along with the training framework as open-source: https://github.com/salesforce/CodeGen.

## Recorded benchmark results

A research result applies to its stated dataset, split, metric and evaluation configuration. Compare like-for-like settings, preserve the metric's unit and direction, and distinguish paper-reported results from independent reproduction. The best result recorded here is not a claim of exhaustive, current global coverage.

- [Vulnerability Detection on BigVul (val)](<https://www.sota2.com/research/sota/vulnerability-detection-on-bigvul-val.md>): Vulnerability Detection; BigVul (val); Accuracy: 96.6.

- [Paired Vulnerability Detection on PRIMEVUL paired (val)](<https://www.sota2.com/research/sota/paired-vulnerability-detection-on-primevul-paired-val.md>): Paired Vulnerability Detection; PRIMEVUL paired (val); P-C: 3.01.

- [Vulnerability Detection on PRIMEVUL (val)](<https://www.sota2.com/research/sota/vulnerability-detection-on-primevul-val.md>): Vulnerability Detection; PRIMEVUL (val); Accuracy: 96.7.

- [Vulnerability Detection on PrimeVul Paired (full)](<https://www.sota2.com/research/sota/vulnerability-detection-on-primevul-paired-full.md>): Vulnerability Detection; PrimeVul Paired (full); PC Score: 3.01.

## Original sources and implementation

[Original paper](<https://arxiv.org/abs/2305.02309>)

[PDF](<https://arxiv.org/pdf/2305.02309.pdf>)
