Why Code Model RL Scores Double: Training and Evaluation Logic

    This article explains why a code model can score more than twice as high after reinforcement learning post-training on the same base model. It breaks the phenomenon into training-side factors—cost penalties, length-weighted baselines, rollout length oscillation control, and dense credit assignment—and evaluation-side factors such as stricter scoring criteria, harness inconsistency, and benchmark-training overlap. It also offers reusable practices for separating training from evaluation, reporting distributions, and validating scores against real business metrics.

    1. The Phenomenon: Same Base, Post-Training, Double the Score

    In coding benchmarks, a common pattern appears: a model performs average on its general-purpose base version, but after one round of reinforcement learning post-training targeting software engineering tasks, its scores on multiple code benchmarks can rise to more than twice the base score. Such results are often read as “the base model is weak” or “the benchmark is rigged.” From an engineering perspective, a more reasonable explanation is that the post-training stage systematically optimized the task distribution, reward shaping, and execution environment, while differences in evaluation criteria and execution frameworks were amplified.

    It is important to note that a higher score does not mean general capability improved by the same proportion. A coding evaluation is essentially the coupled result of three things: the model, the execution framework, and the scoring rules. A change in any one of them can significantly alter the final number. To understand the doubling effect, the training side and the evaluation side must be examined separately.

    2. Training Side: Making Reinforcement Learning Actually Learn

    2.1 Reward Functions Need a Cost Penalty

    In software engineering tasks, a model can generate patches of arbitrary length. If the reward is based only on “did the tests pass,” the model tends to produce long, repetitive output with many irrelevant changes to “get lucky.” Once a cost penalty term is introduced, the reward is tied to generation length, number of tool calls, and editing rounds, forcing the model to balance “solving the problem” against “controlling cost.”

    Illustrative expression (not a specific implementation):

    1. # r_task: reward for whether the task passes
    2. # cost: normalized token / call / round cost
    3. reward = r_task - lambda_cost * cost

    The key is calibrating lambda_cost: too large makes the model overly conservative and afraid to modify anything; too small degrades into unconstrained length inflation.

    2.2 Length-Weighted Reward Baselines

    Policy gradient methods rely on baselines to reduce variance. When the sample length distribution varies greatly, a single global baseline unbalances the gradient scale between long and short samples. Using length-bucketed or length-weighted baselines puts trajectories of different sizes on the same scale for comparison, making training more stable and convergence faster.

    2.3 Controlling Rollout Length Oscillation

    The most common source of training instability in long-horizon software tasks is rollout length oscillating back and forth across iterations: in one step the model learns to “try a few more times” and length spikes; in the next step the penalty takes effect, length drops sharply, and capability fluctuates with it. Common control measures include:

    • Setting a soft constraint range for length instead of a hard cutoff;
    • Applying partial credit assignment to overlong trajectories to avoid “all or nothing”;
    • Retaining a certain proportion of historically successful trajectories during sampling to stabilize the reward distribution;
    • Monitoring length quantiles (P50/P90) rather than the mean alone.

    2.4 Credit Assignment for Long-Horizon Tasks

    Fixing a cross-file defect often requires multiple rounds of localization, editing, and test runs. If the reward is given only at the final state, correct intermediate steps are not reinforced. A workable approach is to introduce staged signals, such as “tests turning from failing to passing,” “compile error count decreasing,” or “the correct file being located,” turning sparse rewards into dense ones.

    3. Evaluation Side: Why the Same Model Scores Very Differently

    3.1 Stricter Scoring Criteria Lower Overall Scores

    Newer benchmarks often no longer hard-code requirements in the prompt, but instead simulate the standards open-source maintainers use to review code changes, adding many “instant fail” conditions: fixing only the specified path without handling similar issues, failing to stay compatible with existing input types in the repository, or not adding necessary tests can all result in a zero. On such benchmarks, models without targeted adaptation generally lose points, which is an expected outcome.

    3.2 Inconsistent Execution Frameworks (Harness)

    The same model can differ by several percentage points across execution frameworks, due to different available tool sets, different context organization, different failure retry strategies, and different patch application methods. If post-training and evaluation use the same framework, the model’s calling habits for that framework have already been reinforced, so scores are naturally higher; switching to an unfamiliar framework puts it at a clear disadvantage.

    3.3 The Risk of Benchmarks and Training Sharing the Same Origin

    When a benchmark and the training method come from the same team, the grasp of scoring details is naturally higher. This does not necessarily mean cheating, but scores must be discounted when interpreted, and horizontal comparisons from independent third-party evaluations should be prioritized.

    4. Reusable Practical Recommendations

    1. Separate training from evaluation: keep at least one independent evaluation environment different from the training framework to estimate real generalization.
    2. Report distributions, not single points: provide the mean and variance across multiple runs, along with length and cost distributions.
    3. Keep reward design simple before complex: first get the two-dimensional “pass rate - cost” reward working, then introduce staged signals.
    4. Build a regression set: turn historical failure cases into regression tests to prevent capability regression during post-training.
    5. Focus on real gains: validate scores against business metrics such as human adoption rate, rework rate, and average fix time.

    5. Conclusion

    “Double the score” is usually the combined result of training-side optimization (cost penalties, length-weighted baselines, oscillation control, dense credit assignment) and evaluation-side factors (stricter scoring, framework consistency). For developers, what is truly valuable is not a particular number, but building a reproducible, comparable, and regression-capable evaluation and training loop. On the cloud platform side, containerized execution environments, object storage for trajectory data, message queues for scheduling sampling tasks, and logging, monitoring, and alerting services for observing training stability can support this engineering pipeline. General-purpose cloud product categories offered by providers such as Baidu AI Cloud can serve as infrastructure options for such workflows.