NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Enhancing Code LLMs with Reinforcement Learning in Code Generation: A Survey

Junqiao Wang, Zeng Zhang, Yangfan He, Zihao Zhang, Xinyuan Song, Yuyang Song, Tianyu Shi, Yuchen Li, Hengyuan Xu, Kunyu Wu, Yi Xin, Zhongwei Wan, Xinhang Yuan, Zijun Wang, Kuan Lu, Menghao Huo, Jingqun Tang, Guangwu Qian, Keqin Li, Qiuwu Chen, Lewei He · DOI · OpenReview

Introduction

Recent advancements in Large Language Models (LLMs) have significantly impacted the field of automated programming. However, standard training paradigms primarily rely on "Next Token Prediction," which often results in models acting as "stochastic parrots"—generating syntactically correct code that may lack functional logic or efficiency. Traditional metrics like BLEU or ROUGE, which measure textual similarity to a reference, fail to capture the essence of programming: execution and correctness.

To address these limitations, Reinforcement Learning (RL) has emerged as a transformative tool, shifting the focus from token-matching to functional problem-solving. By utilizing execution-based rewards, such as unit test results, RL allows models to optimize for what actually works in a sandbox environment. This survey explores the evolution of this field, tracking the rapid development of RL-enhanced models for both code generation and compiler optimization.

Timeline of RL-based developments in compiler optimization and code generation (2021-2024).

Reinforcement Learning Methodologies for Code

The core of the RL approach in code generation involves treating the LLM as an agent that interacts with a programming environment. This environment provides feedback—often in the form of compiler errors or unit test pass/fail signals—which the model uses to refine its policy through trial and error.

The Reinforcement Learning framework applied to code generation, illustrating the interaction between the Agent, Environment, and State.

Several key frameworks have been developed to implement this loop:

  • Policy-Based Methods: Algorithms like PPO (Proximal Policy Optimization) are used to iteratively refine the model's strategy based on cumulative rewards.
  • Actor-Critic Frameworks: Models such as CodeRL utilize an "actor" (the LLM) to generate code and a "critic" network to evaluate functional correctness, providing a more nuanced reward signal than simple binary pass/fail.
  • Preference Optimization: Newer techniques like DPO (Direct Preference Optimization) and GRPO (Group Relative Policy Optimization) have gained traction. DPO simplifies the process by eliminating the need for a separate reward model, while GRPO reduces computational overhead by using group-based reward averages.
  • Execution-Guided Synthesis: This method involves real-time execution against unit tests, using the feedback to directly "punish" buggy code and "reward" functional solutions during the fine-tuning phase.

Datasets and Benchmarking

The transition to RL-based training requires specialized datasets that go beyond static text. The survey categorizes these into:

  1. Pre-training Sources: Massive, cleaned crawls from GitHub and Common Crawl provide the foundational syntax.
  2. Functional Benchmarks: Industry standards like HumanEval and MBPP (and their "+" versions with expanded test cases) are used to evaluate basic logic. More rigorous sets like APPS provide competition-level challenges.
  3. Contamination-Free Benchmarks: LiveCodeBench is highlighted as a critical tool, pulling problems from recent contests to ensure models are tested on logic they haven't seen during pre-training.

Key Insights and Performance

A major finding of this survey is the "Execution Reward" shift. By using a compiler or interpreter as the environment, RL provides a ground-truth signal that human labeling cannot match. Furthermore, models like PPOCoder have integrated Abstract Syntax Trees (ASTs) to ensure the structural logic of the code aligns with the intended goal.

Results indicate that RL-based fine-tuning consistently boosts performance on the APPS benchmark. Notably, RL-tuned models with fewer parameters often outperform much larger base models. For instance, the 770M parameter B-Coder and RLTF models achieved higher pass@1 scores on competition-level tasks than the 12B parameter Codex. RL also improves robustness, increasing the "pass@k" rate, which signifies a higher likelihood of producing a working solution within a limited number of attempts.

Challenges and Future Directions

Despite the progress, several hurdles remain:

  • Computational Cost: RL training remains expensive, requiring high-performance hardware for extensive sampling.
  • Language Gap: Most research is concentrated on high-level languages like Python. There is a significant need for datasets and RL methods targeting low-level languages like Assembly or formal verification languages like Lean.
  • Scalability: Current methods excel at short snippets but struggle with the context and logic required for massive, multi-file enterprise codebases.

Summary updated

BibTeX
@misc{wang2024enhancing,
  author = {Junqiao Wang and Zeng Zhang and Yangfan He and Zihao Zhang and Xinyuan Song and Yuyang Song and TIANYU SHI and Yuchen Li and Hengyuan Xu and Kunyu Wu and Yi Xin and Zhongwei Wan and Xinhang Yuan and Zijun Wang and Kuan Lu and Menghao Huo and Jingqun Tang and Guangwu Qian and Keqin Li and Qiuwu Chen and Lewei He},
  title = {{Enhancing Code LLMs with Reinforcement Learning in Code Generation: A Survey}},
  year = {2024},
  eprint = {2412.20367},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.20367},
}
Figure