TL;DR
Standard supervised fine-tuning (SFT) treats all code tokens equally, leading large language models (LLMs) to make subtle, critical logic errors in otherwise well-structured code. This paper introduces Fault-Guided Fine-Tuning (FGIT), a method that identifies these "error-sensitive segments" using multi-granularity code differences and dynamically prioritizes them during training via adaptive loss weighting. FGIT yields an average 6.9% relative improvement on pass@1, enabling 7B open-source models to outperform closed-source alternatives like GPT-3.5-Turbo on key benchmarks.
What Problem Does This Paper Address?
While modern code-generation LLMs achieve impressive scores on standard benchmarks, they frequently suffer from a frustrating issue: they generate code that looks perfectly plausible but fails due to minor, critical bugs (e.g., forgetting to handle a zero input, or an off-by-one error in a loop index).
The authors argue that this stems from a fundamental limitation of standard Supervised Fine-Tuning (SFT). Standard SFT optimizes cross-entropy loss uniformly across all tokens. As a result, a high-stakes conditional statement that determines code correctness receives the exact same optimization priority as a generic variable declaration or a routine syntax token. To fix this, the authors define these critical decision points as error-sensitive segments and propose a fine-tuning curriculum that forces the model to focus on them.
Methods
FGIT introduces a two-component pipeline designed to refine an already instruction-tuned LLM:
-
Error-Sensitive Segments Identification: To find where code typically goes wrong, the authors use a strong teacher model (Qwen2.5-Coder-32B-Instruct) to generate similar but functionally incorrect variants of correct code solutions. They select the most semantically similar incorrect variant using UnixCoder embeddings. Next, they compute differences at two granularities:
-
Line-Level: Using Python's
difflibto find added/deleted lines. - Token-Level: Using the Levenshtein distance algorithm mapped directly to the LLM's tokenizer vocabulary.
These are combined into a Hybrid Level Vector, creating a priority system where tokens that are both inside a modified line and directly altered themselves receive the highest importance.
- Dynamic Importance Reweighting: Instead of uniform token weighting, FGIT modifies the SFT loss function. Inspired by the Bradley-Terry ranking model, it dynamically scales token weights based on the student model's current confusion. If the model assigns similar probabilities to both the correct and incorrect tokens (meaning it struggles to tell them apart), the token weight scales up to a maximum hyperparameter ($\alpha$). If the model can easily discriminate between them, the weight decreases toward a baseline.
Datasets
The authors evaluated their approach using several prominent datasets and benchmarks:
- Training/Fine-Tuning Datasets: Decontaminated versions of Evol-Instruct (the original instruction dataset for MagiCoder), OSS-Instruct, and PYX (used for SemCoder).
- Evaluation Benchmarks: HumanEval(+), MBPP(+), and BigCodeBench (including both the Full and Hard configurations).
Key Insights and Ideas
- Not All Tokens Are Created Equal: Treating syntax boilerplate with the same weight as a critical edge-case condition limits an LLM's functional correctness. Prioritizing the "differentiating" tokens yields better code robustness.
- Learning From Near-Misses: Showing an LLM a "near-miss" incorrect variant helps it map out the exact boundaries of correct logic far better than training on correct examples alone.
- Dynamic vs. Fixed Weighting: Static token weighting doesn't account for what the model already knows. Dynamically scaling weights based on the model's real-time probability outputs ensures training focus shifts dynamically to harder-to-learn patterns, which also naturally mitigates overfitting.
- Universal Post-Processing Power: FGIT works remarkably well even on models whose original training data is proprietary (like CodeLlama-Instruct), proving it can act as an effective, dataset-agnostic refinement step.
Key Results
- Benchmark Superiority: Across seven different LLMs, FGIT achieved an average relative improvement of 6.9% on pass@1.
- Beating Closed-Source Models: The enhanced SemCoder-S (7B) achieved an 83.5% pass@1 on HumanEval+, outperforming GPT-3.5-Turbo (76.8%). Similarly, MagiCoderS-DS (6.7B) outperformed GPT-3.5-Turbo on HumanEval+.
- Impact on Hard Tasks: The benefits of FGIT became even more pronounced on complex tasks. On the challenging BigCodeBench-Hard benchmark, SemCoder-S saw a 20.8% relative performance jump (moving from 16.9% to 20.3% pass@1).
- Defeating Alignment Baselines: FGIT consistently outperformed standard SFT and Direct Preference Optimization (DPO), demonstrating that fine-grained token-level guidance is superior to coarse-grained sequence-level preferences for code generation.
Limitations and Future Work
- Teacher Model Dependency: The quality of the identified error-sensitive segments relies heavily on the teacher model's ability to generate plausible, subtle bugs. The authors plan to experiment with even stronger teacher models like GPT-4-Turbo.
- Hyperparameter Sensitivity: Performance is sensitive to the weight range parameter $\alpha$ and the number of training epochs. Training for too many epochs causes the model to over-focus on error-prone segments, leading it to neglect the surrounding context tokens.
- Scale Constraints: Due to computational resource limits, the experiments primarily focused on 7B parameter models. Validating FGIT on larger scales (e.g., 30B+ or 70B+ models) remains an open direction.
Summary updated