Skip to content

About

30 original bugs. Every one fails with the buggy code and passes with the fix.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

92 Commits

Folders and files

Repository files navigation

ml-bugfix-bench

A small benchmark that tests whether a language model can fix the bugs that quietly ruin machine learning projects: data leakage, misaligned joins, wrong axes, swapped metrics, and training loops that look fine but aren't.

Each of the 30 tasks gives the model a short bug report (written as a user would describe the symptom) and the buggy module. The model must return the fixed module, which is graded by hidden pytest tests in a separate process. Nothing is graded by eye, by string match or by another LLM.

$ mlbugbench list
t01_scaler_leakage           leakage   medium  Scaler fitted before the split
t02_groupby_alignment        pandas    easy    Group mean assigned by index
...
30 tasks | leakage: 7, metrics: 6, numpy: 6, pandas: 7, training: 4

Results

Model pass@1 leakage metrics numpy pandas training Cost (USD)
reference (known-good fixes) 1.000 1.00 1.00 1.00 1.00 1.00 0
buggy (unchanged code) 0.000 0.00 0.00 0.00 0.00 0.00 0
your model mlbugbench run --model ...

The two baseline rows validate the benchmark, not a model: every task's tests fail on the buggy code and pass on the reference fix. CI enforces this on every commit, because a task that the buggy code already passes measures nothing. Model rows get added by running the benchmark; no model scores are listed until they come from a real run.

Why these bugs

None of these crash. They produce plausible numbers that are wrong, which is what makes them expensive in practice:

Category What goes wrong Examples
leakage (7) test information reaches training scaler fit before the split, feature selection outside CV, target encoding that includes the row's own label, shuffled folds on time series
pandas (7) silent misalignment assigning a groupby result by index, a lookup merge that fans out rows, day-first dates parsed month-first
metrics (6) numbers that look right swapped precision/recall, the wrong predict_proba column, a confusion matrix in hash order
numpy (6) shape and numerics normalising along the wrong axis, softmax overflow, a seed that is created and then ignored
training (4) loops that "work" early stopping that returns the last weights, a dropped final batch, a sign error in gradient descent
All 30 tasks
Task Bug Category Difficulty*
t01_scaler_leakage Scaler fitted before the split leakage medium
t02_groupby_alignment Group mean assigned by index pandas easy
t03_merge_fanout Lookup merge duplicates rows pandas medium
t04_row_normalize Normalising along the wrong axis numpy easy
t05_softmax_overflow Softmax overflows on large logits numpy easy
t06_stratified_split Split loses class balance training easy
t07_precision_recall Precision and recall swapped metrics easy
t08_proba_column Wrong predict_proba column metrics easy
t09_onehot_columns One-hot columns differ between train and test pandas medium
t10_impute_leakage Imputation statistics use test data leakage easy
t11_time_series_cv Shuffled folds on time-ordered data leakage medium
t12_rolling_lag Rolling feature includes the current day leakage medium
t13_early_stopping Early stopping returns the last weights training medium
t14_gradient_sign Gradient descent diverges training easy
t15_last_batch Last partial batch is dropped training easy
t16_shuffle_pairs X and y shuffled independently numpy easy
t17_seeded_noise Seed is ignored numpy easy
t18_mean_of_means Average of per-campaign rates pandas medium
t19_log_loss_clip Log loss returns NaN metrics easy
t20_rmse RMSE is actually MSE metrics easy
t21_confusion_order Confusion matrix labels out of order metrics medium
t22_dropna_alignment Features and target misaligned after cleaning pandas medium
t23_day_first_dates Dates parsed month-first pandas easy
t24_category_codes Category codes differ between train and test pandas medium
t25_cv_selection_leak Feature selection outside cross-validation leakage hard
t26_class_weights Class weights favour the majority class metrics easy
t27_cosine_similarity Cosine similarity uses column norms numpy medium
t28_dedup_after_split Duplicates leak across the split leakage medium
t29_bincount_length Histogram shorter than the number of classes numpy easy
t30_target_encoding_loo Target encoding includes the row's own label leakage hard

* Difficulty is the author's estimate. Once several models have been run, it should be replaced by measured solve rates.

How a task is built

tasks/t25_cv_selection_leak/
  task.json      title, category, difficulty, and the bug report shown to the model
  buggy.py       the code shown to the model (imported as `solution`)
  reference.py   a known-good fix, never shown to the model
  test_task.py   hidden tests that import from `solution`

Design rules:

  • Bug reports describe symptoms, not fixes. For example: "On a dataset of pure noise, cross-validated accuracy comes out around 90%." The model has to work out the cause.
  • Tests check behaviour, so any correct fix passes. The leakage task trains on 2,000 noise features and requires CV accuracy below 0.7, then on real signal requires above 0.8. A Pipeline, a manual fold loop or any other leak-free approach all pass.
  • Results are deterministic. Seeds are fixed, and PYTHONHASHSEED=0 is set in the sandbox. One task depends on set iteration order, so its labels were chosen to make the buggy order provably unsorted.

Running it

pip install -e ".[dev]"
mlbugbench validate                         # every task: buggy fails, reference passes
mlbugbench run --model reference            # harness check, must be 1.000

export OPENAI_API_KEY=...                   # any LiteLLM model string works
mlbugbench run --model gpt-4o-mini
mlbugbench run --model ollama/qwen2.5-coder:7b
mlbugbench run --model gpt-4o-mini --samples 5 --temperature 0.8 --k 1 5   # pass@k
mlbugbench report                           # writes results/leaderboard.md

Each run writes results/<model>.json (scores by category and difficulty, cost, timeouts, failed task ids) and results/<model>.attempts.jsonl (every response, the extracted code and the test output). pass@k uses the unbiased estimator from the HumanEval paper (Chen et al., 2021).

Sandboxing

Each attempt runs in a fresh temp directory with a minimal environment and a 60 s timeout. That keeps tasks from interfering with each other, but it is not a security boundary: model-written code runs as your user. To grade an untrusted model's output, split collection from grading and grade inside the container with no network:

mlbugbench run --model some/model                     # collects responses (and grades locally)
docker build -t mlbugbench .
docker run --rm --network none --read-only --tmpfs /tmp -v "$PWD/results:/app/results" \
  mlbugbench regrade results/some_model.attempts.jsonl

Adding a task

  1. Copy a task folder and write buggy.py, reference.py and test_task.py.
  2. Write the bug report from the user's point of view. Don't name the fix.
  3. Make sure the tests would pass any correct fix, not just yours.
  4. Run mlbugbench validate <task_id>. CI rejects the task if the buggy code passes or the reference fails.

Limitations

  • 30 tasks gives wide error bars: one task is 3.3 points. Treat differences under about 10 points as noise unless you sample several times.
  • The tasks are short modules. They test diagnosis and repair, not navigating a large codebase.
  • The tasks are public now, so future models may have seen them. The validate and regrade tooling makes it cheap to add private tasks that never leave your machine.

License

MIT

About

30 original bugs. Every one fails with the buggy code and passes with the fix.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages