---
id: 18441
lang: en
title: "Karpathy Gave an AI Agent One File and 5 Minutes per Run: It Improves Model Training on Its Own"
published_at: "2026-11-27 12:36:41"
source_name: "X: @Lonerwb"
source_url: "https://x.com/Lonerwb/status/2126261659471671420"
canonical_url: "https://news.hamidun.com/en/news/18441"
categories: ["research", "autonomous"]
publisher: "AI News by Jemal Hamidun (news.hamidun.com)"
---

# Karpathy Gave an AI Agent One File and 5 Minutes per Run: It Improves Model Training on Its Own

> **Краткая суть (BLUF):** 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.  - Requires one NVIDIA GPU (tested on H100), Python 3.10+, and uv - Rules for the agent live in program.md, and work happens on a separate git branch - results.tsv stores the commit, score, peak VRAM, status, and a description of the change

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.

---
- **Первоисточник:** [X: @Lonerwb](https://x.com/Lonerwb/status/2126261659471671420)
- **Каноническая ссылка:** https://news.hamidun.com/en/news/18441
- **Экосистема автора:** [Бесплатный интенсив по вайбкодингу — предзапись в Нике](https://t.me/vibecodeguidebot?start=agent_intensive_news_md) · [Nomad AI](https://nomadnet.ai) · [Telegram @jemal_hamidun](https://t.me/jemal_hamidun)
