GitHub · nanochat: The best ChatGPT that $100 can buy.
Open the sourceKarpathy presents nanochat as a minimal, hackable harness for running the full LLM pipeline—from tokenization and pretraining through finetuning, evaluation, and inference—on accessible hardware and budgets. He teaches a research workflow built around one complexity dial, rapid experiments at small scale, explicit metrics, and changes that generalize across model depths.
- nanochat favors a cohesive, readable end-to-end codebase over a highly configurable framework with large abstractions. - Model depth is the single user-facing complexity control; other hyperparameters are derived automatically to target compute-optimal models. - The primary optimization target is wall-clock time to exceed GPT-2's DCLM CORE score on an 8XH100 node. - Karpathy recommends iterating quickly with smaller models and judging changes through validation bits per byte, CORE score, utilization, and throughput. - Candidate improvements should be principled enough to work across the full range of model depths, not only one configuration. - Accessibility includes both low compute cost and low cognitive complexity, with a goal of enabling end-to-end work on micro models for under $1,000.
Based on Andrej Karpathy's public content. Not affiliated with or endorsed by Andrej Karpathy.
Supports these rules
Quotes from this video
“The important thing to note is that nanochat is written and configured around one single dial of complexity the depth of the transformer.”
“the trained model comes out compute optimal. The idea is that the user doesn't have to think about or set any of this, they are simply asking for a smaller or bigger model using `--depth`, and everything "just works".”
“for related documentation. For quick experimentation (~5 min pretraining runs) my favorite scale is to train a 12-layer model (GPT-1 sized), e.g. like this:”
“I like to change something in the code, re-run a d12 (or a d16 etc) and see if it helped, in an iteration loop.”
“To see if a run helps, I like to monitor the wandb plots for:”
“`val_bpb` (validation loss in vocab-size-invariant units of bits per byte) as a function of `step`, `total_training_time` and `total_training_flops`.”
“VRAM utilization, `train/mfu` (Model FLOPS utilization), `train/tok_per_sec` (training throughput)”
“The primary metric we care about is "time to GPT-2" the wall clock time needed to outperform the GPT-2 (1.6B) CORE metric on an 8XH100 GPU node.”
“Currently, the most interesting part personally is speeding up the latency to GPT-2 (i.e. getting a CORE score above 0.256525).”
“But any candidate changes to the repo have to be principled enough that they work for all settings of depth.”
“Accessibility is about overall cost but also about cognitive complexity nanochat is not an exhaustively configurable LLM "framework"; there are no giant configuration objects, model factories, or if-then-else monsters in the code base.”
“It is a single, cohesive, minimal, readable, hackable, maximally-forkable "strong baseline" codebase designed to run start to end and produce a ChatGPT model you can talk to.”