- The paper introduces PAFT, a method that uses token-level alignment to guide minimal edits by preserving stable code regions.
- It employs full-sequence masking and a curriculum-based approach to optimize edit scope, significantly improving pass@1 and reducing average edit distance.
- Empirical results show PAFT outperforms standard SFT and advanced baselines by enhancing code consistency and localized repair, offering practical benefits for APR.
PAFT: Preservation-Aware Fine-Tuning for Minimal-Edit Program Repair
Introduction and Motivation
LLMs have become integral to automated program repair (APR), primarily due to their proficiency in generating plausible patches that pass test suites. However, one persistent failure mode is over-editing—models often produce patches that rewrite more code than necessary. This behavior leads to maintenance overhead, impedes reviewability, and disrupts stable code context, which are undesirable in realistic software engineering pipelines. APR tasks, especially for real-world repositories and educator-facing code, require both functional correctness and minimal perturbation of non-faulty code spans.
The core challenge emerges from the lack of explicit preservation signals during traditional supervised fine-tuning (SFT). These objectives treat the entire output as equally optimal, ignoring that most bugs are localized and that stable code should be preserved whenever feasible. PAFT ("Preservation-Aware Fine-Tuning") directly addresses this shortcoming by introducing token-level alignment-guided supervision, thereby training models to discriminate between stable context and edit-relevant regions.
Figure 1: Motivating example of PAFT illustrating failures of standard SFT and how PAFT enforces more localized, minimal edits.
Methodology
PAFT’s pipeline is defined by three key components: alignment-guided token weighting, full-sequence masking, and curriculum-based instance ordering.
- Token-level Preservation Signal: For each buggy-fixed code pair, PAFT computes deterministic token-level alignments (via Ratcliff/Obershelp-style pattern matching) to identify stable tokens in the patched output that are copied from the buggy input. These aligned positions receive increased loss weight during training, incentivizing copying where possible and focusing generation capacity on true fault regions. This approach is orthogonal to preference-based or RL-based approaches which require additional preference data or complex reward modeling.
- Preservation-Aware Loss Objective: Supervised fine-tuning is performed over quantized LLM adapters (QLoRA) using a masked and weighted loss. The loss function upweights preservation tokens by a coefficient walign, encouraging models to maximize alignment on stable spans.
- Edit-Difficulty Curriculum: Training instances are scheduled in order of increasing line-diff size. The model first learns highly localized edits, then generalizes to larger diffs. This curriculum stabilizes optimization and avoids premature bias toward large-scale rewriting.
- Unified Protocols: All backbones are trained and evaluated using consistent templates, parsing, and decoding protocols. Inference does not require special token masks or preservation signals—benefits accrue fully from the fine-tuning phase.
Figure 2: Overview of the PAFT pipeline—a quantized LLM is fine-tuned using preservation-aware weighting and a diff-size curriculum to emphasize minimal, localized edits.
Experimental Results
Minimal-Edit Behavior and Metric Validity
Empirical evaluation on Defects4J and HumanEval-Java with standard LLM backbones demonstrates that state-of-the-art models consistently over-edit. Metrics such as average edit distance (AED) and code consistency rate (CCR) show weak coupling with pass@k and, crucially, human annotation studies confirm AED is a stronger operational proxy for patch reviewability and edit faithfulness.
Benchmarks and Baseline Comparisons
Across both benchmarks (Defects4J for project-level, HumanEval-Java for function level), PAFT fine-tuning yields substantial improvements:
- Defects4J/DS-Coder-6.7B: Pass@1 increases from 5.8% (Base) and 6.1% (SFT) to 10.1% (PAFT). AED drops from 142.9 to 80.7, and CCR rises from 70.7 to 76.3.
- HumanEval-Java/OpenCoder-8B: Pass@1 improves from 33.0% (SFT) to 50.4% (PAFT), AED reduces from 100.4 to 74.2, and CCR increases from 69.9 to 74.8.
Notably, PAFT outperforms AdaPatcher, RepairLLaMA, and advanced prompting-based approaches. Gains are not limited to average metrics—distributional analysis reveals left-shifted AED distributions and enhanced patch locality.
Figure 3: AED distributions on Defects4J for DS-Coder-6.7B and its variants. PAFT consistently decreases both mean and median edit distance, tightening edit scopes beyond all compared methods.
Component Analysis
Ablation studies with DS-Coder-6.7B isolate the incremental effect of each PAFT component:
- SFT alone mostly reduces AED (from 142.9 to 93.5) without boosting pass@1.
- Full-sequence masking and curriculum increase CCR but may amplify aggressive edits unless preservation weighting is active.
- Optimal walign=2.0 delivers the best correctness-locality trade-off. Underweighting or overweighting aligned tokens either diminishes correctness or over-regularizes toward copying.
Baselines and Oracle Selection
PAFT’s single-pass, training-centric approach outperforms both prompt-based minimality instructions and post-hoc or sample-selection strategies. Even with Min@10 AED or Max@10 CCR (optimistic oracle selection among k=10 outputs), baseline models cannot match the median or average edit locality achieved by PAFT’s default configuration.
Implications and Future Directions
The findings establish that controlling edit locality must be embedded in training objectives, not left to inference or prompting. Explicit preservation signals in LLM fine-tuning:
- Yield smaller, better-localized, and more reviewable patches, which aligns with practical code review preferences.
- Achieve higher functional accuracy, not by shrinking diffs indiscriminately, but by targeting changes to actual faults while copying stable content.
- Outperform preference-learning frameworks (e.g., AdaPatcher, DPO) in both metric and instance-level analyses using simpler supervision that does not require preference or reward data.
From a theoretical standpoint, PAFT’s lightweight, alignment-based approach introduces a new inductive bias for controlled code generation. Practically, this suggests that future APR systems should jointly optimize for both semantic plausibility and fidelity to the input’s stable structure, leveraging alignment-guided objectives.
Future research should expand PAFT to multi-file defects, cross-language repair, or integrate with explicit semantic equivalence checkers. Combined use with task capability-oriented adaptation could yield further improvements.
Conclusion
PAFT demonstrates preservation-aware fine-tuning is an effective paradigm for APR. It achieves simultaneous improvements in correctness and patch minimality over SFT and advanced baselines, with strong empirical backing from both automated metrics and human annotation. The results suggest that future work in code LLM alignment should focus on integrating explicit context-preservation signals at the training phase, enabling models to meet the dual objectives of functionality and maintainable code change scopes (2604.03113).