AI engineering
Karpathy's autoresearch: a practical guide to the experiment loop
Understand Karpathy's autoresearch, its five-minute experiments, fixed evaluator, and keep-or-discard loop, with a bounded first-run plan and practical adaptations.

A coding agent can suggest an experiment. The harder part is making its next decision depend on what actually happened. Karpathy's autoresearch makes that relationship concrete: the agent changes training code, runs an experiment, reads a fixed metric, and keeps or discards the change before trying again.Andrej Karpathy · autoresearch ↗
The public repository applies this idea to training a small language model on one GPU. Its useful contribution for other builders is the shape of the experiment: a narrow editing scope, an evaluator outside that scope, a comparable budget, and a record that survives the conversation.Andrej Karpathy · autoresearch ↗
Understand the three files before running the loop
| File | Role in the upstream project | Who changes it |
|---|---|---|
| prepare.py | Data preparation, tokenizer utilities, fixed constants, and evaluation | The experiment agent is instructed to leave it unchanged |
| train.py | Model, optimizer, configuration, and training loop | The experiment agent edits this file |
| program.md | Instructions describing how the research should proceed | The human sets and refines the protocol |
That division makes the experiment reviewable. You can inspect the instruction file separately from the candidate implementation, then compare each proposed change against an evaluator that should stay fixed. Before starting, read the files yourself and identify the exact boundary between a candidate and its test.Andrej Karpathy · autoresearch ↗
Separate the coding agent from the model being trained. The agent proposes edits to Python code. Running that code trains a candidate language model, and the evaluator measures that candidate. These are different parts of the system, even when both are described casually as AI.

Follow one experiment from baseline to decision
The upstream protocol establishes an unchanged baseline, works on a dedicated experiment branch, records results in results.tsv, and advances or resets the candidate commit according to the outcome. It also asks the agent to consider whether an improvement justifies added complexity.Andrej Karpathy · autoresearch ↗
| Stage | What should happen | What the record should explain |
|---|---|---|
| Baseline | Run the starting implementation with the fixed evaluator | The revision, environment, and result used for comparison |
| Hypothesis | Choose a specific change to the permitted implementation | What might improve and why the change tests that idea |
| Experiment | Run the candidate under the agreed budget | The candidate revision, output, and any failure |
| Decision | Apply the acceptance rule to the observed result | Why the candidate is retained or rejected |
| Next trial | Continue from the retained state | What was learned, including unsuccessful ideas |
This table is a reading aid for the experiment lifecycle. For a real run, use the pinned program.md for the exact commands and repository-specific rules. Preserve rejected experiments in the log so the next trial has more to work with than the current code.
Read the metric as carefully as the code
The score is val_bpb: validation bits per byte, where lower is better. The evaluator converts prediction loss into a byte-normalized quantity, excluding special tokens that have no byte length. It uses the fixed validation loading and sequence-length setup in prepare.py.Andrej Karpathy · autoresearch ↗
The training program prints that score alongside values such as training time, total time, peak GPU memory, and parameter count. Those additional fields help explain what a candidate achieved and what it consumed. Read the complete summary rather than judging a run from a reassuring sentence written by the agent.Andrej Karpathy · autoresearch ↗
A better validation score under a short training budget answers a specific research question. Product latency, deployment cost, response quality on a different task, and long-run behavior require their own evaluation. Decide which result you need before reusing the loop for another problem.
Keep the comparison budget meaningful
The upstream training budget is 300 seconds. Startup, compilation, and final evaluation contribute additional elapsed time, so a five-minute training budget is not a promise that the entire command finishes in five minutes. The implementation reports training_seconds and total_seconds separately.Andrej Karpathy · autoresearch ↗Andrej Karpathy · autoresearch ↗
The same machine and budget make successive candidates easier to compare. The README also points out that results from different compute platforms are not directly comparable. Record the hardware and environment with the baseline before drawing conclusions from someone else's score.Andrej Karpathy · autoresearch ↗
For a different task, choose the resource that makes comparisons useful. A database optimization might hold the dataset and concurrency fixed. A retrieval experiment might hold the query set and time limit fixed. More generated candidates are useful only when their results remain comparable.

Start with one manual experiment
The documented upstream requirements include a single NVIDIA GPU, with the project tested on an H100, Python 3.10 or newer, and uv. Follow the repository's current platform notes if your setup differs. The commands below are the core quick-start steps after obtaining the repository and installing those prerequisites.Andrej Karpathy · autoresearch ↗
uv sync
uv run prepare.py
uv run train.pyRun them inside a dedicated checkout. Confirm that data preparation completes, the training process runs, and the final summary contains a real val_bpb result. Save the output and the starting revision. Until that baseline works, changing the candidate adds another source of uncertainty.
The published protocol is designed to continue until a human interrupts it. Its per-experiment timeout handles a stalled trial; it does not impose a total session budget. For an initial evaluation, explicitly agree on a smaller run instead of discovering the operating cost after an unattended session.Andrej Karpathy · autoresearch ↗
Read README.md, program.md, prepare.py, and train.py before starting. Summarize the editable scope, fixed evaluator, data requirements, and output fields. Use a dedicated experiment checkout.
First establish the unchanged baseline and confirm a valid evaluation result. Then run at most three candidate experiments, stopping earlier if 30 minutes of total session time has elapsed. This explicit session limit replaces the upstream instruction to continue indefinitely for this run.
Keep prepare.py, the evaluation method, data, dependencies, and resource budget fixed. Edit only train.py for candidates. Give each trial a concise hypothesis and record its revision, measured score, resource use, and keep/discard/crash decision. Apply the upstream comparison and complexity criteria.
Stop if the evaluator cannot run, the fixed files change, or the permitted budget is exhausted. Finish with the best retained revision, the full experiment log, rejected ideas, and the checks still needed before trusting the result more broadly. Do not deploy or publish anything.The limits in that prompt are a proposed starting arrangement, not upstream defaults. Pick limits appropriate to your machine and project. If you change them later, keep the original experiment record so you can distinguish more search effort from a better individual candidate.
Inspect the winning change before calling it progress
- Check the evaluator and protected inputs against the baseline. A written editing restriction should be verified, not assumed to be an enforced permission boundary.
- Inspect the retained diff and the experiment log together. The hypothesis, code change, and measured outcome should tell the same story.
- Re-run a promising candidate and its baseline under comparable conditions. Treat a small single-run difference cautiously when the process is variable.
- Review resource use and implementation complexity alongside the primary metric. The metric should serve the task you intend to improve.
- Keep a separate final evaluation for questions the development loop could overfit. Do not continually expose that final check and then treat it as independent evidence.
These are proposed review practices for using an optimization loop responsibly. They extend the practical assessment of a candidate; they are not claims that the upstream repository supplies an external enforcement service, a production deployment system, or a complete statistical evaluation.
Adapt the pattern to a problem you can actually score
Consider an original example: improving search in a small product catalogue. Freeze a development set of queries and expected first results. Let the agent edit the ranking function. A fixed evaluation command reports the fraction of queries whose expected result ranks first, plus a latency measurement under a specified procedure.
A trial is useful when it changes a stated ranking idea and produces an interpretable result. If a candidate simply hard-codes the visible queries, the score becomes less useful. Inspect the implementation and reserve a separate review set until the final candidate has been chosen.
| Autoresearch concept | Possible search experiment counterpart |
|---|---|
| The editable training implementation | One ranking module |
| The fixed evaluator and data setup | An unchanged scoring script and development fixtures |
| A comparable training budget | A fixed experiment time limit and consistent latency procedure |
| The primary validation score | The agreed ranking score, subject to explicit regression limits |
| The retained revision and results log | A reviewable candidate commit and experiment history |
Investigate whether [TASK] is suitable for a bounded experiment loop.
Identify the candidate implementation in [EDITABLE PATHS], the fixed evaluation command [COMMAND], and the protected fixtures or data [PATHS]. Confirm that the unchanged baseline runs before proposing experiments.
Define the primary metric, its direction, and the regression limits that can veto a higher score. Specify the per-trial resource budget, total trial/time limits, and what gets logged. Keep an independent final review set outside repeated development feedback.
If any of those pieces are missing, describe what must be built or agreed first. Do not substitute an agent's opinion for the missing evaluator. Treat any file names or commands in this brief as placeholders until confirmed against the actual project.This adaptation is useful because it preserves the decision structure while changing the domain. It does not require a language-model training task. It does require a test whose improvement means something outside the agent's own explanation.
Choose work where repeated evaluation is worth the effort
Good starting candidates have a narrow implementation surface, a repeatable check, and enough room for useful alternatives. When an evaluation is slow, a failed change is hard to undo, or success depends on preferences that have not been specified, define those boundaries before starting repeated autonomous trials.
For visual design, automated checks can detect overflow, broken links, or a contrast failure. They cover only part of the result. Your intended tone, visual direction, and whether the page explains the product still need a concrete brief and human judgment. A passing test suite and a successful design review are different pieces of evidence.
Start with one baseline and a few documented experiments. If the score is useful and the retained changes withstand review, you have a basis for a longer run. The lasting asset is the experiment setup: the candidate boundary, evaluator, budget, and record that let someone explain why a change was kept.
Sources & further reading
Checked November 7, 2026. Definitions and guidance come from the references below; prompts and concepts are original sinabuilds work.
- Autoresearch README Andrej Karpathy · autoresearch
Primary description of the project, file responsibilities, hardware requirements, quick start, fixed-time comparison, and platform limitations. Repository revision pinned to 228791f.
- program.md: the upstream experiment protocol Andrej Karpathy · autoresearch
Source of baseline setup, editable-file restrictions, experiment records, keep/discard behavior, timeout handling, and indefinite continuation. The bounded first-run prompt in this article is an explicit adaptation.
- prepare.py: fixed constants and validation evaluation Andrej Karpathy · autoresearch
Defines the 300-second training budget, fixed data/evaluation setup, and evaluate_bpb calculation. Explains what the score measures.
- train.py: training process and reported results Andrej Karpathy · autoresearch
Primary implementation of training and the final evaluation summary, including separate training and total elapsed time, memory, and model-size fields.