Build a ChatGPT-style LLM end-to-end — tokenizer, pretraining, SFT — then chat via web UI or CLI
NOTE
These instructions target single-node training on Linux (default d24 speedrun) for the hardware platforms listed in the Overview.
To manage containers without sudo, add your user to the docker group. Open a terminal and test Docker access:
docker ps
If you see a permission-denied error, add your user to the docker group (skip if it already works):
sudo usermod -aG docker $USER
newgrp docker
Nanochat uses Weights & Biases for training visualization and a Hugging Face token for evaluation datasets. Export both in your shell:
export WANDB_API_KEY=<YOUR_WANDB_API_KEY>
export HF_TOKEN=<YOUR_HF_TOKEN>
export WANDB_RUN=speedrun # optional run name
Create a W&B account and a Hugging Face token if you do not have them. The launch script exits immediately if either key is unset.
Clone the playbook repository and navigate to the assets directory:
git clone https://github.com/NVIDIA/dgx-spark-playbooks
cd dgx-spark-playbooks/nvidia/playbook-nanochat/assets
Run the single-node setup script. It clones nanochat, checks out the supported commit, copies speedrun_single.sh, and builds the nanochat Docker image:
chmod +x setup.sh launch.sh
./setup.sh
Confirm the image built:
docker images | grep nanochat
Your directory structure after setup should look like:
assets/
├── Dockerfile
├── launch.sh
├── setup.sh
├── speedrun_single.sh
└── nanochat/
Ensure your API keys are still exported, then launch:
./launch.sh
NOTE
On a multi-GPU host, default --gpus all may not select the intended GPU. Set GPU_DEVICE to pin a device (N from nvidia-smi):
GPU_DEVICE='"device=N"' ./launch.sh
The training container runs the full pipeline automatically:
report.mdA full d24 run is on the order of 12+ hours. Keep the terminal open or use tmux / screen.
Track progress at wandb.ai under the nanochat project (the run URL appears in the training logs). Key metrics:
After training, checkpoints are under nanochat_cache/. Run inference from a container with the same GPU selection as training.
Web UI (recommended):
docker run --rm --gpus all --net=host \
-v $(pwd)/nanochat:/workspace/nanochat \
-v $(pwd)/nanochat_cache:/root/.cache/nanochat \
-w /workspace/nanochat \
nanochat \
python -m scripts.chat_web
Open a browser to http://<HOST_IP>:8000. If you are on a remote SSH session, forward the port:
ssh -L 8000:localhost:8000 username@<HOST_IP>
CLI:
docker run --rm -it --gpus all \
-v $(pwd)/nanochat:/workspace/nanochat \
-v $(pwd)/nanochat_cache:/root/.cache/nanochat \
-w /workspace/nanochat \
nanochat \
python -m scripts.chat_cli -p "Why is the sky blue?"
To stop training early:
WARNING
This stops the training run and any in-progress work in the container.
# If launch.sh is running: press Ctrl+C
# Or stop the container directly
docker stop $(docker ps -q --filter ancestor=nanochat)
To free disk space (cache dirs are often root-owned because the container runs as root):
sudo rm -rf ./nanochat_cache ./hf_cache
docker rmi nanochat
Smaller / faster run: Edit speedrun_single.sh before setup to reduce data and model size:
# Fewer data shards
python -m nanochat.dataset -n 10 &
# Smaller model (d4 instead of d24), smaller batch size
python -m scripts.base_train --depth=4 --device-batch-size=32
Then re-run ./setup.sh to rebuild with the changes.
Batch size: The default --device-batch-size=64 is tuned for high-memory hardware platforms. Lower it (32, 16, 8) if you hit OOM.