# AI use cases for Nanochat (karpathy/nanochat)

Repo: [karpathy/nanochat](https://github.com/karpathy/nanochat) | Use cases: 3 | Page: https://dedupedai.com/use-cases/karpathy-nanochat/

nanochat is the simplest experimental harness for training LLMs on a single GPU node. Its minimal, hackable code covers tokenization, pretraining, finetuning, evaluation and inference, so you can train a GPT-2 capability model in about 2 hours on an 8XH100 node and talk to it over a CLI. One dial, --depth, sets the model size and every other hyperparameter is derived from it.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- Train a GPT-2 class chat model end to end and talk to it: https://dedupedai.com/use-cases/karpathy-nanochat/train-your-own-gpt-2-in-two-hours/
- Train a compute-optimal miniseries by changing one depth dial: https://dedupedai.com/use-cases/karpathy-nanochat/sweep-model-size-with-one-depth-dial/
- Run a tiny Nanochat training on CPU or Apple Silicon: https://dedupedai.com/use-cases/karpathy-nanochat/try-nanochat-on-a-laptop/

## How to train a GPT-2 class chat model end to end and talk to it with Nanochat

Repo: [karpathy/nanochat](https://github.com/karpathy/nanochat) | Difficulty: Advanced | Time: 2 hours | Basis: From the README

Set up the environment, run the speedrun script, then chat with your model in the CLI.

**Who it is for:** An ML engineer who wants to see the full LLM pipeline on one GPU node.

**The problem:** Full LLM training stacks are large and hard to follow from tokenizer to chat.

**The outcome:** Your own trained model you can chat with over the CLI after about 1.5 to 2 hours on 8XH100.

### Steps

1. Run `uv sync --extra gpu` for CUDA
2. Run `source .venv/bin/activate`
3. Run `bash runs/speedrun.sh`, ideally in a screen session
4. Run `python -m scripts.chat_cli` to talk to the model

### Prompt to paste into your agent

```text
On this 8-GPU node, set up karpathy/nanochat with `uv sync --extra gpu`, run `bash runs/speedrun.sh` in a screen session, and when it finishes start `python -m scripts.chat_cli`.
```

### Caveat

Cloud GPU time costs money; the README puts the GPT-2 run at about $48, closer to $15 on a spot instance.

Risk, platform: GPUs with less than 80GB may run out of VRAM; reduce --device-batch-size until it fits.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/karpathy-nanochat/train-your-own-gpt-2-in-two-hours/

## How to train a compute-optimal miniseries by changing one depth dial with Nanochat

Repo: [karpathy/nanochat](https://github.com/karpathy/nanochat) | Difficulty: Advanced | Time: 3 hours | Basis: From the README

Run base training at different --depth values and compare validation bits per byte and CORE score.

**Who it is for:** A researcher testing an idea across model sizes.

**The problem:** Changing model size usually means retuning width, heads, learning rate and training horizon by hand.

**The outcome:** A set of compute-optimal models where only --depth changes and other hyperparameters follow.

### Steps

1. Run base training with `torchrun --standalone --nproc_per_node=8 -m scripts.base_train` and `--depth=12`
2. Repeat at other depths (GPT-2 capability is around d24 to d26)
3. Compare `val_bpb` and `core_metric` across runs
4. Check `train/mfu` and `train/tok_per_sec` for throughput

### Prompt to paste into your agent

```text
Run nanochat base_train sweeps at depth 12, 16 and 20 on this node, then tabulate val_bpb, core_metric and train/mfu for each run.
```

### Caveat

Any change to the repo should work across all depth settings.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/karpathy-nanochat/sweep-model-size-with-one-depth-dial/

## How to run a tiny Nanochat training on CPU or Apple Silicon with Nanochat

Repo: [karpathy/nanochat](https://github.com/karpathy/nanochat) | Difficulty: Intermediate | Time: 45 minutes | Basis: From the README

Use the CPU or MPS setup and the runcpu example to learn the pipeline without GPUs.

**Who it is for:** A student who wants to read and run the code before renting GPUs.

**The problem:** GPU clusters are expensive just to learn how the pipeline fits together.

**The outcome:** A shrunken model trained in tens of minutes on CPU or MPS, for learning only.

### Steps

1. Run `uv sync --extra cpu`
2. Run `source .venv/bin/activate`
3. Read and run the runs/runcpu.sh script
4. Optionally set `NANOCHAT_DTYPE=bfloat16` on recent macOS MPS to save memory

### Prompt to paste into your agent

```text
Set up nanochat for CPU with `uv sync --extra cpu`, run runs/runcpu.sh, and explain each stage it runs as it goes.
```

### Caveat

The README says you will not get strong results this way.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/karpathy-nanochat/try-nanochat-on-a-laptop/
