All benchmarks

  Paper

A 220M-parameter model fixed more Python type errors than GPT-4 (PyTy, ICSE 2024)

Made by Yiu Wai Chow, Luca Di Grazia and Michael Pradel

ICSE 2024

Weights not on Hugging FaceSource: Chow, Di Grazia and Pradel

The result

  • Quality

    Type errors removed with up to 50 checked suggestions (top-50 error removal), 281 test errors. Small model: PyTy (TFix t5-base, 220M). Large model: GPT-4.

    85.4%vs 39.1%

    Ahead by 46.3 points

    PyTy 220M85.4%
    GPT-439.1%

    Type errors removed (top 50) · higher is better

  • Latency

    Average over PyTy’s whole run on the 281 test errors (6 h 44 min on one NVIDIAV100 server), including running the Pyre type checker on up to 50 candidates per error. No latency is reported for the OpenAI models, so no comparison.

    No comparison

    Only the small model’s time is reported.

    PyTy 220M86.2 son one NVIDIA Tesla V100 server
    GPT-4Not reported

    s per type error · lower is better

The story

Fixing the errors a type checker finds

Python lets developers add type annotations gradually, and checkers such as Pyre then flag code where the types don’t fit. Fixing those errors by hand takes time, so Yiu Wai Chow, Luca Di Grazia and Michael Pradel at the University of Stuttgart built PyTy for that one job and published it at ICSE 2024.

Given a few lines of code and the checker’s message, it proposes a replacement that removes that error without adding new ones. To learn it, the team collected real fixes from GitHub.

Data

PyTyDefects

2,766 error-fix pairs from 176 GitHub repositories

Real developer fixes, isolated automatically with type checking and delta debugging; ten frequent error classes

Two authors hand-checked a random sample of 100 entries. Test set: 10% of each class (281 errors in 174,586 lines of code); the rest was split 90/10 into training and validation.

With so little data, they didn’t train from scratch. They started from TFix, a T5 model already trained on 104,804 JavaScript fixes, and fine-tuned its 220-million-parameter version on the Python fixes, with special tokens so the model keeps Python’s indentation.

Small model

PyTy (fine-tuned TFix t5-base)

220M · University of Stuttgart

Fine-tuned (all weights) on the PyTyDefects training split; weights on Zenodo and GitHub

Base
TFix t5-base (T5 trained on 104,804 JavaScript fixes)

Training

Full fine-tune with Adam

30 epochs, batch 32, learning rate 1e-4 (code default); kept the checkpoint with the lowest validation loss (epoch 17)

One NVIDIA Tesla V100 (server with 48 Xeon cores, 250 GB RAM)
Time
Not reported for training

Not reported: cost.

At use time PyTy samples up to 50 candidate fixes and runs the type checker on each, and shows a fix only if it removes the error without adding new ones.

Against OpenAI’s models

The authors gave text-davinci-003, gpt-3.5-turbo and gpt-4 the same 281 held-out errors. The prompt had the task, the buggy code, the checker’s message, the line with the error and the answer format, and the released script drew 50 answers per error at temperature 0.3. Both sides were scored the same way: does the error disappear under Pyre, and does the fix match the developer’s own commit.

Large model

GPT-4

Size not disclosed · OpenAI

Used as released through OpenAI’s API (gpt-4), prompted with the task, code, error and answer format; 50 samples at temperature 0.3

Evaluation

281 type errors

Test set
PyTyDefects test split
Metric
Error removal and exact match, top-1 / top-5 / top-50
How it was compared
Same errors and checks for every model; gpt-4 ran on 22 Oct 2023 (saved log); its prompt and settings are in the released code.

What they found

With up to 50 suggestions checked, PyTy removed 85.4% of the errors against 39.1% for gpt-4, the best of the three LLMs; at the first suggestion the gap was smaller, 50.9% against 34.1%. PyTy also matched the developer’s exact fix more often: 54.4% against 26.4% at top-50. The authors found the LLMs mostly fixed errors that need a single-token edit. Of 30 pull requests they opened with PyTy’s fixes, 20 had been merged when the paper was written.

There is no cost comparison. PyTy took 6 hours 44 minutes for the 281 errors on one NVIDIAV100 server, 86.2 seconds per error on average, most of it spent running the type checker.

All the numbers

Show all numbersHide all numbersEvery model · Cost, latency and energy · 7 more results

Every model on the headline test

Cost, latency and energy, as reported

Cost
Not reported
Latency · seconds per type error (average)
PyTy 220M86.2
GPT-4not reported
PyTy took 6 h 44 min for all 281 test errors, including running the type checker on up to 50 candidates per error. GPT latency is not reported, so there is no comparison.
Energy
Not reported

More from the source

  • Error removal, first suggestion (top-1)

    Small model 50.9Large model 34.1 %

    Table 2

  • Error removal, top-5

    Small model 66.2Large model 36.7 %

    Table 2

  • Exact match with the developer’s own fix, top-1

    Small model 37.7Large model 18.9 %

    Table 2

  • Exact match with the developer’s own fix, top-50

    Small model 54.4Large model 26.4 %

    Table 2; §6.4.1 ‘Answer to RQ4a’

  • Error removal, top-50

    Small model 85.4gpt-3.5-turbo 26 %

    text-davinci-003: 34.6.

    Table 2

  • Error removal, top-50

    PyTy on the small TFix model (60M) 79Large model 39.1 %

    The authors say this shows PyTy could run in a resource-constrained setup such as a developer laptop.

    Table 2; §6.3

  • Error removal, top-50, without the Python fine-tuning

    Original TFix (t5-large, 770M) 16.7 %

    Table 2; §6.3

Worth knowing

  • GPT-4 here is the version available when the paper was written (published January 2024); newer models were not tested.
  • The paper doesn’t say how the LLMs’ top-5 and top-50 suggestions were generated, or which GPT-4 snapshot was used.
  • At the first suggestion the gap is smaller: 50.9% vs 34.1% error removal.
  • No cost comparison; PyTy’s 86.2 s per error includes running the type checker on many candidates.
2 more caveats
  • Error removal is judged by the type checker only; the paper shows an example where PyTy’s fix removes the error but changes the code’s meaning.
  • The authors evaluate their own tool; not independently replicated.

Weights on Hugging Face

Not on Hugging Face

Not on Hugging Face (search not applicable: the model is distributed with the ICSE artifact). Code and the PyTyDefects dataset: GitHub sola-st/PyTy and Zenodo record 10441045.

Sources

  1. Yiu Wai Chow, Luca Di Grazia, Michael Pradel, ‘PyTy: Repairing Static Type Errors in Python’, arXiv:2401.06619 (Table 2, §5, §6.4.1)
  2. Same paper, ICSE 2024 (ACM Digital Library)
  3. Code and PyTyDefects dataset, GitHub (sola-st/PyTy)
  4. ICSE 2024 artifact, Zenodo
  5. arXiv preprint; published at ICSE 2024 (DOI 10.1145/3597503.3639184).
3 more sources behind this page
  1. arXiv 2401.06619v1 (HTML)
  2. github.com/sola-st/PyTy/README.md
  3. github.com/sola-st/PyTy/src/eval_code/LLM/chatgpt.py
Share this benchmark

Drawing the image…

Post text