Small code models are often trained to repair their own programs. They write a solution, run it, read the error message, and try again. These models get most of their benefit on the first retry and then stall, repeating code that fails the same tests. The strongest open code models could, in principle, teach small models how to fix code. Two things stand in the way. First, the teacher usually splits text into tokens differently from the student, so the usual way of copying the teacher's probabilities does not apply. Second, most of a repair turn is the student re-copying its previous program, so a naive distillation signal is spent on text the student already reproduces perfectly.
This note proposes to distill the teacher's probabilities only on the bytes that actually change between a failed attempt and a verified fix, the "diff hunks." The hunks are defined on raw characters, not tokens, so they serve as a natural alignment unit between mismatched vocabularies. Concretely, we show the teacher the student's own failed program together with the real execution feedback. We then train the student to match the teacher's likelihood of each edited span, with spans aligned at the byte level. The claim is that this targeted, tokenizer-independent signal lowers stagnation and raises success on later repair rounds. It should do so more than two alternatives: fine-tuning on teacher-written repair text, and cross-tokenizer distillation spread over the whole trajectory.
Core Claim
Holloway and Amin, in Rapid Fixes, Gradual Failures, found three things about self-repair: 57% of successful repairs happen on the first retry, about 45% of non-recovering trajectories stagnate, and recovery is largely a task-level property of what the model can already do. That paper motivates this work. It locates the failure in the student's inability to find where and how to change code after the first retry. It says nothing about how to fix it.
Our hypothesis is that the missing ingredient is dense information at the edit site. At the edit site, the teacher's probability over alternatives encodes which changes are plausible given the traceback. A single sampled fix string throws that away. Elsewhere, teacher and student both put near-certain probability on copying unchanged code, so matching there adds cost and alignment noise but little information.
This is a specific claim about the intersection of the two directions. The research file found no work that performs cross-tokenizer likelihood distillation over execution-grounded, multi-turn repair. Our proposal also departs from the obvious version of that gap, "apply an existing cross-tokenizer method to repair dialogues," in two ways. It restricts the loss to byte-defined diff hunks, and it conditions the teacher on the student's own failures rather than on the teacher's.
Relation to Prior Work
The distillation machinery comes from Approximate Likelihood Matching (ALM), described in Universal Cross-Tokenizer Distillation via Approximate Likelihood Matching and its companion paper. ALM finds "chunks," meaning token runs in both tokenizers that cover the same bytes. It computes each chunk's probability as the product of its token probabilities and matches teacher to student with a binarized divergence. We reuse this method unchanged, except that we choose which chunks count.
ALM was validated on static instruction and math data. There, Gemma2-2B moved to the Qwen2 tokenizer reached an average of 55.1, against 51.6 for supervised fine-tuning and 53.0 for MinED. ALM never saw code, execution feedback, or multi-turn repair.
E-SCOT (Entropy-aware Span-Constrained Optimal Transport) aligns tokens by character offsets and upweights positions where student and teacher disagree in confidence. It constrains our design through a negative result: when vocabulary overlap falls below 25%, heuristic cross-tokenizer methods do worse than plain supervised fine-tuning. Code tokenizers disagree sharply on indentation runs, multi-character operators, and identifier splitting. That makes overlap on source code a live risk, and it is one reason we align on byte-level hunks rather than on tokens.
CTPD (Cross Tokenizer Preference Distillation) also projects tokens to character spans and weights spans by importance, using a contrastive teacher pair on general preference data. Our span weighting is instead dictated by what the program execution changed, not by the teacher's contrastive judgment.
On the refinement side, RefineCoder (Adaptive Critique Refinement) trains on instruction, bad code, critique, then good code trajectories using only the sampled text. It argues explicitly against teacher distillation on the grounds of a performance ceiling. Our proposal tests that argument directly. We keep RefineCoder's trajectory format and add dense teacher likelihoods on the edits.
Anchored Self-Play (Anchored Self-Play for Code Repair) trains a single model as both bug generator and fixer with reinforcement learning. It anchors realism to reference bugs through a frozen code-embedding model. We share its concern that training bugs should look like real bugs, and we meet it by using the student's own failures. Unlike ASP, we transfer from a stronger, differently tokenized teacher.
Token Alignment via Character Matching shows that token-boundary artifacts alone can halve code pass rates: StarCoder rises from 30.25% to 56.58% pass@1 on Subword MBXP once they are fixed. This supplies evidence that boundary handling matters in code, and we reuse its character-trie idea for snapping hunk edges.
Research Program
We first collect repair trajectories on the student's own behavior. For each training task, the student samples an attempt, which is executed in a sandbox using the mxeval harness. Failed attempts are paired with their traceback or failing assertion.
A verified fix for each failure comes from one of two sources. Preferably, it is one of the student's own later samples that passes the tests. When no such sample exists, it is a teacher-generated fix that passes. Each pair of failed attempt and fix is compared at the byte level, and the resulting hunks are widened to the nearest byte positions that are chunk boundaries in both tokenizers. This widening is where indentation and operator splits get absorbed.
Next we score each hunk twice. The teacher sees the specification, the student's failed code, and the feedback in its own tokenization. The student sees the same content in its tokenization. Let $\mathcal{H}$ be the set of aligned chunks falling inside diff hunks, and let $p_T(c)$ and $p_S(c)$ be the teacher's and student's probabilities of chunk $c$ given their respective contexts. The training objective is
$$\mathcal{L} = \sum_{c \in \mathcal{H}} w_c\, D_f\big(p_T(c)\,\|\,p_S(c)\big) + \lambda\, \mathcal{L}_{\text{LM}},$$
where $D_f$ is ALM's binarized $f$-divergence, $w_c$ weights each chunk, and $\mathcal{L}_{\text{LM}}$ is the ordinary next-token loss on the fix. The weights $w_c$ are uniform by default, and a variant scales them by how far the teacher's and student's chunk probabilities diverge. The coefficient $\lambda$ balances the two terms using ALM's gradient-magnitude balancing.
The next-token loss covers the whole fix. The student therefore still learns to copy unchanged code, while the teacher signal is spent only where the program changed.
Then we iterate. After training, the student generates new failures, and we repeat the collection and training steps for three rounds, mirroring RefineCoder's three iterations.
In parallel, we measure the byte-level and token-level vocabulary overlap between teacher and student on code specifically. This places each student pair relative to E-SCOT's 25% threshold.
For the concrete setup, the teacher is a Qwen-family code model. The main students are Llama-3.2-1B and Gemma-2-2B, which have tokenizers different from the teacher's. A control student shares the teacher's tokenizer. With the control, ordinary token-level distillation is possible and serves as an upper reference.
Baselines
The naive reference is the untrained student, prompted to repair its code with feedback for up to $K$ rounds. It is evaluated both with and without the history of previous attempts, since Holloway and Amin found that full history can hurt on MBPP+.
The strongest existing competitor is text-only trajectory fine-tuning in the style of RefineCoder. The student is fine-tuned on exactly the same (spec, failed code, feedback, verified fix) trajectories, without teacher probabilities. RefineCoder-QW-7B reports 83.3 pass@1 on HumanEval+ and 21.7 averaged over LiveCodeBench and BigCodeBench-hard after three iterations. Those numbers are for a 7B student under their own data, so we treat them as context, not a target. We rerun the method on our students with identical trajectories, the same number of optimizer steps, and the same learning-rate search budget. This is the baseline that matters most, because the only difference is the dense teacher signal. Beating it means a higher pass rate after round $K$, and a lower stagnation rate, beyond seed variance across three training seeds.
The second competitor is full-trajectory cross-tokenizer distillation: ALM, and separately E-SCOT, applied to every aligned chunk of the fix rather than to hunks only. It uses the same data, the same teacher forward passes, and the same tuning budget. This is the "obvious" combination, and it isolates whether localizing to hunks is what helps.
A matched-length ablation distills on randomly placed spans of the same total byte length as the hunks. This separates "fewer, targeted chunks" from "fewer chunks." A second ablation replaces the student's own failures with teacher-written failed attempts, to test whether on-policy failures matter.
The same-tokenizer control student, trained with ordinary token-level KL on hunks, bounds how much our method loses to cross-tokenizer approximation.
We report teacher compute (forward passes and tokens) for every method, so that dense distillation is not credited for extra compute.
Why not just…?
Why not just fine-tune on the teacher's verified repairs? This is the serious threat. RefineCoder shows text-only trajectory training works well, and cross-tokenizer distillation has a documented failure mode at low overlap. The matched comparison above settles it. If hunk-localized distillation does not beat text-only fine-tuning on round-$K$ pass rate by more than seed noise, the dense signal is not worth its cost for repair, and we will report that. Our specific prediction is that the gap appears mainly on tasks where the untrained student failed every seed. In Holloway and Amin's study, recovery on such tasks was only 22.9% for the models they tested. A single fix string gives the student one path there, whereas a probability profile over the edit site gives it several.
Why not just pick a teacher with the same tokenizer? Sometimes one can, and our control student measures what that buys. But the student vocabularies practitioners want are often fixed by other constraints: compact vocabularies, byte-level models, or a different model family already deployed. The best code teacher rarely matches them. The question is whether cross-tokenizer transfer can approach the same-tokenizer result on code. The gap between the two students answers it directly.
Why not just spend the budget on more samples instead of refinement? Since most repair gains come in round one, sampling many independent attempts might match refinement. AuPair (Golden Example Pairs for Code Repair) reports that repair-oriented prompting reached 51.32% on CodeForces at 144 calls, against about 16% for plain sampling and self-repair baselines, which suggests repair is not trivially replaced by sampling. We still compare every trained student against best-of-$N$ sampling from the same student at an equal number of model calls.
Why not just use reinforcement learning with test rewards? Anchored Self-Play shows reinforcement learning on repair helps: +7.0 points over standard self-play on BugSourceBench. However, it needs many rollouts per update and still has to correct drift toward unrealistic bugs. Our method is a supervised objective on existing trajectories, so it is complementary rather than competing. As a secondary check, we test whether a hunk-distilled student makes a better starting point for such training.
Proposed Experiments
We evaluate on HumanEval+ and MBPP+ for Python repair and on LiveCodeBench for harder, contamination-resistant problems. We use HumanEval-Java for a strictly typed language, where Holloway and Amin found repair degrades 30–50% faster per iteration than in Python. The LLMTrans split of CodeTransOcean covers translation with compiler feedback. On LLMTrans, ChatGPT moved from a debugging success rate of 48.57% at zero rounds to 52.57% at three rounds (CodeTransOcean). For our 1–2B students on this setup, we found no reported result on Lacuna, so baselines will be run by us.
Our metrics are pass rate after each of ten repair rounds, and the fraction of all successes that occur after round one. We also track the stagnation rate, meaning trajectories whose test-pass fraction is unchanged for three consecutive rounds, and the recovery rate on tasks where every seed initially failed.
The decisive checks are three. First, hunk-localized distillation must beat text-only trajectory fine-tuning on round-10 pass rate and stagnation, with the advantage concentrated after round one and on tasks that all seeds failed. If the gain appears only on round one, it is ordinary capability transfer, not better repair. Second, it must beat full-trajectory ALM and the matched random-span ablation. Otherwise, localization is not the active ingredient. Third, its benefit over text-only fine-tuning should shrink as measured code-vocabulary overlap falls. If it instead collapses below text-only fine-tuning at low overlap, as E-SCOT's findings would predict for token-level methods, byte-level hunk alignment did not solve the alignment-noise problem. That result would itself be informative about how cross-tokenizer distillation behaves on source code.
References
- Rapid Fixes, Gradual Failures: Exploring Iterative Self-Correction Dynamics in Large Language Models for Program Synthesis
- Universal Cross-Tokenizer Distillation via Approximate Likelihood Matching
- Cross-Tokenizer Distillation via Approximate Likelihood Matching
- Entropy-aware Span-Constrained Optimal Transport for Robust Cross-Tokenizer Knowledge Distillation
- CTPD: Cross Tokenizer Preference Distillation
- RefineCoder: Iterative Improving of Large Language Models via Adaptive Critique Refinement for Code Generation
- Anchored Self-Play for Code Repair
- Token Alignment via Character Matching for Subword Completion
- AuPair: Golden Example Pairs for Code Repair
- CodeTransOcean: A Comprehensive Multilingual Benchmark for Code Translation