Domain-Adaptable Reinforcement Learning for Code Generation with Dense Rewards

Erfan Aghadavoodi Jolfaei, Daniel Maninger, Abhinav Anand, Mert Tiftikci, Mira Mezini

TL;DR

Researchers have developed a new reinforcement learning framework that fine-tunes Large Language Models (LLMs) for code generation by replacing "all-or-nothing" feedback with dense, token-level rewards. By mapping execution outcomes and static analysis directly back to specific parts of the code, the framework significantly boosts functional correctness in general Python tasks and slashes execution failures in robotics simulations by over 50%.

What Problem Does This Paper Address?

While LLMs are surprisingly good at writing code, they often produce "hallucinated" syntax, insecure patterns, or code that simply doesn't work in the real world. This is particularly dangerous in fields like robotics, where a single line of incorrect code could lead to a physical collision or hardware damage.

The standard way to improve these models is through Reinforcement Learning from Verifiable Reward (RLVR). However, most current RL methods use sparse rewards: the model writes an entire program, and it gets a "1" if it passes all tests and a "0" if it fails. This creates a massive "credit assignment" problem. If a 50-line script fails, the model doesn't know if the error was a typo on line 2 or a logic error on line 48. This makes training slow and inefficient.

Methods

The authors introduce a unified fine-tuning framework based on Proximal Policy Optimization (PPO) that utilizes a customizable, execution-aware reward formula.

The key innovation is the token-level reward mapping mechanism. Instead of waiting until the end of the sequence, the framework provides feedback across four dimensions:

  1. Syntactic Correctness ($R_{sync}$): Uses a modified SYNCODE algorithm to flag tokens that violate language grammar in real-time.
  2. Code Style and Vulnerabilities ($R_{lint}$): Integrates the Ruff linter to detect syntax errors and security flaws.
  3. Distributional Regularization ($R_{KL}$): Ensures the model doesn't drift too far from its original functional state.
  4. Task-Specific Rewards ($R_{opt}$): Includes unit test results, Data Flow Graph (DFG) matching, and simulator feedback (via RoboSim).

Crucially, when a sequence-level error occurs (like a failed unit test), the framework uses an attribution mechanism to distribute that penalty across the generated tokens, creating a "dense" signal that tells the model exactly where it likely went wrong.

Datasets

The framework was evaluated across two distinct domains:

  • General-Purpose Python: Trained on a subset of OpenCodeInstruct (5,000 samples) and evaluated on MBPP (Mostly Basic Python Problems) and its more rigorous variant, MBPP+.
  • Robotic Program Synthesis: Trained on the ROBO-INSTRUCT dataset and evaluated on the ROBOEVAL benchmark, which tests a model's ability to generate executable control programs for robots in a simulated environment.

Key Insights and Ideas

  • Dense is Better Than Sparse: By transforming binary "pass/fail" outcomes into token-level signals, the model learns much faster. It’s the difference between a teacher marking an entire essay "F" versus providing red-pen corrections on specific sentences.
  • Domain Adaptability: The reward function is modular. You can swap out a robotics simulator for a web-app tester or a security scanner, making the framework "domain-adaptable."
  • Small Models, Big Gains: The researchers used a relatively small model (Qwen2.5-Coder 1.5B). Their RL approach allowed this compact model to narrow the performance gap with models many times its size, proving that smart training can be more effective than raw scale.
  • Environment Awareness: In robotics, "correct" code isn't just about syntax; it's about physics. The integration of simulator feedback allows the model to learn physical constraints (e.g., "I can't move the arm through a wall") directly through the RL loop.

Key Results

The results show that structured RL provides a massive "level-up" for code LLMs:

  • General Coding: On the MBPP benchmark, the model saw an absolute pass@1 increase of 19.3% (rising from 46.0% to 65.3%). On the tougher MBPP+, it improved by 14.3%.
  • Robotics: On ROBOEVAL, the base 1.5B model originally failed 77 out of 80 tasks due to Python errors. After fine-tuning, these errors dropped to 11, and the model successfully solved 14 tasks from scratch—a 51% reduction in execution failures.
  • Efficiency: The model shifted from producing 100% non-executable robotic code to 51% executable code, demonstrating a newfound "awareness" of the simulation environment.

Limitations and Future Work

Despite the success, the authors note several areas for improvement:

  • Length Bias: There is a risk that the reward system might inadvertently favor shorter or longer code snippets based on how rewards are distributed.
  • Complex Logic: While the model improved significantly, it still struggles to match the absolute performance of much larger "frontier" models (like 7B+ parameter models) on complex reasoning tasks.
  • Reward Design: Future work is needed to design more general execution-based rewards that go beyond simple unit tests or specific simulators.
  • Scaling: The authors suggest investigating how this dense reward approach scales when applied to much larger, more capable LLMs.

Summary updated

BibTeX
@inproceedings{jolfaei2026domain,
  author = {Erfan Aghadavoodi Jolfaei and Daniel Maninger and Abhinav Anand and Mert Tiftikci and Mira Mezini},
  title = {{Domain-Adaptable Reinforcement Learning for Code Generation with Dense Rewards}},
  booktitle = {DL4C @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=0bwoOSnBA3},
}
Figure