TL;DR
DiDPO (Diff-in-Diff Policy Optimization) is a novel, critic-free reinforcement learning method designed specifically for training coding agents. By breaking down complex code changes ("diffs") into fine-grained functional units and grouping similar edits across different rollouts, DiDPO solves the long-standing credit assignment problem in code generation, boosting performance by over 10% on competitive benchmarks.
What Problem Does This Paper Address?
Reinforcement Learning with Verifiable Reward (RLVR) has become a dominant paradigm for training LLM coding agents. Because code can be objectively tested via compilers and unit tests, the environment provides a clean, binary success/failure signal.
However, coding tasks suffer from a severe credit assignment problem. In standard agent tasks, an action is atomic (e.g., moving a chess piece). In coding, a single multi-line edit—a code "diff"—might fix one bug but introduce another, or contain a mix of brilliant logic and minor syntax errors. Standard RLVR methods look only at the final outcome or the step-level reward, treating the entire code diff as a single unit. This makes it impossible for the model to learn which specific part of a large edit actually caused the code to pass or fail.
Methods
To address this, the authors propose Diff-in-Diff Policy Optimization (DiDPO). Instead of treating a code diff as an indivisible block, DiDPO looks inside the action to perform hierarchical credit assignment without requiring a separate critic network or extra environment rollouts.
The method operates in three core steps:
- Sub-diff Decomposition: Diffs from multiple trajectories of the same task are sliced into contiguous sub-diffs at multiple scales.
- Dynamic Anchor Selection via "Groupability Score": To avoid cluttering the training with meaningless fragments (like blank lines or basic syntax scaffolding), DiDPO uses a submodular optimization function called a Groupability Score (GS). This score balances the semantic size of a sub-diff against its "group mass"—how frequently a similar functional edit appears across different rollouts.
- Diff-Level Advantage Calculation: Aligned sub-diffs are clustered into advantage groups. DiDPO computes a local, group-relative "diff-level advantage" by comparing the rewards of trajectories that share this specific sub-diff pattern. This local advantage is combined with the overall trajectory-level advantage and projected back to individual response tokens.
Datasets
The authors evaluated DiDPO across eight diverse code-generation and algorithmic reasoning benchmarks:
- Function-level Synthesis: HumanEval, MBPP.
- Mixed Programming Challenges: APPS (spanning Introductory, Interview, and Competition tiers).
- Contamination-Resistant Benchmarks: LiveCodeBench.
- Competition-Level Reasoning: LeetCode, USACO (USA Computing Olympiad), OJBench, and ICPC.
For training, they utilized a filtered subset of prime data, augmented using a cold-start pipeline with GPT-5.5 to generate high-quality multi-turn trajectories for Supervised Fine-Tuning (SFT) before running RL.
Key Insights and Ideas
- Whole Diffs are Too Sparse: Grouping trajectories based on entire code diffs fails because minor variations cause the similarity score to drop below thresholds. Slicing into sub-diffs uncovers a rich set of recurring, mergeable functional states across different rollouts.
- The Evolution of Code Quality: Early in training, the model's advantage groups are dominated by short fragments and syntax scaffolding. As training progresses, the Groupability Score naturally shifts the model's focus toward meaningful "Block" edits (like function bodies and loop structures), providing a cleaner, low-bias credit signal.
Key Results
DiDPO achieved state-of-the-art results among agentic RL baselines across both Qwen2.5-Coder-7B and Qwen3.5-4B backbones:
- Overall Performance: On Qwen2.5-Coder-7B, DiDPO achieved an average score of 48.4% across standard benchmarks, outperforming the strong agentic baseline GiGPO (44.2%) and standard GRPO (42.8%).
- Hard Algorithmic Tasks: On the highly challenging USACO benchmark, DiDPO more than doubled the performance of GRPO, jumping from 6.8% to 15.6%.
- Efficiency: Remarkably, DiDPO achieves these gains with only a 2.3% training time overhead compared to GRPO, and introduces zero inference overhead since the sub-diff grouping happens entirely during the offline advantage calculation phase.
Limitations and Future Work
While highly effective, DiDPO relies on a similarity matrix calculation that scales quadratically with the number of sub-diff candidates (though it is bounded in practice by a similarity threshold). The authors note that incorporating caching or approximate nearest-neighbor search could further optimize this process. Additionally, the method currently requires a "cold-start" SFT phase to ensure the base model can reliably generate the multi-turn thought-action format required for rollout generation.
Summary updated