---
title: "Train a Chat Model with NanoChat"
publisher: "nvidia"
type: "playbook"
updated: "2026-08-04T16:16:47.454Z"
description: "Build a ChatGPT-style LLM end-to-end — tokenizer, pretraining, SFT — then chat via web UI or CLI"
canonical: "https://build.nvidia.com/playbooks/nanochat.md"
---

# Basic idea

[nanochat](https://github.com/karpathy/nanochat) is Andrej Karpathy’s educational ChatGPT-style training stack — popularized as the best ChatGPT that $100 can buy. This playbook walks you through training and chatting with your own model locally: tokenizer training, pretraining, midtraining / supervised fine-tuning (SFT), and inference via a simple web UI or CLI.

# What you'll accomplish

- Build a Docker environment with PyTorch and nanochat dependencies on your hardware platform
- Run the full training pipeline (BPE tokenizer → base pretraining → chat fine-tuning → report)
- Chat with your trained checkpoints through a web UI or CLI

# What to know before starting

**Required:**

- Basic Linux command line and shell usage
- Working with Docker containers and GPU passthrough
- Basic understanding of training foundation LLM models

# Supported hardware platforms

Use the matrix below to confirm your hardware platform, OS, memory, and whether multi-node applies. This playbook covers **single-node** training on the platforms listed.

| Hardware platform | OS | Memory  | Multi-node capable hardware |
| :---- | :---- | :---- | :---- |
| **DGX Station** | DGX OS (Linux) | ~288 GB HBM | — |

> [!NOTE]
> Only platforms listed in the Supported hardware platforms table above are covered by this playbook.

# Prerequisites

**Hardware requirements**

- Supported hardware platform — see Supported hardware platforms matrix above
- Adequate storage for datasets and checkpoints (~50 GB free recommended)

**Software requirements**

- Docker installed: `docker --version`
- NVIDIA Container Toolkit configured
- Verify GPU access: `nvidia-smi`
- Check Docker GPU integration (use the default container tag for your hardware platform from the matrix above):
```bash
docker run --rm --gpus all nvcr.io/nvidia/pytorch:<tag> nvidia-smi
```
- [Weights & Biases](https://wandb.ai/) account and API key (required by the launch scripts)
- [Hugging Face](https://huggingface.co/docs/hub/en/security-tokens) token (for evaluation / gated datasets)
- Network access to NGC, Hugging Face, and FineWeb / ClimbMix data

# Ancillary files

Assets live under `assets/` in this playbook:

| File | Purpose |
|------|---------|
| `Dockerfile` | Single-node image (PyTorch NGC + nanochat dependencies) |
| `setup.sh` / `launch.sh` | Single-node setup and launch |
| `speedrun_single.sh` | Single-node speedrun (default d24) |

Upstream reference: [nanochat on GitHub](https://github.com/karpathy/nanochat/).

# Time & risk

- **Estimated time:** Single-node setup is ~30 MIN; a full single-node d24 run is on the order of 12+ hours (mostly unattended compute).
- **Risk level:** Medium
- Model training is memory-intensive; changing batch size, depth, or precision can cause OOM
- Large dataset downloads and checkpoints need substantial disk space
- Launch scripts exit if `WANDB_API_KEY` or `HF_TOKEN` are unset
- **Rollback:** Stop containers, then remove caches (`~/.cache/nanochat` or local `nanochat_cache/`) and the `nanochat` Docker image (non-destructive to the host OS)
- **Last Updated:** 07/31/2026
- Removed DGX Spark support (not ready yet); playbook is Station / single-node only

# Credits

- [nanochat](https://github.com/karpathy/nanochat) by Andrej Karpathy
- [FineWeb](https://huggingface.co/datasets/HuggingFaceFW/fineweb) / ClimbMix by Hugging Face (pretraining data)
- [SmolTalk](https://huggingface.co/datasets/HuggingFaceTB/smoltalk) by Hugging Face (SFT data)

## More

- [Instructions](/playbooks/nanochat/instructions.md)
- [Troubleshooting](/playbooks/nanochat/troubleshooting.md)