Skip to main content

finetune-doctor

Did your fine-tune overfit? Which checkpoint should you keep? What can you delete?

Point it at a training output folder — or at any model on the HuggingFace Hub — and get the answer in a second.

CI PyPI Python License

finetune-doctor on a public Mistral-7B fine-tune: keep checkpoint-500; the best eval at step 900 was never saved; the last eval is 6% worse

Works with anything built on the HuggingFace Trainer — TRL's SFTTrainer, Unsloth, LLaMA-Factory, Axolotl, Seq2SeqTrainer for Whisper, plain Trainer for BERT. They all leave the full training history in trainer_state.json, and almost nobody reads it.

Try it on a public model — no install of anything else, no GPU

pip install finetune-doctor
finetune-doctor anshpunia8597/mistral-7b-medical-qa-finetuned

Or the latest from main: pip install git+https://github.com/junglezke/finetune-doctor. ftdoctor works as a short alias for the command; it is also the name 0.1.0 shipped under.

That is the banner above: a real Mistral-7B fine-tune on the Hub. finetune-doctor reads its trainer_state.json and the checkpoint folders the repo actually holds, and says:

  • the best eval was at step 900 — which was never saved, so you cannot have it;
  • of the checkpoints that exist, checkpoint-500 is the best;
  • the last eval is 6% worse, and that is outside the eval's own noise, so it is real.

On your own run

finetune-doctor ./outputs                    # the folder with checkpoint-*/ in it
finetune-doctor ./outputs/checkpoint-1200    # or any one checkpoint
finetune-doctor trainer_state.json           # or just the file
from finetune_doctor import load, diagnose

result = diagnose(load("./outputs"))
print(result.headline)          # outputs: keep checkpoint-1000; overfitting.
print(result.pick.keep_step)    # 1000

And get your disk back

A full fine-tune that saves every few hundred steps leaves dozens of multi-gigabyte checkpoints behind. Most of each one is optimizer state you only need to resume training.

finetune-doctor prune ./outputs            # show the plan -- deletes nothing
finetune-doctor prune ./outputs --apply    # do it

By default prune keeps the recommended checkpoint and the latest one untouched, and from every other checkpoint removes only resume-only files — optimizer.pt, scheduler.pt, RNG state, DeepSpeed shards. Every model stays loadable. --mode full deletes the other checkpoints outright, and is refused when the run has no eval to base a recommendation on.

Before deleting anything, --apply re-checks each target is a checkpoint-N directory directly inside your output folder, containing a trainer_state.json, and not one being kept.

What 89 public fine-tunes look like

To calibrate the checks, finetune-doctor was run on 89 trainer_state.json files published on the Hub — LLM SFT and QLoRA runs, Whisper, BERT, audio classifiers. 88 were supervised fine-tunes; one turned out to be an RL run (more on that below).

41 of 88 (47%) logged no eval metric at all. Nothing can tell whether they overfit — training loss only ever goes down.
23 had fewer than 5 evals: too few to tell a trend from noise.
24 had enough evals to judge. Of those:
  10 the final checkpoint was the best one.
  10 the final checkpoint was not the minimum — but the difference was within the eval's own noise. A naive argmin(eval_loss) tells these people to go back to an earlier checkpoint for nothing.
  4 the final checkpoint was genuinely worse; 2 of them by more than 3%.

And a few things only real logs turn up:

  • Loss that doubles at every epoch boundary. A Qwen2.5-7B SFT whose loss jumped on the first step of each of its 10 epochs. Periodic, so not instability — the step straddling the epoch boundary computes its loss differently. The usual advice for loss spikes (lower the learning rate) would have been wrong.
  • Loss of exactly 0.0 from the first step — which was fine. A Gemma-3-12B run whose name said SFT logged a loss of 0.0 from step one. An early version of finetune-doctor called it "trained on nothing, labels masked". It was a GRPO run, where a loss near zero is normal. finetune-doctor now recognises RL runs, skips the loss-based checks instead of misreading them, and hands them to rl-doctor. (For a genuinely zero loss in SFT, the usual cause is every label masked to -100 — and finetune-doctor says so.)
  • Eval loss up 37%, accuracy still improving. An audio classifier selected on accuracy. Judged on loss it overfit badly; judged on the metric its author actually chose, the last checkpoint was the best. finetune-doctor recovers that choice from best_metric and says so.
  • inf gradients that do not matter. A Mistral run logged grad_norm = inf at 10 scattered steps out of 34,000. Under fp16 that is the loss scaler skipping an overflowing step — harmless, and telling someone to roll back over it would be wrong.

What it checks

catches
Which checkpoint best eval, the noise band around it, and the best checkpoint that exists
Overfitting eval getting worse while training loss keeps falling; the train/eval gap; steps and hours spent after the best point
Stopped improving the eval flatlined early: same result for a fraction of the compute
Loss vs your metric eval loss rising while accuracy / WER / BLEU improves — not overfitting in the sense you care about
No eval and the exact TrainingArguments to fix it
Broken loss NaN loss; loss of exactly zero (masked labels)
RL runs recognised and handed to rl-doctor, not misread as a broken SFT
Not learning loss flat or rising, with the learning rate that explains it
Loss spikes real spikes, periodic ones, and ones that land on epoch boundaries — each with different advice
Gradients exactly-zero gradients (nothing trainable), spikes that the loss felt, fp16 overflow that it didn't
Learning-rate schedule a tail of steps trained at a learning rate of ~0
Eval below train eval loss consistently under training loss — check for train/eval overlap
Unfinished runs the log ends before max_steps

Every finding comes with the numbers it fired on and a concrete change to make.

How it decides

Noise-aware, not argmin. Each eval metric has its own step-to-step noise, estimated robustly from successive differences. Any checkpoint within 2× that noise (or 1%, whichever is larger) of the best is reported as equivalent. "Your last checkpoint is 1.2% worse" is only said when 1.2% is more than the eval's jitter.

Your metric, not ours. trainer_state.json records best_metric but not which metric it was. finetune-doctor finds the eval series that contains that exact value at best_global_step and ranks on it — accuracy, WER, BLEU, whatever you selected on. Direction (higher or lower is better) comes from the name, and is checked against which extreme the Trainer kept. Use --metric to override.

Only checkpoints that exist. The best eval often lands on a step that was never saved, or was deleted by save_total_limit. Checkpoints are taken from the folders really present — on disk or on the Hub — never inferred from save_steps, which is meaningless under save_strategy="epoch". Given only a bare trainer_state.json, finetune-doctor says it cannot tell which checkpoints exist instead of guessing.

Calibrated on real runs. Every threshold was set against the 89 public runs above, and several were changed because of them: a 1.5× loss-spike rule flagged ordinary small-batch noise; a band-only overfitting rule called 1% drops "overfitting"; a global-median gradient rule mistook the normal early-training decline for spikes. Ten of those runs are pinned in validation/ and re-checked in CI against their public sources.

What it will not do

  • It only sees what was logged. No eval metric, no overfitting verdict — it will tell you so rather than guess from training loss.
  • It does not run your model. It reads the history. Whether the "best" checkpoint is good enough for your task is still a question for your own evaluation.
  • It cannot see sampling noise it was not shown. The noise band comes from the eval's step-to-step variation. A tiny eval set can be noisy in ways a smooth curve hides; if yours has a few dozen examples, treat small differences with suspicion either way.
  • prune cannot be undone. That is why it defaults to a dry run, defaults to keeping every model's weights, and checks every path before touching it.

In CI

finetune-doctor ./outputs --fail-on warning --format markdown -o "$GITHUB_STEP_SUMMARY"

Exits non-zero when a finding at that severity fires, and writes a Markdown report for the job summary.

finetune-doctor is for supervised fine-tuning. For RL post-training (GRPO, PPO, RLVR) — reward hacking, entropy collapse, degenerate groups — see rl-doctor, and to test the reward function itself, reward-doctor.

Development

git clone https://github.com/junglezke/finetune-doctor && cd finetune-doctor
pip install -e ".[dev]"
pytest                                                      # 59 tests
python validation/fetch.py && python validation/run.py --check   # the public runs
python tools/make_banner.py                                 # regenerate the README image

Contributing

The most useful thing you can send is a run where finetune-doctor is wrong — it called a fine run broken, or missed something real. A link to a public model with a trainer_state.json is enough. There is an issue template for it.

License

Apache-2.0.

Metadata

Release files for finetune-doctor 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for finetune-doctor 0.2.2
File Size Uploaded Provenance Actions
finetune_doctor-0.2.2.tar.gz 55.4 kB With provenance Details for finetune_doctor-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for finetune-doctor 0.2.2
File Interpreter ABI Platform Actions
finetune_doctor-0.2.2-py3-none-any.whl Python 3 none any Details for finetune_doctor-0.2.2-py3-none-any.whl

Total release size: 104.8 kB

Release files / finetune_doctor-0.2.2.tar.gz

Download URL finetune_doctor-0.2.2.tar.gz
Size 55.4 kB
Tags Source
SHA-256 checksum
How to use checksums
da9e182b546cc89d6266be36bdd0613519079b63b0f81c5db906944be042ce04
BLAKE2b-256 checksum
How to use checksums
e293d9d457050b9e900742864b2cb15fe1d513606ef8dc624d3b06d0ef9a2ebd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / finetune_doctor-0.2.2-py3-none-any.whl

Download URL finetune_doctor-0.2.2-py3-none-any.whl
Size 49.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78fb86b7991f720a60a5ceab5434235c2fc7da073541bd208f4a2265786346d1
BLAKE2b-256 checksum
How to use checksums
f43604ad6b4f09ce531c17302b42fd247f8c8e56b095ec71e2c7eeb5bc8bba09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Security for finetune-doctor 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for finetune_doctor-0.2.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page