Introduction
MFTCoder is a novel multi-task fine-tuning framework designed to enable Large Language Models (LLMs) to master multiple coding tasks simultaneously. By leveraging task synergies and addressing common pitfalls like data imbalance and inconsistent convergence, the framework significantly enhances model performance. Using this methodology, the researchers developed CodeFuse-CodeLlama-34B, which achieved a state-of-the-art 74.4% pass@1 on HumanEval, notably surpassing the zero-shot performance of GPT-4.
The Challenge: Breaking the Silos
Traditionally, fine-tuning Code LLMs has followed a "siloed" approach, where models are trained on specific datasets for isolated tasks like code completion or summarization. This approach suffers from two primary flaws:
- Resource Inefficiency: Deploying separate models for every specific task (repair, translation, unit testing) is prohibitively expensive.
- Missed Synergies: Coding tasks are inherently related; for instance, understanding how to complete a function often aids in summarizing it. Single-task training fails to leverage this "cross-pollination" of knowledge.
While previous multi-task attempts existed, they often struggled with data imbalance—where large datasets drown out smaller ones—and uneven convergence, where one task reaches optimization while others remain under-trained.
The MFTCoder Framework
MFTCoder addresses these challenges through several technical optimizations designed to handle multiple tasks in parallel.
Balanced Loss and Convergence
To prevent the model from favoring tasks with higher data volume, MFTCoder introduces a loss function weighted by the number of "valid tokens" (actual code tokens versus padding). Additionally, Focal Loss is implemented at both the sample and task levels to force the model to prioritize harder, less-optimized tasks. The framework also utilizes dynamic convergence balancing, adjusting task weights during training based on validation loss gradients to ensure all tasks reach their optimal state simultaneously.
Efficient Tokenization: Pack Mode
Standard fine-tuning often wastes over 90% of sequence length on padding tokens. MFTCoder introduces "Pack Mode," which stitches multiple training samples into a single sequence. This reduces padding to less than 10%, significantly boosting training speed and resource utilization.
Data Engineering and Benchmarking
The researchers utilized a mix of high-quality instruction datasets, including self-instructed data generated via GPT-3.5/4 and the newly open-sourced CodeExercise-Python-27k dataset. Evaluation was conducted across several standard benchmarks, including HumanEval (Python), HumanEval-X (Multilingual), MBPP, and DS-1000.
To test generalization, the team used Text-to-SQL datasets (such as WikiSQL and Spider) as "unseen" tasks. The results were striking: the MFT model achieved 2.25x higher logical accuracy on the Spider benchmark than a standard mixed-data model, despite neither having seen SQL data during fine-tuning.
Key Results and Insights
- The Multi-Task Advantage: A model trained on five tasks simultaneously (MFT) performs better on each individual task than a model trained specifically for only one of those tasks.
- HumanEval SOTA: CodeFuse-CodeLlama-34B reached a 74.4% pass@1, outperforming the base CodeLlama (53.7%) and GPT-4 (67%).
- Efficiency Gains: The "Pack" tokenization mode provided a 2x speedup in training compared to traditional methods by eliminating redundant padding.
- Multilingual Mastery: On HumanEval-X, the MFT model showed superior performance across Java, C++, and Go, proving that multi-tasking helps bridge the gap between different programming languages.
Conclusion and Future Work
MFTCoder demonstrates that multi-task fine-tuning is not just a matter of efficiency, but a path to more robust, fundamental code logic understanding. Future research will focus on optimizing "task taxonomies"—determining which functional abilities (e.g., completion vs. translation) pair best together—and reducing the computational overhead of dynamic convergence balancing. The team is also exploring Mixture of Experts (MoE) architectures to allow for even greater specialization within the multi-task framework.
Summary updated