HyperAIHyperAI

Command Palette

Search for a command to run...

修正者に決めさせる:修正者の尤度からコードローカライザを訓練する

Khalil Hennara Muhammad Hreden Zeina Aldallal Sara Chrouf Safwan AlModhayan

概要

コードローカライザは通常、参照パッチが編集するファイルを予測するよう訓練されるが、修正者が読む必要のあるコードは、修正者が変更するコードと同一ではない。我々はFixer-Guided Localization(FGL)を提案する。ローカライザが複数の局所化候補を提案し、凍結された修正者が検証済みパッチを生成する尤度に基づいて各候補を採点し、ローカライザはテストの実行や強化学習を用いずに、重み付き教師ありファインチューニングによってこれらのスコアで訓練される。我々はKaggle Gemma-4 Developer Agentコンペティション向けに、Gemma 4 E4B上で1,629件のテスト検証済みKimi K3軌跡からフルパイプラインを構築した。FGLターゲットにより、修正者は教師の局所化と同頻度でバグを発見しつつ、使用コード量を27.5%削減した。開発セットでは、マッチドコントロールと比較して、1回のEMラウンドでエージェントは期待される方向に変化した。パッチに到達したタスクが増加し(53対46)、存在しないファイルの読み取りで行き詰まるタスクが減少し(43対54)、解決されたタスクが増加した(8対6)。訓練はエージェントの動作も変化させる。訓練済みエージェントはベースモデルより約3倍多く探索し、誤ったパッチの生成が大幅に減少し、単一エージェントは78タスク中最大11タスクを解決したのに対し、ベースモデルは8タスクであった。13回の評価実行の分析により、8分の予算制約下で4Bエージェントを制限する要因(時間、繰り返しループ、編集品質)が特定され、小規模コーディングエージェントの訓練に関する実践的な教訓が得られた。すべてのデータ、コード、アダプタは公開されている。

One-sentence Summary

MISRAJAI researchers propose Fixer-Guided Localization (FGL), which trains a Gemma 4 E4B code localizer by scoring proposals with a frozen fixer’s patch likelihood and applying weighted supervised fine-tuning without running tests or reinforcement learning, matching teacher localization accuracy while using 27.5%27.5\%27.5% less code and improving agent task solving.

Key Contributions

  • Fixer-Guided Localization (FGL) treats localization as a hidden variable: a localizer proposes candidate locations, a frozen fixer scores each candidate by the log-probability of a verified patch, and the localizer is trained with weighted supervised fine-tuning, without running tests or reinforcement learning. Offline, this target helps the fixer find the bug as often as the teacher localization while using 27.5% less code.
  • A data generation and conversion pipeline produces and verifies teacher trajectories inside the competition agent loop and sandbox, then converts them into two-agent training data without inventing tool outputs. Released assets include 1,629 test-verified trajectories, data, training code, and trained adapters.
  • The evaluation covers eight systems on Gemma 4 E4B with paired tests and a matched control, showing that one expectation-maximization round moves the agent in the expected direction: more tasks reach a patch (53 vs. 46), fewer tasks get stuck reading nonexistent files (43 vs. 54), and more tasks are solved (8 vs. 6). An analysis of 13 evaluation runs identifies time budget, repetition loops, and edit quality as the main limits for a 4B agent under an 8-minute budget.

Introduction

Language-model agents now fix real GitHub issues, and many follow a two-stage design where a localizer first finds relevant code before a fixer writes a patch. This matters because localization quality is a bottleneck for downstream repair. Prior localizers are often trained to predict files changed by the reference patch, but that label is a weak proxy: fixes may depend on unchanged code such as callers, base classes, or tests, and strong file-level accuracy still leaves low issue resolution. Learning from fixer outcomes has typically required expensive reinforcement learning with test execution. The authors propose Fixer-Guided Localization (FGL), an expectation-maximization method that treats localization as a hidden variable. A frozen fixer scores candidate locations by the log-probability it assigns to a verified patch, and the localizer is fine-tuned on those candidates using weighted supervised fine-tuning alone.

Dataset

The authors describe data as the most expensive part of the project, with summary details in Table 1.

Sources and task filtering

  • Collected about 10K tasks from SWE-bench, SWE-Gym, R2E-Gym, and SWE-smith.
  • Every patch was checked to apply at its base commit, and a no-model run verified that target tests fail before the reference fix and pass after it.
  • 3,894 of the first 4,500 ranked tasks passed.
  • Tasks from the four repositories of the competition development set are excluded to avoid overlap with evaluation. Counts are given in Figure 4 and Table 9 in Appendix D.

Teacher trajectories

  • Kimi K3 ran inside the competition agent loop on each task container, with 8 minutes per attempt and no network. Git history that could reveal the fix was removed first.
  • A fresh container ran the task tests on the teacher patch. A trajectory counts as solved only if the tests pass.
  • Of 3,068 attempts on 2,959 tasks, 1,629 tasks were solved, or 55 percent: 564 from SWE-Gym, 492 from SWE-bench, 307 from SWE-smith, and 266 from R2E-Gym.
  • 1,577 solved trajectories were kept under per-source and per-repository caps. Only verified trajectories are used for training.
  • A solved trajectory has a median of 15 tool calls, a 90th percentile of 33, and 13.8K tokens.

Recall cleaning

  • The teacher sometimes recalled the real upstream fix, citing pull requests and commit hashes, some invented, and sometimes wrote a fix before reading the code.
  • A cleaning pass found 3,233 recall passages in 1,116 trajectories and rewrote only those reasoning passages.
  • Tool calls, tool outputs, and patches were never changed.

From one agent to two

  • Each trajectory is cut at its first edit. Exploration before the cut becomes a localizer record ending with answer z.
  • The fixer record calls the localizer, reads every location of z, may request code that z misses, and then continues with the teacher edits and submission unchanged.
  • Every requested read is answered with code the teacher actually saw, checked byte for byte. No tool output is invented.
  • Added steps use short fixed sentences to avoid letting a language model reintroduce recalled knowledge.

Exact training text

  • Raw trajectories do not contain the exact request the model receives because tool schemas, system-prompt additions, and message structure come from the agent framework.
  • Every trajectory is replayed through the competition agent stack with a scripted model that returns the teacher turns, and the requests sent are kept.
  • Token IDs match vLLM's own rendering on all 141 test prompts.
  • Table 2 lists the resulting 9,173 records, about 90M tokens.

How the data is used

  • Training uses only verified, recall-cleaned, and replayed trajectories.
  • The final records combine localizer and fixer structure with exact agent request text, totaling 9,173 records and about 90M tokens.
  • The section does not specify an explicit separate validation split or mixture ratios beyond the per-source and per-repository caps.

Method

The authors leverage a two-agent system built upon a single frozen base model equipped with two distinct LoRA adapters. The primary agent, the fixer, acts as the main controller. It invokes the localizer as a tool to explore the repository. The localizer operates in a fresh session and returns a list of up to eight code locations, specifying the path, symbol, line range, and whether the location requires editing or is read-only. The fixer then reads these locations, potentially requests additional code, and proceeds to edit, test, and submit the patch.

To train this system, the authors utilize teacher trajectories generated by a single-agent model. Each trajectory is split at the point of the first code edit. The exploration phase preceding the cut is converted into a localizer record that concludes with a localization answer zzz. The fixer record is constructed by having the fixer call the localizer, read the locations in zzz, and request any missing code using only the outputs the teacher actually observed. The fixer then continues with the teacher's original edits and submission unchanged. This ensures that no tool outputs are invented and that the added steps use fixed sentences to prevent the model from recalling external knowledge.

For a given task with issue xxx, repository RRR, and a verified teacher patch y⋆y^{\star}y⋆, the localizer provides a distribution pϕ(z∣x,R)p_{\phi}(z \mid x, R)pϕ​(z∣x,R) over localizations zzz, and the fixer provides pθ(y∣x,ctx⁡(z))p_{\theta}(y \mid x, \operatorname{ctx}(z))pθ​(y∣x,ctx(z)), where ctx⁡(z)\operatorname{ctx}(z)ctx(z) is the code pointed to by zzz. Since the correct localization is unobserved, the method maximizes the likelihood of the verified patch over all possible localizations:

log⁡p(y⋆∣x,R)=log⁡∑zpϕ(z∣x,R)pθ(y⋆∣x,ctx⁡(z)).\log p(y^{\star} \mid x, R) = \log \sum_{z} p_{\phi}(z \mid x, R) p_{\theta}(y^{\star} \mid x, \operatorname{ctx}(z)).logp(y⋆∣x,R)=logz∑​pϕ​(z∣x,R)pθ​(y⋆∣x,ctx(z)).

A localization is evaluated solely on its utility in helping the fixer generate the verified patch. The gradient for the localizer is computed as an average under the posterior:

q(z)∝pϕ(z∣x,R)pθ(y⋆∣x,ctx⁡(z)).q(z) \propto p_{\phi}(z \mid x, R) p_{\theta}(y^{\star} \mid x, \operatorname{ctx}(z)).q(z)∝pϕ​(z∣x,R)pθ​(y⋆∣x,ctx(z)).

To approximate this posterior, the authors draw KKK candidates z1,…,zKz_1, \dots, z_Kz1​,…,zK​ from the localizer. The posterior weights are computed as a softmax over the fixer's scores. Each candidate is scored using:

sk=1∣y+⋆∣∑t∈y+⋆log⁡pθ(yt⋆∣y<t⋆,x,ctx⁡(zk))−λctx⁡tok⁡(zk)−λreq⁡∣ak∣,s_k = \frac{1}{|y_{+}^{\star}|} \sum_{t \in y_{+}^{\star}} \log p_{\theta}(y_t^{\star} \mid y_{<t}^{\star}, x, \operatorname{ctx}(z_k)) - \lambda_{\operatorname{ctx}} \operatorname{tok}(z_k) - \lambda_{\operatorname{req}} |a_k|,sk​=∣y+⋆​∣1​t∈y+⋆​∑​logpθ​(yt⋆​∣y<t⋆​,x,ctx(zk​))−λctx​tok(zk​)−λreq​∣ak​∣,

where y+⋆y_{+}^{\star}y+⋆​ represents the tokens on the patch's added lines. This focuses the score on new lines rather than copied context. The terms tok⁡(zk)\operatorname{tok}(z_k)tok(zk​) and ∣ak∣|a_k|∣ak​∣ penalize the size of the localized code and the number of extra reads, respectively, preventing the model from simply selecting the entire repository. The weights are set as wk=softmax⁡k(sk/τ)w_k = \operatorname{softmax}_k(s_k / \tau)wk​=softmaxk​(sk​/τ), with τ\tauτ chosen per task to maintain a target effective sample size.

The training pipeline avoids memorization by splitting the training tasks into two folds, A and B. Models trained on one fold are used exclusively to propose and score candidates for the other fold. This ensures that every task is handled by models that have not seen it during training.

For each task, the localizer from the opposite fold proposes K=8K=8K=8 localizations. These are combined with the teacher's localization and simple variants, yielding an average of 7.1 candidates per task after deduplication. The fixer from the opposite fold then scores each candidate with a single forward pass, requiring no gradient computation or test execution.

The resulting scores are converted into weights. For each task, the three candidates with the highest weights are retained, along with the teacher's localization as an anchor to prevent the localizer from drifting. The deployed localizer is then fine-tuned on these weighted candidates using a weighted negative log-likelihood loss, augmented by an anchor term on the teacher's localization:

Lloc⁡(ϕ)=−∑i∑kwiklog⁡pϕ(zik∣xi,Ri)−β∑ilog⁡pϕ(ziteacher⁡∣xi,Ri).\mathcal{L}_{\operatorname{loc}}(\phi) = - \sum_{i} \sum_{k} w_{ik} \log p_{\phi}(z_{ik} \mid x_i, R_i) - \beta \sum_{i} \log p_{\phi}(z_i^{\operatorname{teacher}} \mid x_i, R_i).Lloc​(ϕ)=−i∑​k∑​wik​logpϕ​(zik​∣xi​,Ri​)−βi∑​logpϕ​(ziteacher​∣xi​,Ri​).

This process constitutes ordinary weighted supervised fine-tuning without online rollouts or test runs. While the full method can alternate between retraining the fixer and the localizer, the authors run a single round and update only the localizer.

Experiment

This work evaluates LoRA adapters trained on Gemma 4 E4B for repository-level code repair, comparing a single-agent baseline, two-stage localizer-fixer systems, and stage-3 models trained with EM targets on 78 development tasks under the competition harness. The offline and end-to-end results indicate that EM targets are as useful as teacher localizations for the fixer while using less code, but they do not significantly improve solved tasks over the matched control, and the single agent remains the most robust system. The main limitations are constrained inference time, low-temperature repetition loops, temperature-dependent trade-offs between timeouts and wrong patches, and trained localizers assuming code layouts that do not exist in many repositories.

Data collection was the dominant project expense, driven mainly by teacher trajectories and a smaller recall-cleaning cost. GPU time for training and all Stage 3 work totaled about 130 A100 GPU hours. In the associated experiments, the single agent was the most robust, while two-agent systems were more likely to run out of budget, enter repetition loops, and use incorrect repository paths. Teacher trajectories were the largest data cost, far exceeding recall cleaning. Training and Stage 3 GPU use was about 130 A100 GPU hours. Single-agent runs were more robust than two-agent runs, which solved fewer tasks and showed more repetition and path errors.

The training dataset contains 9,173 records and about 90 million tokens, covering single-agent, fixer, and localizer trajectories. Single-agent records are the longest per record and have the highest share of tokens with a loss, while fixer trajectories contribute the most total tokens, especially the noisy-fix variant. Localizer records are much shorter and have the lowest trained-token shares. Single-agent trajectories have the largest median and tail token counts per record and the highest trained-token share. The noisy fixer role adds the most total tokens and the most records, despite spanning fewer unique tasks than the single-agent split. Localizer trajectories are consistently shorter than single-agent and fixer trajectories, with lower shares of trained tokens. Combining edited and viewed code in the S3 localizer yields a slightly higher trained-token share than either S2 localizer variant alone.

An offline test on 1,016 training tasks shows that starting the fixer from the highest-weight candidate is comparable to starting from the teacher localization for editing and patch-related location outcomes. The highest-weight candidate is substantially smaller and causes fewer context overflows. Exact patch reproduction is rare for either input, while the fixer usually selects an alternative to the teacher localization. The highest-weight candidate and teacher localization produce nearly identical first-edit patched-location and any-edit rates, but the highest-weight candidate cuts localization size by 27.5% and context overflows by 44%. The fixer rarely uses the teacher localization as-is, preferring another candidate on 83% of tasks, and still prefers an alternative on 86% without the size penalty; localizer proposals and edited functions alone are the most common alternatives.

Trained agents make far fewer incorrect patches than the base model, but they explore longer and most tasks then run out of time or tool calls. The single-agent setup is the most robust, solving up to 11 tasks while two-agent systems solve 4 to 8 tasks and show more repetition loops and missing-path or missing-file errors. None of the solved-task differences reaches statistical significance. Low-temperature trained agents produce far fewer wrong patches than the base model, but most tasks run out of budget. At higher temperature, agents hit the budget less often but leave many more wrong patches, with solved tasks staying flat. The single-agent system is more robust than two-agent variants, with fewer loops and far fewer missing-path or missing-file errors.

The experiments evaluate data collection costs, training-data composition, fixer initialization, and agent robustness. Teacher trajectories dominate data expenses, while training and Stage 3 require about 130 A100 GPU hours. An offline test shows that starting the fixer from the highest-weight candidate matches teacher localization on editing and patch-related location outcomes while reducing context overflows. Trained agents produce fewer incorrect patches than the base model but often run out of budget, and single-agent systems are more robust than two-agent variants, which show more repetition loops and missing-path or missing-file errors.


AIでAIを構築

アイデアからローンチまで — 無料のAIコーディング支援、すぐに使える環境、最高のGPU価格でAI開発を加速。

AI コーディング補助
すぐに使える GPU
最適な料金体系

HyperAI Newsletters

最新情報を購読する
北京時間 毎週月曜日の午前9時 に、その週の最新情報をメールでお届けします
メール配信サービスは MailChimp によって提供されています