Papers
Topics
Authors
Recent
Search
2000 character limit reached

PAFT: Preservation Aware Fine-Tuning for Minimal-Edit Program Repair

Published 3 Apr 2026 in cs.SE | (2604.03113v2)

Abstract: LLMs are effective for automated program repair, but plausible patches that pass the full test suite often rewrite more code than necessary, increasing review and maintenance costs. This over-editing is common because most bugs are localized, while standard supervised fine-tuning provides no explicit signal about which tokens should be preserved and which should be changed. We propose PAFT, a preservation-aware fine-tuning method for minimal-edit program repair. PAFT derives token-level preservation signals by aligning buggy and fixed code, combines them with full-sequence masking, and applies an edit-difficulty curriculum. Across Defects4J and HumanEval-Java, PAFT improves pass@1 by up to 65.6% over standard supervised fine-tuning (StdFT) while reducing average edit distance (AED) by up to 32.6%. On Defects4J with DeepSeek-Coder-6.7B, PAFT also outperforms AdaPatcher, a strong preference-based repair baseline, improving pass@1 from 5.9% to 10.1% while reducing median AED from 61.0 to 42.0. Overall, PAFT preserves stable context and concentrates edits on faulty regions, yielding smaller, more localized, plausible patches without inference-time search, reranking, or post-processing.

Summary

  • 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

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.

  1. 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.
  2. 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 walignw_\textrm{align}, encouraging models to maximize alignment on stable spans.
  3. 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.
  4. 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

    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

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.0w_\textrm{align}=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).

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We found no open problems mentioned in this paper.

Collections

Sign up for free to add this paper to one or more collections.