Program synthesis—the automated generation of code from user intent—has long been a "holy grail" of computer science. While large language models (LLMs) like OpenAI’s Codex have shown impressive capabilities in translating natural language into executable code, their closed-source nature limits the broader research community's ability to study, audit, or build upon them. Furthermore, generating complex programs from a single, monolithic prompt remains a significant challenge due to the vast search space of programming languages and the difficulty of unambiguously specifying complex logic.
To address these hurdles, Salesforce Research introduced CodeGen, a family of open-source large language models (up to 16.1B parameters). Beyond simply scaling up model size, the researchers introduce a novel multi-turn program synthesis paradigm. They demonstrate that breaking complex coding tasks into a conversational dialogue significantly improves the model's success rate compared to traditional single-prompt approaches.
Training Curriculum and Methods
The authors trained a family of autoregressive transformers ranging from 350 million to 16.1 billion parameters. To scale this efficiently, they developed and open-sourced JAXFORMER, a library optimized for training on Google’s TPU-v4 hardware.
The models were trained using a sequential curriculum:
- CodeGen-NL: Initially trained on The Pile, an 825 GiB English text corpus, for general language understanding.
- CodeGen-Multi: Initialized from the NL model and trained on BigQuery, a massive corpus of multiple programming languages (C, C++, Go, Java, JavaScript, Python).
- CodeGen-Mono: Further fine-tuned specifically on BigPython, a curated dataset of permissively licensed Python code from GitHub.
The Multi-Turn Paradigm
The most novel methodological contribution is the shift from single-turn to multi-turn program synthesis. Instead of asking the model to write a complex function all at once, the user provides specifications progressively. The model generates a subprogram, and the user then provides the next instruction, building the final program step-by-step.
By factorizing the problem, the search space is drastically reduced. Focusing on one sub-problem at a time helps the model avoid the arduous task of tracking complex dependencies across a long, single prompt. To evaluate this, the authors introduced the Multi-Turn Programming Benchmark (MTPB), consisting of 115 diverse problems (math, data science, algorithms) factorized into multi-step prompts.
Key Insights and Results
- Competitive with State-of-the-Art: The 16.1B CodeGen-Mono model is highly competitive with the original OpenAI Codex on the standard HumanEval benchmark. As model size increases from 350M to 16.1B, performance consistently improves, confirming that code generation follows established scaling laws.
- Multi-Turn Superiority: On the MTPB benchmark, providing the same intent in a multi-turn fashion improved the pass rate by over 10 percentage points across almost all model sizes compared to a single-turn prompt.
- Emergence via Scaling: The ability to synthesize code isn't explicitly taught; it "emerges" from next-token prediction on large datasets. The authors hypothesize that because programmers often interleave comments with code, the model learns to associate natural language intent with functional logic.
- Perplexity as a Proxy: The researchers found that "pass" problems (where the model succeeds) have significantly lower perplexity than "non-pass" problems. This suggests that if a model "understands" the prompt (finds it predictable), it is much more likely to generate correct code.
Limitations and Future Work
While CodeGen represents a significant step forward for open-source program synthesis, challenges remain. The models rely on the "weak signal" of interleaved comments and code found on GitHub; if comments are inaccurate or poorly placed, the model's performance suffers. Interestingly, the authors also noted that the largest models (16.1B) can sometimes become too literal, failing on simple tasks because they over-interpret specific keywords in the prompt (e.g., seeing the word "return" and assuming they must define a function even when an executable script was requested).
Future research directions include exploring how models can better handle long-term dependencies in multi-turn dialogues and refining the "noisy" supervision found in public code repositories.
The CodeGen checkpoints and the JAXFORMER library are available as an open-source contribution at https://github.com/salesforce/CodeGen.
Summary updated