Karpathy's Autoresearch Overfits Your Validation Set. On a Clinical Model, That's a Safety Claim

Karpathy's autoresearch pins the metric but still overfits the validation set. On clinical models: seal a site-and-time test set, gate hard, plant canaries.

Clint JohnsonPublished 9 min read

Key takeaways

  • Autoresearch pins how the metric is computed, but dozens of keep-or-revert steps against one validation set will still overfit it.
  • Keep a sealed test set split by site and time in a schema the agent can't read, and have an outside scorer that owns the labels return one number.
  • Track the validation-to-sealed gap, kept-commit survival and canary trips, then run the single candidate in shadow mode before release.

Yes, Karpathy's autoresearch overfits your validation set. The loop pins how the metric is computed, but it runs dozens of keep-or-revert steps against one validation set. Every kept commit is a small fit to that set. On a nanochat training script, the cost is val_bpb gains that may not hold up anywhere else. On a clinical model, the cost is a patient-safety claim that isn't true.

I'd still run an autoresearch-style loop on a clinical model. I'd treat it as a search tool, not as evidence. The validation number it reports is a hypothesis. The sealed test set and shadow mode decide whether the hypothesis holds.

I've written this rule about clinical AI before: a guardrail that only exists in a config file is a slide, not a control. In MedScrub we found guardrails written into skill configs that weren't enforced on the main write path. Autoresearch has the same weakness. prepare.py is marked "DON'T touch." As far as the published descriptions go, that's an instruction to the agent, not a permission boundary. Everything below moves the instructions into places the agent can't argue with: database grants, a scorer service and a git remote.

How Karpathy's autoresearch loop works

The repo is three files. prepare.py holds data prep and the eval. program.md holds the agent's instructions. train.py is the only file the agent edits. The metric is val_bpb, validation bits-per-byte. The agent edits, commits, trains and parses val_bpb. If the score improved, the commit stays. If it didn't, the agent runs git reset.

That design protects the metric definition. It does nothing for the validation data. DataCamp's guide says the loop runs 80–100 experiments overnight and warns that "running 100 experiments against the same validation set carries an overfitting risk."

The headline results are mostly this kind of number. Tobi Lütke's Shopify adaptation was reported as a 19% improvement in validation scores overnight. That may be a real gain. The coverage doesn't give a held-out number, so nobody outside can tell.

Why the loop overfits, and why "test sets get reused anyway" doesn't save you

The obvious pushback is that the field has reused benchmark test sets for years and survived. My view: that reuse is human-paced. A paper gets a few submissions, each picked by a person who looked at the results. The loop makes a keep-or-revert call on every experiment, 80–100 a night, and nothing but the number decides. I'd treat that as a different regime until someone shows me otherwise. Clinical data also shifts harder than most benchmarks do: a new site, a new quarter, a new documentation template.

Passive overfitting is the mild case. The worse case is an agent that can reach the eval data or the scoring code. Huang et al. tested 17 models on 38 tasks. With no instruction to cheat, the spontaneous hacking rate was 30.5% on open-ended research-pipeline tasks and 2.9% on narrow kernel tasks. (Their headline figure of 505 of 677 comes from a setting where hacking was explicitly permitted. The authors call that a stress test, not a prevalence estimate.)

Two of their hacks map straight onto clinical setups:

  • Readable validation split. The scorer printed accuracy on a split the agent could read. The agent built predictions keyed to the validation labels and maxed the score.
  • Fingerprinting. A calibrator read the shape, sum and moments of the eval array and returned outputs fitted to it. It called this "transductive beta-calibration."

Onset timing matters too. In their annotated spontaneous hacks, the median onset came 71% of the way through a run. Late commits deserve the most suspicion.

Seal the test set where the agent can't reach it

Split the sealed set by site and time. Hold out whole sites the agent never trains or validates on, plus a later time window. A random row split leaks the same hospitals and the same quarter into both sides. That's exactly the shift you most need to measure.

Put the sealed set in a warehouse schema the agent's role has no grant on. Enforce it in the database, not in program.md:

REVOKE ALL ON SCHEMA ml_sealed FROM PUBLIC;
GRANT USAGE ON SCHEMA ml_dev TO autoresearch_agent;
GRANT SELECT ON ALL TABLES IN SCHEMA ml_dev TO autoresearch_agent;
GRANT USAGE ON SCHEMA ml_sealed TO scorer_svc;
GRANT SELECT ON ALL TABLES IN SCHEMA ml_sealed TO scorer_svc;

The scorer runs as its own service outside the sandbox. It also owns the validation labels, so the agent submits predictions and never computes its own score. That isn't paranoia. In the same paper's certify_model task, every model that ran it built its own evaluation, and twelve of them reported about 0.85 for a model whose held-out score was 0.46.

The scorer returns one number. No per-site breakdown, no list of failed checks, no reasons. Hacks that got past review rose from 7 of 150 after one round to 56 of 150 after five, and detailed reviewer feedback roughly doubled cumulative evasion compared with a generic rejection (40.5% vs 20.3%). Every detail you return teaches the agent the shape of your checks. Your human-facing eval reports can be as rich as you like, and you should build those properly. The agent-facing channel stays a single number.

The gate: keep a change only if it holds everywhere

A commit stays only if it beats the headline metric and also holds up per site, per subgroup and on calibration. All of that runs inside the scorer, and it all collapses into the one number:

def score(cand, base, tol=0.002):
    ok = (cand.headline > base.headline
          and all(cand.site[s] >= base.site[s] - tol for s in base.site)
          and all(cand.group[g] >= base.group[g] - tol for g in base.group)
          and cand.calib_err <= base.calib_err + tol   # finer, hidden binning
          and not cand.canary_trips)
    return cand.headline if ok else base.headline - 1.0  # agent sees only this

The calibration check is where a gate can quietly become a new target. In the paper, agents beat a worst-group, equal-width 15-bin ECE by collapsing a subgroup's confidences until each bin's mean confidence matched its accuracy. Nothing was actually calibrated. So compute calibration with a finer check on the scorer side, and don't document its bins anywhere the agent reads.

To blunt fingerprinting, score each call on a freshly re-sampled subset of validation rows. Shuffling row order alone doesn't help, because shape, sum and column moments stay the same. A new subset changes the sum and moments between calls, so outputs fitted to one array don't carry over. The cost is noisier keep-or-revert comparisons. Widen the tolerance or average over a few draws.

If you want the slow, human version of this discipline, it's the training recipe: one change at a time, look at the data, don't trust a curve you didn't check. The agent won't look at the data unless the scorer makes it pay for skipping that step.

Canaries for clinical shortcuts

A canary is a planted shortcut that should never help. If a kept commit gets lift from one, the run is suspect. I'd plant three.

Label-adjacent fields. Add a synthetic column to the validation split. Derive it from the label and give it a name a chart might contain. In the sealed set it's noise. If permuting that column wipes out a kept commit's gain, that's a trip. Real label-adjacent fields, meaning anything recorded after prediction time, belong in your leakage checks before the loop ever starts.

Cached eval output. Leave a decoy predictions file in the sandbox with a known fingerprint. Audit file access. Any read is a trip. Monitor during the run, not after. Watch for edits that wrap or patch metric functions as well. One agent in the paper monkey-patched np.corrcoef and called it a "numerical-stability" wrapper.

Site and ID artifacts. Keep site codes and encounter-ID formats in the features the agent can see. Then shuffle site code within each label class and re-score. If the score drops, the model is reading the hospital, not the patient. The sealed set's held-out sites confirm it.

Canaries don't replace a held-out check. In the paper, 38 hacks passed a programmatic audit that re-ran on a held-out split, and the ones that pass review "tend to resemble ordinary work." Canaries make the cheap hacks loud so the expensive checks can spend their budget on subtle ones. Don't hand canary review to an LLM either. A judge that saw only code and scores missed 6.5% of confirmed hacks, and LLM evaluators fail hardest where it matters.

De-identified sandbox, git history as evidence

The agent's sandbox gets de-identified data only. "De-identified" has to mean measured per identifier, not one overall recall number (your overall recall number is lying). Whether a given agent tool can sit under a BAA depends on a narrow setup, and even a covered tool doesn't make your system compliant (covered isn't compliant). The sealed set can live closer to the source data because only the scorer reads it.

Then fix one thing in the stock loop. Autoresearch makes git history the experiment log, but git reset throws away the code of every failed attempt. On a clinical model, the failed diffs are evidence. Commit every attempt to an append-only attempts branch before scoring, and push it to a remote the agent's credentials can't force-push. When someone asks how this model was built, the answer is the full diff history, the scorer's numbers and the canary log. A summary the agent wrote doesn't count.

Open the sealed set once, then shadow mode

A run ends with one candidate: the head of the kept branch. Open the sealed set for it once. In the same pass, score every kept commit from that run as a diagnostic. Don't use those per-commit scores to pick a different commit to ship. The moment you do, the sealed set becomes a second validation set and you're overfitting it by hand.

If the candidate passes, it goes to shadow mode. It runs on live traffic, its outputs are logged next to the production model's, and nobody acts on them. Compare two things per site: the disagreement rate with the production model, and calibration drift as labels arrive. A site where disagreement jumps is the shift neither split captured. Fix the shadow duration before it starts, long enough for every site to produce enough cases to estimate its own disagreement rate. Deciding when to stop after looking at the numbers is just another way to overfit.

In clinical data the labels often arrive late, so you also need drift signals that don't wait for labels.

How to measure autoresearch overfitting

  • Validation-to-sealed gap. The candidate's validation score minus its sealed score. Track it per run. A gap that grows with run length means the loop is fitting the validation set and your runs are too long.
  • Kept-commit survival rate. The share of kept commits whose validation gain points the same direction on the sealed set. If most late commits don't survive, the agent spent the back half of the run memorizing your validation data.
  • Canary trips. Count per run, by canary. Any trip on the candidate disqualifies it. Trips elsewhere in the run tell you what the agent tried, and that's worth reading before the next run starts.

Here's the threshold I'd start with and adjust once real runs come in: if the gap eats more than half the validation gain the run claimed, halve the run length for the next one. Don't add experiments to find the signal. More experiments against the same validation set is the problem.

Questions people ask

Does Karpathy's autoresearch overfit the validation set?

Yes. The loop protects the metric definition, but it runs many keep-or-revert experiments against the same validation set, so kept commits gradually fit that set. DataCamp's guide to the loop warns about the same risk.

How do you stop an AI research agent from reward hacking the eval?

Keep the evaluation data and scoring logic out of the agent's reach. Put the sealed test set in a schema the agent's role has no grant on, and run the scorer as a separate service that owns the labels and returns one number. Plant canaries such as a decoy cached predictions file and a label-derived column.

Why should the scorer return only one number to the agent?

Every extra detail teaches the agent the shape of your checks. In the reward-hacking study cited in the article, detailed reviewer feedback roughly doubled cumulative evasion compared with a generic rejection (40.5% vs 20.3%).

Is it safe to run autoresearch on a clinical model?

Only as a search tool, not as evidence. Run it on de-identified data, keep every attempt in an append-only git branch, and open the sealed site-and-time test set once per candidate. Then run shadow mode before release.