Data-efficient LLM Fine-tuning for Code Generation

Weijie Lv, Xuan Xia, Sheng-Jun Huang · DOI

Abstract

Recent advancements in Large Language Models (LLMs) for code generation have largely relied on scaling synthetic datasets. However, this "brute force" approach often introduces noise and computational inefficiency. This paper presents a data-efficient fine-tuning strategy that demonstrates how training on a carefully selected 40% subset of a dataset can outperform training on the full 100%. By integrating a complexity-consistency data selection strategy with a novel "dynamic pack" tokenization technique, we achieve superior performance while reducing training time by 27% and peak GPU memory usage by 30%.

Introduction

Open-source code LLMs, such as DeepSeek-Coder and CodeLlama, are rapidly approaching the capabilities of proprietary models like GPT-4. To bridge the remaining performance gap, researchers typically employ intensive fine-tuning using massive synthetic datasets like OSS-Instruct. While effective, this method faces two primary challenges: inefficiency due to redundant or low-quality samples, and potential performance degradation when low-quality data outweighs high-signal instructions.

This research investigates how to identify the most influential training samples to optimize both model performance and training efficiency. We propose that the quality and relevance of data are more critical than sheer volume, leading to a "less is more" paradigm in code-specific fine-tuning.

Methodology

1. Complexity-Consistency Data Selection

To move beyond random sampling, we developed a two-step selection process designed to maintain the breadth of the original data distribution while prioritizing challenging samples.

  • Consistency (Diversity): We utilize K-Means clustering on sentence embeddings of the instructions. This ensures that the selected subset reflects the broad distribution of the original dataset, preventing the model from over-specializing in a narrow subset of programming tasks.
  • Complexity (Difficulty): Within each cluster, we calculate an Instruction Following Difficulty (IFD) score. This metric measures the model's "surprise" (perplexity) when generating code given an instruction compared to generating it without the instruction. A high IFD score indicates that the mapping from instruction to code is particularly challenging for the model, making it a high-value learning opportunity.

2. Dynamic Pack Tokenization

Standard fine-tuning often involves significant computational waste due to padding tokens used to reach fixed sequence lengths. While traditional "packing" methods exist, they often truncate data to fit context windows. Our Dynamic Pack technique sorts samples by length and intelligently concatenates them to fill the 4,096-token context window as efficiently as possible. This approach minimizes the "padding tax" without truncating code, leading to significant hardware efficiency gains.

Experimental Setup

We validated our approach using two primary training sets:

  • Evol-Instruct: 78,000 samples of iteratively complex code instructions.
  • OSS-Instruct: 75,000 samples seeded from real-world GitHub snippets.

Models were evaluated on industry-standard benchmarks, including HumanEval/HumanEval+ and MBPP/MBPP+, which measure functional correctness in Python code generation.

Results and Discussion

The "U-Shaped" Performance Curve

Our findings reveal a non-linear relationship between data volume and model performance. Performance typically peaks when using only 30-40% of the highest-quality data. Beyond this point, the inclusion of lower-quality or redundant samples leads to a performance decline, suggesting that "noise" in large synthetic datasets can actively harm the model's reasoning capabilities.

Performance Gains

Using the DeepSeek-Coder-Base-6.7B model on the OSS-Instruct dataset, our selection strategy yielded superior results with less data:

  • Accuracy: A subset of 30,000 samples (40%) achieved a score of 66.9%, surpassing the 66.1% achieved by the full 75,000-sample dataset.
  • Efficiency: Training time per epoch was reduced from 47 minutes to 34 minutes.
  • Memory Optimization: Peak GPU memory usage dropped from 61.47 GB to 42.72 GB, significantly lowering the barrier for training on mid-tier hardware.

Resource Utilization

The impact of Dynamic Pack tokenization was particularly evident in the CodeLlama-Python-7B model, where the padding rate was slashed from 54.41% to just 17.23%. This reduction in wasted tokens directly translates to faster throughput and lower energy consumption.

Conclusion

This research demonstrates that data efficiency is a viable and superior alternative to brute-force scaling for code LLM fine-tuning. By balancing complexity with distributional consistency, we can train more capable models in less time and with fewer resources.

One remaining challenge is the inherent correctness of synthetic data. While our current strategy selects for complexity, future work will focus on incorporating automated validation mechanisms to ensure that selected samples are not only difficult but also logically sound. This will further refine the quality of the training signal and push the boundaries of open-source code intelligence.

Summary updated

BibTeX
@inproceedings{lv2025data,
  author = {Weijie Lv and Xuan Xia and Sheng-Jun Huang},
  title = {{Data-efficient LLM Fine-tuning for Code Generation}},
  booktitle = {IJCNN},
  year = {2025},
  doi = {10.1109/ijcnn64981.2025.11227906},
}
Figure