Language models that rewrite code to make it faster usually work in a loop: propose a revision, run it, read the timing, and try again. Running every candidate on large stress inputs is slow. A tempting shortcut is to replace execution with a learned "judge," a model that reads two versions of a program and predicts which is faster. Such judges already exist and beat GPT-4o at the task on fixed test sets. But offline model-based optimization, the study of optimizing designs against a learned predictor when the true objective cannot be queried, has shown repeatedly that the moment you optimize against a learned predictor, the optimizer finds inputs where the predictor is confidently wrong. We expect the same failure in code: a refiner steered by a judge will learn to write code that looks optimized to the judge while running no faster, or slower.
This note proposes to measure that failure directly and to fix it with the main tool from offline optimization, a conservative surrogate. A conservative surrogate is trained to give low scores to candidates unlike its training data. Here the "unlike" candidates are the refiner's own judge-pleasing rewrites. The claim is that a judge trained with these self-generated adversarial negatives lets an iterative refiner reach the final efficiency of an execute-everything loop while running only a small, fixed number of stress-test executions per problem. A judge trained the ordinary way cannot do this, and neither can an ensemble judge penalized for disagreement.
Core Claim
The efficiency judge of Rethinking Code Refinement: Learning to Judge Code Efficiency fine-tunes DeepSeek-Coder models on pairs of programs with measured runtimes. It reaches 72.49% pairwise accuracy on Python and a Spearman correlation of 0.66 on speedup regression. It was only ever evaluated passively, on pairs written by humans or by models that were not trying to fool it. We make two claims. The first is diagnostic: once the judge becomes the acceptance signal in a refinement loop, the fraction of judge-approved edits that actually run slower rises well above the roughly 30% "machine refinements degrade efficiency" base rate reported in the same paper, and the judge's accuracy on loop-generated pairs falls below its reported 72.49%. The second is constructive: a conservative training objective in the style of Conservative Objective Models from Design-Bench and PRIME from Data-Driven Offline Optimization for Architecting Hardware Accelerators closes most of that gap. The negatives in that objective are sampled from the refiner itself while it optimizes against the current judge.
Concretely, let $J_\theta(c, c')$ be the judge's predicted log-speedup of revision $c'$ over original $c$. Let $\mathcal{D}$ be pairs with measured log-speedup $s$. Let $q(c' \mid c)$ be the distribution of rewrites produced by the refiner when it is told to please the current judge. The training objective is
$$ \mathcal{L}(\theta) = \mathbb{E}_{(c,c',s)\sim\mathcal{D}}\big[(J_\theta(c,c') - s)^2\big] + \alpha\Big(\mathbb{E}_{c' \sim q(\cdot\mid c)}\big[J_\theta(c,c')\big] - \mathbb{E}_{(c,c')\sim\mathcal{D}}\big[J_\theta(c,c')\big]\Big), $$
where $\alpha \ge 0$ sets how much the judge distrusts rewrites that resemble what the refiner does when gaming it. This is the COMs penalty with one change. The "out-of-distribution" samples do not come from gradient ascent in a continuous space, which fails for discrete programs, as DEMO's collapse on NAS in Design Editing for Offline Model-based Optimization illustrates. They come from the actual discrete optimizer the judge will face.
Research Program
The work has three parts. The first builds an exploitation testbed. We use COFFE's deterministic CPU instruction counts from COFFE as ground truth. COFFE reports a relative standard deviation of 0.003% for instruction counts versus 2–5% for wall-clock time, which removes the measurement jitter that ICER identifies as a driver of "efficiency overfitting." Any disagreement between judge and ground truth is then the judge's fault rather than noise. We reproduce the EMNLP judge and plug it into a refiner loop. We then log every accepted edit with its judged and true speedup. We also catalogue the edit types the refiner discovers that inflate judged speedup: cosmetic vectorization, renamed or reordered loops, removed comments, added caching that never hits. This catalogue is itself a finding, since no paper in the file has characterized what judge exploitation looks like in code.
The second part trains conservative judges. Problems are split into a judge-training pool and a disjoint evaluation pool. On the training pool we run the refiner against a naive judge and collect its rewrites as samples from $q$. A small fraction of these rewrites is executed to add labeled pairs to $\mathcal{D}$, echoing PRIME's use of infeasible designs as negatives. We then train with the objective above, repeating the collect-and-retrain step for two or three rounds.
The third part attacks the open problem Design-Bench flags: choosing $\alpha$ without ground-truth queries. We propose an "exploitation probe" on the training pool only. For each candidate $\alpha$, run a short judge-guided refinement, execute the final candidates, and pick the $\alpha$ whose judged improvements best rank-correlate with true improvements. Every $\alpha$ decision is made on problems the evaluation never touches.
At evaluation time the loop works as follows. The refiner proposes $k$ candidates. Cheap functional unit tests filter out incorrect ones, which keeps ICER's relaxed correctness-only acceptance for exploration. The judge ranks the survivors, and only the top $b$ per round, within a total budget $B$ per problem, are run on stress inputs. Accept/reject decisions and final selection use those executions. The judge therefore decides what gets executed, never what gets returned unverified. This keeps the system safe even if the judge is exploited. It also makes the scientific question measurable: how much of the execute-everything result survives at each budget $B$.
A secondary regime tests whether the gains transfer where execution is genuinely expensive. This is heuristic design on large instances from the PathWise suite in PathWise, such as TSP with up to 1,000 cities. The PathWise authors themselves name expensive evaluation as the limitation they leave open. There the judge predicts relative tour quality of heuristic pairs, and the budget is counted in large-instance evaluations.
Baselines
The naive reference point is the refiner with no efficiency signal at all. It samples one correct rewrite per round under ICER's relaxed policy and returns the last correct version. This isolates what any efficiency feedback adds.
The strongest existing method is ICER from Improving Code Efficiency with Iterative Refinement using LLMs, which executes every candidate. On EffiBench it reduces normalized execution time from 1.89× to 1.03× when Gemini-2.5-Pro refactors code generated by DeepSeek-R1-Distill-Qwen-32B. We run ICER with the same refiner model, the same $k$ candidates per round, and the same number of rounds, but with unlimited stress-test execution, i.e. $B = k \times$ rounds. It is the upper reference our budgeted method must approach. We also report EffiLearner from EffiLearner, which feeds line-level profiles back into the prompt and cut StarCoder2-15B execution time on EffiBench from 0.93 s to 0.12 s. It is a second execute-everything reference under the same refiner.
The direct competitor for the budgeted regime is the naive judge of Rethinking Code Refinement, retrained on our training pool and inserted into the identical ranking-then-execute loop at the same $B$. A second competitor is an ensemble of five such judges that ranks by mean minus a disagreement penalty. This is the standard uncertainty-aware alternative from offline optimization, in the spirit of RoMA in RoMA: Robust Model Adaptation for Offline Model-based Optimization. Its penalty weight gets the same probe-based tuning as our $\alpha$. A third competitor is zero-shot GPT-4o used as the ranker, which reached 63.67% accuracy passively. A random ranker at the same $B$ is the floor.
The key ablation replaces refiner-generated negatives in the conservative loss with generic perturbations: random mutations of the original, or rewrites from a different model not steered by the judge. If this ablation matches the full method, the ingredient that matters is conservatism in general, not adversarial samples from the actual optimizer.
All systems share the refiner model, the problem split, the unit-test filter, the random seeds, and the number of rewrite samples used for judge training. Each learned ranker gets the same budget of probe executions for hyperparameter selection. Beating the naive and ensemble judges means lower normalized instruction count at equal $B$, with confidence intervals over problems and seeds that exclude zero. We regard the proposal as successful if, at $B$ equal to roughly a quarter of ICER's executions, it recovers at least most of ICER's improvement over the do-nothing baseline.
Why not just…?
Why not just execute everything, since instruction counts are cheap and noise-free? This is the most serious threat. On LeetCode-scale Python, COFFE's instruction counts make execution both precise and fairly affordable, so a surrogate may simply not be worth it there. We will report wall-clock cost, including judge inference, alongside execution count. If execute-everything ICER wins at equal wall-clock on EffiBench and COFFE, we will say so. The claim then narrows to regimes where one evaluation is expensive, which is why the PathWise large-instance experiment is part of the program rather than an afterthought. The exploitation measurements remain useful either way, because judges are already being proposed for settings like pull-request review where execution is unavailable.
Why not just use an ensemble and penalize disagreement? Ensembles detect inputs on which their members disagree. An optimizer that learns a shortcut shared by all members, such as a surface pattern every judge fine-tuned on the same data associates with speed, produces confident agreement. We cannot cite evidence that this happens in code, so the ensemble is a head-to-head baseline rather than a straw man. If it matches the conservative judge at every budget, the simpler method wins and we will report that.
Why not just ask a frontier model to judge, or to reason about Big-O first? The file gives direct evidence against both as primary signals. Zero-shot GPT-4o reaches 63.67% on passive pairs, below the fine-tuned 1.3B judge. ICER finds that forcing explicit Big-O predictions degrades refinement, with frontier models near 60% accuracy on BigOBench and CodeComplex labels. We still include GPT-4o as a ranker because it was never trained on the judge's data. It might therefore be less exploitable despite being less accurate, and that is worth measuring.
Proposed Experiments
The first decisive check is whether exploitation exists at all. On COFFE and EffiBench evaluation problems, we run judge-guided refinement with acceptance by the naive judge alone, for measurement only. We then compare the judge's pairwise accuracy on loop-generated pairs against its 72.49% passive figure, and the fraction of accepted edits that increase instruction count against the roughly 30% passive base rate. If loop-generated pairs are no harder than passive ones, the premise fails. In that case the right conclusion is that naive judges are already safe to use, and the conservative machinery is unnecessary.
The second check is the budget curve. We plot normalized instruction count and COFFE's efficient@1 against $B$ for all rankers, anchored by the do-nothing baseline and full-execution ICER. COFFE reports that models with an 80% functional pass rate fall to 40% on efficient@1, so there is room to move. The conservative judge should dominate the naive and ensemble judges at small $B$, and the curves should converge as $B$ approaches full execution.
The third check is the negatives ablation described above. It tests whether refiner-generated samples, rather than conservatism per se, carry the gain.
The fourth check validates the $\alpha$ probe. We compare the $\alpha$ it selects on the training pool against the oracle-best $\alpha$ on the evaluation pool, which is computed after the fact for analysis only. A small regret would be a partial answer to Design-Bench's offline tuning problem in this domain.
The final check repeats the budget curve on PathWise's large TSP and knapsack instances, where each evaluation is costly. This is the setting in which a win in execution count would translate into real savings.
References
- Rethinking Code Refinement: Learning to Judge Code Efficiency
- Design-Bench: Benchmarks for Data-Driven Offline Model-Based Optimization
- Data-Driven Offline Optimization for Architecting Hardware Accelerators
- Design Editing for Offline Model-based Optimization
- COFFE: A Code Efficiency Benchmark for Code Generation
- Improving Code Efficiency with Iterative Refinement using LLMs
- PathWise: Planning through World Model for Automated Heuristic Design via Self-Evolving LLMs
- EffiLearner: Enhancing Efficiency of Generated Code via Self-Optimization
- RoMA: Robust Model Adaptation for Offline Model-based Optimization