Random Selection Reveals Implicit Knowledge Consensus in Code Generation

Ren-Biao Liu, Xin-Ye Li, Hui Sun, Yali Du, Jiang-Tian Xue, Ming LiICML 2026

Introduction

When fine-tuning Large Language Models (LLMs) for code generation, a common challenge is selecting the best training examples from a vast pool of correct solutions. Supervised Fine-Tuning (SFT) is computationally expensive, and in programming contexts like LeetCode, a single problem might have hundreds of valid Python implementations.

Conventional machine learning wisdom suggests that complex data selection strategies—such as maximizing diversity or ranking by difficulty—should extract the most "information" from a small subset of data. However, this paper demonstrates that simple random sampling is a remarkably robust and high-performing strategy. By preserving the "implicit consensus" of common algorithmic patterns, random selection often outperforms sophisticated diversity-maximizing methods, proving that we may be overcomplicating data selection in code generation.

Experimental Setup

To test whether complex selection strategies truly yield better coders, the researchers systematically compared seven data selection methods across four base models (including Qwen2.5, Llama-3.1, and DeepSeek-Coder variants).

The evaluated strategies spanned multiple representation spaces:

  • Random Sampling: The baseline approach of picking solutions entirely at random.
  • Geometric/Embedding-based: Using K-Means, K-Center, and Facility Location to select solutions based on their distribution in the CodeBERT embedding space.
  • Distributional: Kernel Herding, which attempts to match the statistical distribution of the full solution pool.
  • Structural: AST Coverage, designed to maximize the variety of Abstract Syntax Tree (AST) patterns.
  • Difficulty-based: Instruction-Following Difficulty (IFD) Ranking, which selects solutions the model finds "harder" to process based on loss values.

The study utilized a curated LeetCode dataset containing 2,641 programming problems and over 150,000 verified Python solutions. To ensure computational tractability for the complex algorithms, near-duplicate solutions were removed using MinHash LSH, and the pool was capped at 100 solutions per problem. Models were evaluated using the Pass@k metric on a held-out, date-partitioned test set of 228 problems.

Key Findings: The Power of Random Selection

1. Random is King

Random sampling achieved the highest Pass@1 score on half of the evaluated models and demonstrated the greatest stability across different model architectures. Unlike expensive methods like Levenshtein K-Center or IFD ranking, random selection carries zero computational overhead.

2. Outperforming the "Full" Dataset

Remarkably, training on a small, randomly selected subset (just 11 solutions per problem) often yielded better results than training on the entire dataset. For models like Qwen2.5-7B and Llama-3.1-8B, the random subset outperformed the full dataset, which was six times larger and significantly more expensive to train on. This highlights that in SFT, more data is not always better—excessive data can introduce noise.

3. The "Diversity Trap" and Implicit Knowledge Consensus

Why does random sampling work so well? The authors introduce the concept of Implicit Knowledge Consensus. Random sampling naturally favors the "consensus"—the algorithmic patterns that appear most frequently across many different correct solutions. These representative patterns are exactly what a model needs to align its pre-existing knowledge during fine-tuning.

Conversely, diversity-maximizing algorithms often fall into the "Diversity Trap." Methods like K-Center tend to pick "boundary points"—the most atypical, complex, or convoluted ways to solve a problem. While mathematically informative, these outliers serve as poor teaching tools for models trying to learn generalizable coding patterns. Furthermore, harder problems naturally admit a wider variety of unusual solutions, meaning complex selectors inadvertently bias the training set toward the most confusing versions of the hardest problems.

4. Scaling Up

These findings are not limited to smaller models. The results held true when scaling up to a 32-billion parameter model (Qwen2.5-32B). While some complex methods like Facility Location showed marginal gains at the 32B scale for Pass@10, random sampling remained the dominant strategy for Pass@1 (single-attempt accuracy).

Limitations and Future Directions

While random sampling proves to be a highly effective default, the study notes a few limitations:

  • Domain Specificity: The research focused exclusively on Python and algorithmic LeetCode problems. It remains to be seen if these findings translate to web development, systems programming, or non-verifiable code without unit tests.
  • Multi-Solution Requirement: The methodology relies on having a pool of multiple correct solutions, whereas many real-world SFT scenarios only provide a single "gold standard" solution per prompt.
  • The "Hard Tail": Complex selectors do begin to show value when the specific goal is to solve "Hard" problems or handle strict algorithmic constraints.

Ultimately, practitioners should treat random sampling as a low-cost, highly effective default for verifiable code-generation fine-tuning, reserving complex selection strategies for targeted coverage of difficult, edge-case constraints.

Summary updated

BibTeX
@inproceedings{liu2026random,
  author = {Ren-Biao Liu and Xin-Ye Li and Hui Sun and Yali Du and Jiang-Tian Xue and Ming Li},
  title = {{Random Selection Reveals Implicit Knowledge Consensus in Code Generation}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=xpA2SBvm4g},
}
Figure