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

👤 作者: Boyang Yang, Zijian Cai, Shunfu Jin, Haoye Tian

论文速览

Automated program repair using large language models (LLMs) has shown promise, but current approaches often generate patches that rewrite more code than necessary. This over-editing increases the burden on developers for code review and maintenance, as most bugs are localized and require minimal changes. Standard supervised fine-tuning methods fail to provide explicit guidance on preserving stable code regions, leading to unnecessarily extensive edits. Addressing this issue is crucial for improving the efficiency and practicality of automated program repair systems.

The proposed method, PAFT (Preservation-Aware Fine-Tuning), introduces a novel approach to minimize edits while repairing code. PAFT leverages token-level preservation signals by aligning buggy and fixed code, combines these signals with full-sequence masking, and employs an edit-difficulty curriculum to focus on localized changes. Experimental results demonstrate that PAFT significantly improves repair accuracy and efficiency across benchmarks like Defects4J and HumanEval-Java. For instance, PAFT enhances pass@1 rates by up to 65.6% compared to standard fine-tuning and reduces average edit distance by up to 32.6%. Furthermore, PAFT outperforms AdaPatcher, a strong baseline, by improving pass@1 from 5.9% to 10.1% while reducing median edit distance. By concentrating edits on faulty regions and preserving stable context, PAFT delivers smaller, more targeted patches, streamlining the program repair process without requiring additional inference-time adjustments.

📖 论文核心内容

1. 主要解决了什么问题?

The core problem addressed in this paper is the issue of over-editing in automated program repair using large language models (LLMs). While LLMs can generate plausible patches that pass test suites, these patches often rewrite more code than necessary, leading to increased review and maintenance costs. This over-editing occurs because most bugs are localized, yet standard supervised fine-tuning methods lack explicit signals to distinguish between tokens that should be preserved and those that should be changed. The research gap lies in the absence of fine-tuning techniques that prioritize minimal edits while maintaining patch plausibility. This problem is significant because excessive code modifications can introduce new errors, complicate code reviews, and reduce developer trust in automated repair tools, ultimately hindering their adoption in real-world software development workflows.

2. 提出了什么解决方案?

The paper proposes PAFT (Preservation-Aware Fine-Tuning), a novel fine-tuning method designed to address the over-editing problem in automated program repair. PAFT introduces token-level preservation signals by aligning buggy and fixed code, enabling the model to focus on minimal and localized edits. It combines these preservation signals with full-sequence masking and an edit-difficulty curriculum to guide the fine-tuning process. Unlike existing approaches, PAFT explicitly incorporates preservation awareness into the training process, ensuring that stable code regions remain unchanged while edits are concentrated on faulty areas. This approach eliminates the need for inference-time search, reranking, or post-processing, setting it apart from other methods like AdaPatcher and standard supervised fine-tuning (StdFT).

3. 核心方法/步骤/策略

The methodology of PAFT involves three key components: token-level preservation signals, full-sequence masking, and an edit-difficulty curriculum. First, token-level preservation signals are derived by aligning buggy and fixed code, identifying which tokens should remain unchanged. These signals are then integrated into the fine-tuning process to guide the model toward minimal edits. Second, full-sequence masking is used to train the model to predict the entire sequence while respecting the preservation signals, ensuring that stable context is maintained. Third, an edit-difficulty curriculum is employed, gradually introducing more complex edits during training to improve the model's ability to handle diverse repair scenarios. The implementation leverages the DeepSeek-Coder-6.7B model and fine-tunes it on datasets like Defects4J and HumanEval-Java, ensuring robust evaluation across different programming contexts.

4. 实验设计

The experimental design evaluates PAFT on two datasets: Defects4J and HumanEval-Java. Key metrics include pass@1, which measures the percentage of patches that pass the test suite on the first attempt, and average edit distance (AED), which quantifies the extent of code modifications. PAFT achieves significant improvements, with pass@1 increasing by up to 65.6% over standard supervised fine-tuning and AED decreasing by up to 32.6%. On Defects4J, PAFT outperforms AdaPatcher, a strong baseline, improving pass@1 from 5.9% to 10.1% and reducing median AED from 61.0 to 42.0. These results demonstrate that PAFT not only generates more plausible patches but also minimizes unnecessary edits, validating its effectiveness in addressing the over-editing problem.

5. 结论

The paper concludes that PAFT effectively addresses the over-editing problem in automated program repair by preserving stable code regions and focusing edits on faulty areas. The method achieves state-of-the-art performance on multiple benchmarks, significantly improving both patch plausibility and edit minimality. However, the authors acknowledge limitations, such as the reliance on specific datasets and the potential need for further generalization to other programming languages or repair scenarios. Future directions include extending PAFT to handle multi-line or structural bugs, integrating it with other repair frameworks, and exploring its applicability in real-world software development environments. Overall, PAFT represents a meaningful advancement in the field of automated program repair, balancing patch quality with minimal code disruption.

🤔 用户关心的问题

  • How does PAFT's token-level preservation signal mechanism contribute to the localization of bugs and the generation of minimal-edit patches compared to standard fine-tuning methods? This question probes the core innovation of PAFT and aligns with the user's interest in how LLMs localize bugs and generate patches with minimal edits. It seeks to understand the specific role of token-level preservation signals in improving repair outcomes.
  • What types of bugs (e.g., semantic, syntax, vulnerability) were addressed in the Defects4J and HumanEval-Java datasets, and how did PAFT perform across these different bug types? The user is interested in repair performance across different bug types. This question explores whether PAFT's methodology is equally effective for various bug categories and how its performance varies depending on the nature of the bug.
  • How does PAFT's edit-difficulty curriculum influence the model's ability to generate plausible patches, and how does this compare to other curriculum-based or preference-based approaches like AdaPatcher? This question examines the role of the edit-difficulty curriculum in improving patch plausibility and contrasts PAFT with other approaches, addressing the user's interest in methods that enhance patch generation reliability.
  • What metrics or techniques were used to evaluate patch correctness and plausibility in PAFT, and how do these metrics ensure reliable validation of repairs? The user is interested in patch validation. This question focuses on the evaluation framework used in the paper, including metrics like pass@1 and AED, and how they contribute to assessing the reliability of generated patches.
  • Does PAFT incorporate any static or dynamic analysis techniques to improve the reliability of repairs, and if not, how might such techniques complement PAFT's approach? The user is interested in the interaction between LLM-based repair methods and static/dynamic analysis. This question explores whether PAFT leverages such techniques and invites discussion on potential synergies.

💡 逐项解答

How does PAFT's token-level preservation signal mechanism contribute to the localization of bugs and the generation of minimal-edit patches compared to standard fine-tuning methods?

PAFT's token-level preservation signal mechanism plays a pivotal role in improving bug localization and generating minimal-edit patches compared to standard fine-tuning methods. The paper highlights that standard supervised fine-tuning (StdFT) often fails to distinguish between tokens that need modification and those that should remain unchanged, leading to over-editing and increased maintenance costs. In contrast, PAFT introduces a preservation-aware approach by deriving token-level preservation signals through alignment between buggy and fixed code. This alignment allows PAFT to "preserve stable context and concentrate edits on faulty regions," ensuring that only the necessary changes are made while leaving the rest of the code intact.

The significance of this mechanism is evident in the quantitative improvements reported. For instance, PAFT achieves up to a 65.6% improvement in pass@1 over StdFT and reduces the average edit distance (AED) by up to 32.6% across benchmarks like Defects4J and HumanEval-Java. These metrics underscore PAFT's ability to generate smaller, more localized patches, which are easier to review and maintain. Furthermore, when tested against AdaPatcher, a strong preference-based repair baseline, PAFT not only improves pass@1 from 5.9% to 10.1% but also reduces the median AED from 61.0 to 42.0. This demonstrates that PAFT's preservation signals effectively guide the model to focus on faulty regions, minimizing unnecessary edits and enhancing repair precision.

The token-level preservation signals are further reinforced by PAFT's use of an edit-difficulty curriculum, which gradually exposes the model to increasingly complex repair tasks. This curriculum complements the preservation signals by ensuring that the model learns to prioritize minimal edits even in challenging scenarios. Overall, PAFT's innovative mechanism addresses the limitations of standard fine-tuning by aligning the repair process with the localized nature of most bugs, resulting in more efficient and targeted program repair outcomes.

信心指数: 1.00

What types of bugs (e.g., semantic, syntax, vulnerability) were addressed in the Defects4J and HumanEval-Java datasets, and how did PAFT perform across these different bug types?

The paper "PAFT: Preservation Aware Fine-Tuning for Minimal-Edit Program Repair" provides insights into the types of bugs addressed in the Defects4J and HumanEval-Java datasets, as well as the performance of PAFT across these categories. Defects4J primarily focuses on real-world bugs extracted from Java projects, encompassing a variety of bug types such as semantic errors, logical flaws, and API misuse. HumanEval-Java, on the other hand, includes synthetic programming tasks designed to evaluate code correctness, often targeting logical and semantic issues. While the paper does not explicitly categorize bugs into semantic, syntax, or vulnerability types, the emphasis on localized edits suggests that PAFT is particularly effective for addressing semantic and logical errors, where minimal changes can resolve the issue without altering stable code regions.

PAFT's methodology leverages token-level preservation signals to focus edits on faulty regions, which is critical for handling semantic and logical bugs. The authors highlight that 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%." This performance improvement underscores its ability to generate precise patches that align closely with the original code structure, a key requirement for fixing semantic bugs without introducing new issues. On Defects4J, PAFT outperformed AdaPatcher, a strong baseline, by increasing pass@1 from 5.9% to 10.1% and reducing the median AED from 61.0 to 42.0. These results indicate that PAFT excels in scenarios where minimal and targeted edits are necessary, which is often the case for semantic and logical errors.

However, the paper does not provide detailed analysis or metrics specific to syntax errors or security vulnerabilities. The focus on "preserving stable context" and minimizing edits suggests that PAFT may be less suited for bugs requiring extensive code rewrites or those involving complex security vulnerabilities. Overall, PAFT demonstrates strong performance in addressing localized semantic and logical bugs, but its effectiveness across other bug types, such as syntax errors or vulnerabilities, remains less clear based on the available evidence.

信心指数: 0.85

How does PAFT's edit-difficulty curriculum influence the model's ability to generate plausible patches, and how does this compare to other curriculum-based or preference-based approaches like AdaPatcher?

The edit-difficulty curriculum introduced by PAFT plays a pivotal role in enhancing the model's ability to generate plausible patches by systematically guiding the fine-tuning process to focus on minimal and localized edits. According to the paper, PAFT leverages token-level preservation signals derived from aligning buggy and fixed code, which are then combined with a curriculum that progressively increases the difficulty of edits during training. This approach ensures that the model learns to prioritize stability in the codebase while concentrating changes on the faulty regions. The authors highlight that 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%," demonstrating its effectiveness in generating smaller, more plausible patches.

When compared to AdaPatcher, a preference-based repair method, PAFT exhibits superior performance. AdaPatcher relies on preference modeling to rank patches based on plausibility, but PAFT achieves better results without the need for inference-time search or reranking. Specifically, on the Defects4J benchmark with DeepSeek-Coder-6.7B, PAFT improves pass@1 from 5.9% to 10.1% and reduces median AED from 61.0 to 42.0. This reduction in edit distance underscores PAFT's ability to produce more localized fixes, which are easier to review and maintain. The paper emphasizes that PAFT’s curriculum-driven approach "preserves stable context and concentrates edits on faulty regions," a key advantage over preference-based methods that may generate plausible but overly broad patches.

Overall, PAFT's edit-difficulty curriculum not only enhances patch plausibility but also addresses the common issue of over-editing seen in standard fine-tuning approaches. By focusing on minimal edits and leveraging preservation-aware signals, PAFT outperforms both traditional supervised methods and preference-based approaches like AdaPatcher, making it a robust solution for automated program repair.

信心指数: 1.00

What metrics or techniques were used to evaluate patch correctness and plausibility in PAFT, and how do these metrics ensure reliable validation of repairs?

The paper evaluates patch correctness and plausibility using two primary metrics: pass@1 and Average Edit Distance (AED). Pass@1 measures the proportion of generated patches that pass all test cases on the first attempt, serving as a direct indicator of patch correctness. This metric is particularly significant because it aligns with the ultimate goal of program repair—producing functional code that resolves the bug without introducing new errors. The authors highlight that PAFT improves pass@1 by up to 65.6% over standard supervised fine-tuning (StdFT) and achieves a notable increase from 5.9% to 10.1% when compared to AdaPatcher on Defects4J, demonstrating its effectiveness in generating correct patches.

AED, on the other hand, quantifies the minimality of the edits by calculating the average number of token changes between the buggy and fixed code. This metric ensures that the generated patches are not only correct but also localized and concise, reducing the overhead for developers during code review and maintenance. The paper reports that PAFT reduces AED by up to 32.6% compared to StdFT and decreases the median AED from 61.0 to 42.0 relative to AdaPatcher. By focusing edits on faulty regions while preserving stable context, PAFT addresses the common issue of over-editing, which can complicate patch validation and increase maintenance costs.

Together, these metrics provide a robust framework for validating repairs. Pass@1 ensures functional correctness, while AED emphasizes the efficiency and plausibility of the patches. This dual focus allows PAFT to produce reliable and developer-friendly repairs, balancing correctness with minimal disruption to the original code structure.

信心指数: 1.00

Does PAFT incorporate any static or dynamic analysis techniques to improve the reliability of repairs, and if not, how might such techniques complement PAFT's approach?

The paper on PAFT (Preservation Aware Fine-Tuning for Minimal-Edit Program Repair) does not explicitly mention the use of static or dynamic analysis techniques to enhance the reliability of repairs. Instead, its approach focuses on leveraging token-level preservation signals derived from aligning buggy and fixed code, combined with full-sequence masking and an edit-difficulty curriculum. This methodology aims to reduce over-editing by concentrating changes on faulty regions while preserving stable context. As the authors note, PAFT achieves "smaller, more localized, plausible patches without inference-time search, reranking, or post-processing," which suggests a reliance on the fine-tuning process itself rather than external analysis methods.

While PAFT’s preservation-aware strategy is effective in minimizing edit distance and improving pass@1 rates, integrating static or dynamic analysis techniques could complement its approach by providing additional insights into program behavior and correctness. For example, static analysis could identify potential side effects or dependencies in the code that might be disrupted by a repair, ensuring that the generated patches maintain semantic integrity. Dynamic analysis, on the other hand, could validate the runtime behavior of the patched program against a broader set of test cases, potentially catching edge cases that the fine-tuning process might overlook. These techniques could act as a secondary validation layer, enhancing the robustness of PAFT’s repairs and reducing the risk of introducing new bugs.

In summary, while PAFT does not currently incorporate static or dynamic analysis, these techniques could serve as valuable complements to its preservation-aware methodology. By combining PAFT’s localized editing strategy with the deeper insights offered by analysis tools, future iterations of program repair systems could achieve even higher reliability and maintainability.

信心指数: 0.80

📝 综合总结

PAFT's token-level preservation signal mechanism plays a pivotal role in improving bug localization and generating minimal-edit patches compared to standard fine-tuning methods. The paper highlights that standard supervised fine-tuning (StdFT) often fails to distinguish between tokens that need modification and those that should remain unchanged, leading to over-editing and increased maintenance costs. In contrast, PAFT introduces a preservation-aware approach by deriving token-level preservation signals through alignment between buggy and fixed code. This alignment allows PAFT to "preserve stable context and concentrate edits on faulty regions," ensuring that only the necessary changes are made while leaving the rest of the code intact.

The significance of this mechanism is evident in the quantitative improvements reported. For instance, PAFT achieves up to a 65.6% improvement in pass@1 over StdFT and reduces the average edit distance (AED) by up to 32.6% across benchmarks like Defects4J and HumanEval-Java. These metrics underscore PAFT's ability to generate smaller, more localized patches, which are easier to review and maintain. Furthermore, when tested against AdaPatcher, a strong preference-based repair baseline, PAFT not only improves pass@1 from 5.9% to 10.1% but also reduces the median AED from 61.0 to 42.0. This demonstrates that PAFT's preservation signals effectively guide the model to focus on faulty regions, minimizing unnecessary edits and enhancing repair precision.

The token-level preservation signals are further reinforced by PAFT's use of an edit-difficulty curriculum, which gradually exposes the model to increasingly complex repair tasks. This curriculum complements the preservation signals by ensuring that the model learns to prioritize minimal edits even in challenging scenarios. Overall, PAFT's innovative mechanism addresses the limitations of standard fine-tuning by aligning the repair process with the localized nature of most bugs, resulting in more efficient and targeted program repair outcomes.

The paper "PAFT: Preservation Aware Fine-Tuning for Minimal-Edit Program Repair" provides insights into the types of bugs addressed in the Defects4J and HumanEval-Java datasets, as well as the performance of PAFT across these categories. Defects4J primarily focuses on real-world bugs extracted from Java projects, encompassing a variety of bug types such as semantic errors, logical flaws, and API misuse. HumanEval-Java, on the other hand, includes synthetic programming tasks designed to evaluate code correctness, often targeting logical and semantic issues. While the paper does not explicitly categorize bugs into semantic, syntax, or vulnerability types, the emphasis on localized edits suggests that PAFT is particularly effective for addressing semantic and logical errors, where minimal changes can resolve the issue without altering stable code regions.

PAFT's methodology leverages token-level preservation signals to focus edits on faulty regions, which is critical for handling semantic and logical bugs. The authors highlight that 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%." This performance improvement underscores its ability to generate precise patches that align closely with the original code structure, a key requirement for fixing semantic bugs without introducing new issues. On Defects4J, PAFT outperformed AdaPatcher, a strong baseline, by increasing pass@1 from 5.9% to 10.1% and reducing the median AED from 61.0 to 42.0. These results indicate that PAFT excels in scenarios where minimal and targeted edits are necessary, which is often the case for semantic and logical errors.

However, the paper does not provide detailed analysis or metrics specific to syntax errors or security vulnerabilities. The focus on "preserving stable context" and minimizing edits suggests that PAFT may be less suited for bugs requiring extensive code rewrites or those involving complex security vulnerabilities. Overall, PAFT demonstrates strong performance in addressing localized semantic and logical bugs, but its effectiveness across other bug types, such as syntax errors or vulnerabilities, remains less clear based on the available evidence.

The edit-difficulty curriculum introduced by PAFT plays a pivotal role in enhancing the model's ability to generate plausible patches by systematically guiding the fine-tuning process to focus on minimal and localized edits. According to the paper, PAFT leverages token-level preservation signals derived from aligning buggy and fixed code, which are then combined with a curriculum that progressively increases the difficulty of edits during training. This approach ensures that the model learns to prioritize stability in the codebase while concentrating changes on the faulty regions. The authors highlight that 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%," demonstrating its effectiveness in generating smaller, more plausible patches.

When compared to AdaPatcher, a preference-based repair method, PAFT exhibits superior performance. AdaPatcher relies on preference modeling to rank patches based on plausibility, but PAFT achieves better results without the need for inference-time search or reranking. Specifically, on the Defects4J benchmark with DeepSeek-Coder-6.7B, PAFT improves pass@1 from 5.9% to 10.1% and reduces median AED from 61.0 to 42.0. This reduction in edit distance underscores PAFT's ability to produce more localized fixes, which are easier to review and maintain. The paper emphasizes that PAFT’s curriculum-driven approach "preserves stable context and concentrates edits on faulty regions," a key advantage over preference-based methods that may generate plausible but overly broad patches.

Overall, PAFT's edit-difficulty curriculum not only enhances patch plausibility but also addresses the common issue of over-editing seen in standard fine-tuning approaches. By focusing on minimal edits and leveraging preservation-aware signals, PAFT outperforms both traditional supervised methods and preference-based approaches like AdaPatcher, making it a robust solution for automated program repair.

The paper evaluates patch correctness and plausibility using two primary metrics: pass@1 and Average Edit Distance (AED). Pass@1 measures the proportion of generated patches that pass all test cases on the first attempt, serving as a direct indicator of patch correctness. This metric is particularly significant because it aligns with the ultimate goal of program repair—producing functional code that resolves the bug without introducing new errors. The authors highlight that PAFT improves pass@1 by up to 65.6% over standard supervised fine-tuning (StdFT) and achieves a notable increase from 5.9% to 10.1% when compared to AdaPatcher on Defects4J, demonstrating its effectiveness in generating correct patches.

AED, on the other hand, quantifies the minimality of the edits by calculating the average number of token changes between the buggy and fixed code. This metric ensures that the generated patches are not only correct but also localized and concise, reducing the overhead for developers during code review and maintenance. The paper reports that PAFT reduces AED by up to 32.6% compared to StdFT and decreases the median AED from 61.0 to 42.0 relative to AdaPatcher. By focusing edits on faulty regions while preserving stable context, PAFT addresses the common issue of over-editing, which can complicate patch validation and increase maintenance costs.

Together, these metrics provide a robust framework for validating repairs. Pass@1 ensures functional correctness, while AED emphasizes the efficiency and plausibility of the patches. This dual focus allows PAFT to produce reliable and developer-friendly repairs, balancing correctness with minimal disruption to the original code structure.

The paper on PAFT (Preservation Aware Fine-Tuning for Minimal-Edit Program Repair) does not explicitly mention the use of static or dynamic analysis techniques to enhance the reliability of repairs. Instead, its approach focuses on leveraging token-level preservation signals derived from aligning buggy and fixed code, combined with full-sequence masking and an edit-difficulty curriculum. This methodology aims to reduce over-editing by concentrating changes on faulty regions while preserving stable context. As the authors note, PAFT achieves "smaller, more localized, plausible patches without inference-time search, reranking, or post-processing," which suggests a reliance on the fine-tuning process itself rather than external analysis methods.

While PAFT’s preservation-aware strategy is effective in minimizing edit distance and improving pass@1 rates, integrating static or dynamic analysis techniques could complement its approach by providing additional insights into program behavior and correctness. For example, static analysis could identify potential side effects or dependencies in the code that might be disrupted by a repair, ensuring that the generated patches maintain semantic integrity. Dynamic analysis, on the other hand, could validate the runtime behavior of the patched program against a broader set of test cases, potentially catching edge cases that the fine-tuning process might overlook. These techniques could act as a secondary validation layer, enhancing the robustness of PAFT’s repairs and reducing the risk of introducing new bugs.

In summary, while PAFT does not currently incorporate static or dynamic analysis, these techniques could serve as valuable complements to its preservation-aware methodology. By combining PAFT’s localized editing strategy with the deeper insights offered by analysis tools, future iterations of program repair systems could achieve even higher reliability and maintainability.