Karpathy Gave an AI Agent One File and 5 Minutes per Run: It Improves Model Training on Its Own
Andrej Karpathy has released a repository in which an AI agent picks its own improvements for training a language model. It is given one code file and exactly 5 minutes per run. The agent changes things like the optimizer or batch size, trains the model, and checks the val_bpb score: the lower it is, the better the model. If the score improves, the change stays in git. If not, it is rolled back. That makes the loop easy to transfer to any task that has a fast check and a single number.
AI-processed from X: @Lonerwb; edited by Hamidun News
Picture an intern who is given one file with neural network training code, five minutes for each trial, and one number that shows whether things got better or worse. That is roughly how Andrej Karpathy's repository works: an AI agent edits the code itself, trains a language model for exactly 5 minutes, and checks the val_bpb score. The lower that score, the better the model. If a change helps, the agent saves it to git. If it doesn't, the agent rolls it back. For people building agents, this is a clear example of how to give a model autonomy without losing control.
What val_bpb is and how the loop works
val_bpb measures the quality of a language model on a held-out validation set: the average number of bits needed to predict one byte of text. The model never saw these texts during training, so the number shows how well it actually learned. There is one metric, so there is no debate about whether something got better.
The loop is simple: the agent changes the code, trains the model, checks the score, and keeps only the changes that improved it. It can modify the optimizer (the algorithm that adjusts the model's weights), the batch size (how many examples are processed at once), or the model itself. If the score is the same or worse, the change is rolled back.
Why each run is capped at 5 minutes
The author stresses that every run gets the same training time on your GPU, even when the agent changes the model size. Say the agent decides to use a bigger model. A larger model usually wins simply because of its size, but in the same 5 minutes it gets through less data. So any improvement has to be earned under equal conditions.
In practice, this is a useful technique. If experiments are compared by number of steps or with no limit, the agent can easily "win" simply by spending more compute. A fixed time budget keeps the comparison fair and prevents costs from quietly growing.
How to run it
The requirements are modest: one NVIDIA GPU (the repository has been tested on an H100), Python 3.10+, and the uv package manager. You clone the repository and run three commands inside it. The process then goes like this:
- Data is prepared once: the training dataset is downloaded and the tokenizer is trained.
- The baseline training code runs to record the starting val_bpb value. This is the reference point.
- The agent receives program.md, a Markdown file that describes the working rules. The agent works on a separate git branch: it changes the optimizer, batch, or model and trains for 5 minutes.
- The score decides the fate of the change: if val_bpb is lower, the commit stays; if it is the same or higher, the change is rolled back.
- The result is written to results.tsv: commit, score, peak VRAM usage, status, and a description of the change. Then the loop repeats.
The agent's behavior is set not by orchestration code but by an ordinary text file that can be read and edited like a document. The results.tsv log and the commit history give a complete picture: what was tried, what worked, and how much memory it cost.
What to take from this
The pattern is broader than model training. It has three ingredients: a limited edit scope (one file), a fast check (5 minutes), and an objective signal (a number, not an opinion). Wherever this combination exists, such as performance optimization, hyperparameter tuning, or build configuration, an agent can work with little supervision, and git keeps only the successful steps.
There are limits, too. The source does not claim the agent will find a fundamentally new architecture. Five minutes on a single GPU is a small scale, and improvements found under this budget are not guaranteed to hold up in longer training. The metric may also push the agent toward edits that win specifically on this test. Results should be re-checked on longer runs.
Still, the repository works well as a teaching example: the reliability of an agent system depends not only on the prompt but on the framework around the model, including constraints, verification, and rollback. If you are building agents, start with two questions: what counts as "better" for your system, and how much time the agent gets to evaluate each change.
- Nov 27, 2026Startup with 18 users demands a share of $1 billion from SpaceX over Grok Bot mascot
- Nov 27, 2026Nvidia Engineer Wants to Add Instructions for AI Agents to Linux 7.5 Kernel
- Nov 27, 2026Sber Merges Two GigaChat Models Into One: 40% Faster, 1M-Token Context
- Nov 27, 2026Meta Launches Muse AI Shopper: A Third of Shoppers Expect to Use AI Help on Black Friday
Key Questions Answered
What val_bpb is and how the loop works?
val_bpb measures the quality of a language model on a held-out validation set: the average number of bits needed to predict one byte of text. The model never saw these texts during training, so the number shows how well it actually learned. There is one metric, so there is no debate about whether something got better. The loop is simple: the agent changes the code, trains the model, checks the score, and keeps only the changes that improved it.
Why each run is capped at 5 minutes?
The author stresses that every run gets the same training time on your GPU, even when the agent changes the model size. Say the agent decides to use a bigger model. A larger model usually wins simply because of its size, but in the same 5 minutes it gets through less data. So any improvement has to be earned under equal conditions. In practice, this is a useful technique. If experiments are compared by number of steps or with no limit, the agent can easily "win" simply by spending more compute.
How to run it?
The requirements are modest: one NVIDIA GPU (the repository has been tested on an H100), Python 3.10+, and the uv package manager. You clone the repository and run three commands inside it. The process then goes like this: Data is prepared once: the training dataset is downloaded and the tokenizer is trained. The baseline training code runs to record the starting val_bpb value. This is the reference point. The agent receives program.md, a Markdown file that describes the working rules.
Test Frontier LLMs & Autonomous Agents in One Workspace
Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.
Daily 60-sec AI Voice Brief + Weekly Production AI Agent Playbook
Listen to a 60-second AI news brief every morning and get a weekly hands-on playbook for shipping AI agents to production — tools, MCP servers and patterns that work. Curated by Jemal Hamidun, Head of AI at Alpina Digital.
