mrkeyoor.comAsk

karpathy/nanoGPTtested 12 Oct 2026commit 3adf61e

nanoGPT review

Use nanoGPT to study or modify Karpathy's compact PyTorch training implementation, with responsibility for your own fork and experiment configuration.

  • README install 40 s
  • README snippet failed
9 sto install
  • 5705.2 MB on disk
  • 77 dependencies
LLM Toolsevaluationupdated 22 Nov 2026
+146stars / 7d

nanoGPT is Andrej Karpathy's Python repository for training GPT models from scratch, adapting pretrained GPT-2 weights and generating text. Its November 2025 README notice marks it deprecated and directs new users to nanochat.

Verdict

Use nanoGPT to study or modify Karpathy's compact PyTorch training implementation, with responsibility for your own fork and experiment configuration. Skip it as the starting point for a project that depends on ongoing upstream development: its README marks it deprecated and recommends nanochat.

nanoGPT infographic: training GPT models and generating text, plus its uses, our test result, pitfalls and who it suits
Tested 20 November 2026: the README snippet failed. Before that: 12 Oct: source install 9 s, build 2 s; uv install took 40 s.

We ran it

Lab card: what happened when we ran nanoGPT
Lab card from our sandbox run
Screenshot of nanoGPT (github.com/karpathy/nanoGPT)
github.com/karpathy/nanoGPT
Install✓ · 9s35 packages · 38 MB
Build✓ · 2s
Testsn/ano test script
Known vulns0(pip-audit)
Repo26 files~1,235 lines of source · 0.6 MB · 0 CI workflows

Answers from our run

Does nanoGPT build from source?

Dependencies installed in 9 seconds (35 packages), and the build succeeded in 2 seconds. We cloned commit 3adf61e into a clean Debian container with 3 CPUs and no project-specific setup.

Does nanoGPT have tests you can run?

Not through a standard command: the project exposes no test script or target that our harness could run.

Does nanoGPT have known vulnerabilities in its dependencies?

pip-audit found none in the dependency tree at the time of our run.

Who should not use nanoGPT?

Developers choosing a new project that depends on ongoing upstream development: the README recommends nanochat.

What are the alternatives to nanoGPT?

nanochat, llm.c. Use nanoGPT to study or modify Karpathy's compact PyTorch training implementation, with responsibility for your own fork and experiment configuration.

Setup4/5In our 2026-11-20 run it installed as the README says in 40 s; the README gave no task we could run as written.Editor’s note: Setup observations exist, but neither dated run completed the documented training and sampling workflow.
Docs4/5The README has an install section (“install”) and a usage section (“quick start”); we did not run its quickstart ourselves.Editor’s note: The README contains concrete commands, but the recorded runs do not reproduce the workflow end to end.
Community2/5Last push on 2025-11-12, 64,999 stars and maintainers answered or closed 4 of the 10 most-discussed issues we sampled.Editor’s note: Named issue discussions document troubleshooting, but this sample does not measure support responsiveness.
Maturity2/5No tagged GitHub release and repository created 2022-12-28.Editor’s note: The README marks the repository deprecated, and the recorded runs contain no passing test suite or training benchmark.

How we score

Discussed on

  1. hnNanoGPT1,532 points
  2. hnNanoGPT: The simplest, fastest repository for training medium-sized GPTs114 points
  3. hnkarpathy/build-nanogpt: Video + code lecture on building nanoGPT from scratch9 points
  4. hnShow HN: Karpathy's Nanogpt but for Audio7 points
  5. hn[Andrej Karpathy] Let's reproduce GPT-2, in PyTorch from scratch (nanoGPT)7 points

Who it’s for

Developers with basic PyTorch knowledge who want to inspect or change this particular model and training loop.
Learners using the reduced Shakespeare configuration to study training and text generation.
Researchers willing to maintain their own fork of deprecated code.

Who it’s NOT for

Developers choosing a new project that depends on ongoing upstream development: the README recommends nanochat.
Buyers looking for the separately branded NanoGPT subscription service or API.
Users who need a maintained training platform rather than responsibility for the experiment configuration.

Setup reality

Our October 12, 2026 run at commit 3adf61e installed successfully in 9 seconds and built in 2 seconds. It recorded 35 dependencies and 38 MB on disk. Tests were skipped because no script or target existed; pip-audit reported 0 known vulnerabilities. The recorded sandbox configuration was 3 CPUs, 8 GB RAM and image ghcr.io/astral-sh/uv:python3.12-bookworm.

Our separate November 20, 2026 run at commit 3adf61e154c3 used a fresh environment in a 2-CPU, 4 GB container. It installed torch 2.15.0 in 39.8 seconds, recorded 5705.2 MB in venv site-packages and counted 77 packages besides torch. Its quickstart-lib recipe stopped at a no-snippet finding because it expected a Python code block in the README. Teardown completed successfully.

The README's workflow prepares data, trains and samples a checkpoint through shell commands. It supplies reduced CPU settings with compilation disabled and an Apple Silicon MPS route. Weights & Biases logging is optional.

Our October nanoGPT setup recorded a 9-second install and a 2-second build; November's fresh environment occupied 5705.2 MB. Use Karpathy's repository to study or change its PyTorch training loop. For a new project that depends on upstream development, follow its README's recommendation to nanochat.

The README directs new users to nanochat

nanoGPT's November 2025 README notice marks the repository deprecated and recommends nanochat. The nanoGPT README describes training models from scratch, fine-tuning pretrained GPT-2 checkpoints and generating text with sample.py. Fine-tuning adapts existing weights to new text; sampling generates a continuation from model weights. Those jobs give a reader separate entry points for understanding how training changes a model and how the resulting checkpoint produces text.

The README describes train.py as a roughly 300-line training loop and model.py as a roughly 300-line model definition. That concentration makes this particular implementation useful to readers who want to follow the code directly. The adoption decision starts with its status, however: the maintainer recommends another repository for new users. Choose nanoGPT because studying or modifying this implementation is your purpose, and because you are prepared to own the resulting configuration and fork.

What people use nanoGPT for

GitHub users describe Shakespeare training on an M1, GPT-2 experiments on larger datasets and changes to the model architecture. The reports below name their authors and outcomes so a learning exercise, a reproduction attempt and an invalid result stay distinguishable. A low loss has a different meaning when a model generates usable continuations than when its architecture accidentally exposes future text during prediction.

Person and task Reported outcome What you should take from it
stefanbschneider trained Shakespeare on an M1 Training used MPS with compilation disabled; the user reported loss 1.2 after 2000 iterations at 700-800 ms per iteration. The report identifies a reduced model configuration and a separate sampling problem.
bigsnarfdude trained GPT-2 models on OpenWebText and RedPajama The commenter reported training 124M, medium and large models and described around 100,000 iterations to reach comparable losses. This is bigsnarfdude's account of training, with configuration advice in the same discussion.
englertbruno tried a UNet-style architecture The author traced the unusually low loss to broken causality during compression and expansion. Generated sentences exposed a problem that the loss alone concealed.

A fourth learning example comes from intchrkl's separate implementation inspired by nanoGPT. Its author describes learning transformer components, and its output is described as poorly comprehensible while resembling Shakespeare's style. The repository identity matters here: this is an educational derivative. It illustrates learning through implementation rather than another result from running karpathy/nanoGPT.

What happened when we ran it

Our October 12, 2026 run at commit 3adf61e installed in 9 seconds and built in 2 seconds. It recorded 35 dependencies and 38 MB on disk. Our separate November 20 run at 3adf61e154c3 used a fresh environment in a 2-CPU, 4 GB container. The tables keep each observation attached to its date and counting scope.

Question Answer Verdict Why
Did October installation complete? Yes, in 9 seconds; 35 dependencies and 38 MB were recorded. Setup step succeeded. These are the October harness measurements.
Did October build complete? Yes, in 2 seconds. Build step succeeded. The recorded command exited successfully.
Did October tests pass? Tests were skipped because no script or target existed. No passing test result. Test discovery had no target to execute.
What did October dependency auditing report? pip-audit reported 0 known vulnerabilities. No known advisories reported by that audit. This is the recorded audit outcome.
What did the October repository scan find? 26 files, approximately 1,235 source lines and 0.6 MB checked out. Small source checkout. The figures describe repository files.
What supporting files did October find? 0 CI workflow files, no Dockerfile and no tests directory. Those files were absent from the scan. These are repository scan signals.

November's quickstart-lib recipe cloned in 1 second. It then ran the README dependency list through uv pip install in a fresh virtual environment. The installation, size and package-count records describe that environment separately from October's harness. They also make the distinction between a 0.6 MB source checkout and an installed Python environment concrete.

Question Answer Verdict Why
What did November install? torch 2.15.0 in 39.8 seconds, using the README dependency list. Installation completed. The record names the installed torch version and elapsed time.
How much space did November's environment occupy? 5705.2 MB in venv site-packages. Recorded installed footprint. The measurement names the directory counted.
How many packages did November count? 77 packages besides torch. Recorded dependency count. The count explicitly excludes torch.
Did the quickstart recipe execute its snippet? The snippet step failed because the README had no Python code block to run. Recipe stopped with no-snippet. The recipe expected a Python block; the README presents shell commands.
Was the failure recorded as a finding? The finding was no-snippet. Recipe mismatch identified. The finding repeats the missing Python-block condition.
Did teardown complete? Teardown returned ok. Cleanup succeeded. This is the final recorded step.

Where people get stuck: training and sampling fail differently

Issue #150 reports successful MPS training followed by an MPS sampling abort. In stefanbschneider's account, the reduced Shakespeare run used --device=mps --compile=False, took 700-800 ms per iteration and ended at loss 1.2 after 2000 iterations. Sampling then aborted with an MPSNDArray dimension assertion. The user reported that switching sampling to --device=cpu worked.

Symptom and reporter What helped in the discussion Status described by the evidence
#150: missing torch.amp and an MPS sampling abort abcdggs described a fresh Python 3.8 environment with preview PyTorch; stefanbschneider sampled on CPU. Different users reported different environment and device problems.
#167: float16 NaN loss holyseven used float32; oddlama disabled fused AdamW; cdalinghaus reverted from nightly PyTorch to 1.13.1. The thread contains several reported workarounds.
#137: loss fell and then rose Commenters changed flash attention, AdamW epsilon or CUDA; jbaiter also saw the behavior on CUDA 11.7 with 8 A100s. The CUDA 11.7 reports conflict.
#303: OpenWebText loss stayed high Commenters changed attention or gradient accumulation. JustinKunzi finished with loss within 0.5 of 7.0 for nearly the entire run.

The NaN discussion shows why the sequence of observations matters. In issue #167, numerical changes initially appeared to help, but NaNs returned after 20,000 iterations. NaN denotes a calculation result that is not a valid number. The useful troubleshooting record includes the dtype, optimizer, PyTorch build and recurrence, rather than only the first improvement after a setting changed.

Fewer GPUs change the configuration you must compare

Issue #468 describes a reduced-GPU reproduction attempt that still struggled after suggested settings were restored. banyan-god's follow-up reported that gradient accumulation of 40 did not solve the problem, and yalding asked about the configuration logged in Weights & Biases. That exchange puts the actual recorded settings ahead of assumptions based on the launch command.

In issue #285, pyotr777 explains that block size is sequence length, while batch and accumulation settings determine how many training tokens contribute before weights update. Gradient accumulation combines work from multiple small batches before that update. Reducing context length changes the text available within each chunk; reducing the effective batch changes the text contributing to an update. Record both settings when comparing runs, along with precision, model dimensions and data preparation.

Windows preparation and compilation have separate reports

Issue #153 records Windows data-preparation problems involving PATH, multiprocessing and array sizes. The Windows preparation discussion includes a PATH correction, a small dataset subset with num_proc=1, and a main-module guard as reported responses. It also includes ValueError: could not broadcast input array from shape (8665630,) into shape (4537790,). These are distinct steps and errors, rather than one installation symptom.

Issue #11 concerns a different path: combining a torch.jit.script decorator on fused_gelu with torch.compile. The compilation discussion reports 138 ms per iteration with the decorator and 118 ms without it. Karpathy identified commit 177d5f7dc5f44d6f373cd7767c2a9259d740436e as addressing that issue. Those numbers belong to the issue's benchmark, while our measurements above describe installation and build steps.

The README documents preparation, training and sampling commands

The nanoGPT README starts its Shakespeare workflow with data preparation, then runs training and samples the saved checkpoint. Its quickstart commands are shown below as documentation examples. prepare.py creates train.bin and val.bin; the training configuration writes checkpoints under out-shakespeare-char, and the sampling command selects that directory.

python data/shakespeare_char/prepare.py
python train.py config/train_shakespeare_char.py
python sample.py --out_dir=out-shakespeare-char

The README's CPU route changes more than the device: it disables compilation, reduces context to 64 characters, uses batch size 12 and selects a four-layer, four-head model with embedding size 128. Its reduced run sets 2000 iterations. The CPU instructions explain those settings together; copying only a device flag would select a different configuration. The dependency list also identifies wandb as optional logging.

nanoGPT vs nanochat and llm.c

nanoGPT's README recommends nanochat, while llm.c's README centers C/CUDA training implementations. The comparison below follows those documented scopes. It is most useful when the choice is about which code you want to inspect or maintain: the existing nanoGPT loop, nanochat's broader workflow, or the C and CUDA implementation in llm.c.

Choice Documented scope Pick it when
nanoGPT Python GPT training, pretrained GPT-2 loading, fine-tuning and sampling scripts. You want to study or modify this particular implementation.
nanochat Tokenization, pretraining, finetuning, evaluation and inference. You want the broader workflow recommended by nanoGPT's maintainer.
llm.c C/CUDA implementations with a parallel PyTorch reference in train_gpt2.py. Your purpose is understanding or changing C and CUDA training code.

The separately branded NanoGPT hosted service belongs to a different buying decision. Its API documentation describes creating a key and configuring a client. In r/SillyTavernAI, OGDREADLORD666 preferred OpenRouter after reporting poorer instruction following on that service; No_Alfalfa_9088 described the opposite experience or no fundamental difference. Those comments concern hosted access, not the behavior of Karpathy's training scripts.

Outdated claims, corrected

Issue #81's low-loss UNet proposal was corrected by its author after discovering broken causality. englertbruno explained that compression and expansion let the architecture break the restriction against looking forward in time. The same explanation connected the loss result to poor sentence generation. The proposed lower loss therefore changes meaning once the author's follow-up is read.

Two other corrections concern the hosted service's pages. DeepReview's NanoGPT review advertises a 5% referral discount, but the service API documentation excludes requests billed with provider-selection pricing or markup, including caching mode and pinned providers. Automatic routing and automatic provider caching remain eligible according to that documentation. The discount condition belongs with the claim whenever API pricing is discussed.

The vendor's NanoGPT versus ChatGPT Plus article calls roughly 200 monthly GPT-4o-level messages the break-even point against $20. Its own estimate is $0.01 to $0.05 per conversation. Multiplying that range by 200 gives $2 to $10. The article switches between messages and conversations, so its arithmetic does not support the stated threshold. Neither pricing correction changes the identity or scope of karpathy/nanoGPT.

FAQ

Karpathy's nanoGPT repository is karpathy/nanoGPT, and its README directs new users to nanochat. The questions below separate repository identity, the documented learning workflow and issue-specific training behavior. They also distinguish the small Shakespeare configuration from GPT-2 reproduction, which uses different model sizes and hardware in the README.

Where is Andrej Karpathy's nanoGPT GitHub repository?

The original repository is github.com/karpathy/nanoGPT. Its November 2025 notice says it is deprecated and points to nanochat. The owner name separates it from intchrkl/nanogpt, an educational derivative, and from the hosted NanoGPT service. For this review, the software identity is Karpathy's Python training repository, with the two dated setup observations attached to their recorded commits.

How does nanoGPT differ from nanochat?

nanochat documents tokenization, pretraining, finetuning, evaluation and inference, whereas nanoGPT documents its GPT training, fine-tuning and sampling workflow. The nanoGPT maintainer's recommendation is explicit in the deprecation notice. Choose between them according to the code and workflow you intend to own: nanoGPT's particular loop for study or modification, or the broader project its maintainer recommends to new users.

How can I build a GPT model from scratch?

The nanoGPT Shakespeare quickstart prepares text with data/shakespeare_char/prepare.py, trains with config/train_shakespeare_char.py and samples from out-shakespeare-char. The README gives separate GPU and reduced CPU configurations. Following that sequence keeps data preparation, model updates and generated output as separate steps, each with its own command and resulting files.

How do I train nanoGPT on an M1 Mac?

stefanbschneider reported M1 training with MPS and compilation disabled. The reported reduced configuration used context 64, batch size 12, four layers, four heads and embedding size 128. It reached loss 1.2 after 2000 iterations at 700-800 ms per iteration. The same user later reported an MPS sampling abort and successful sampling on CPU.

Why does training loss become NaN, and does float16 cause it?

Issue #167 contains float16 NaN reports, with different users reporting relief from float32, disabling fused AdamW or reverting from nightly PyTorch to 1.13.1. One attempted numerical workaround was followed by recurrence after 20,000 iterations. The thread is useful for identifying what to record about a failure: precision, optimizer settings, runtime build and the iteration where NaNs appear.

Why does batch size affect convergence, and how is it different from block size?

pyotr777 describes block size as sequence length in issue #285, and explains batch size in terms of training tokens seen before a weight update. The comment includes micro batch size, accumulation steps and parallel processes in that accounting. This distinction helps explain why reducing context and changing GPU count require more careful comparison than matching a single configuration value.

What we have not tested yet

The October and November records do not establish why their installed footprints differ: October recorded 38 MB and 35 dependencies, while November measured 5705.2 MB in site-packages and 77 packages besides torch. The storage requirement is unresolved; 38 MB is not a reliable dependency-storage expectation. October's container image label also does not establish actual runtime versions, which require the toolchain logs. Its 8 GB allocation is environment context rather than a measured training requirement.

Our runs contain no completed training or generation benchmark, Mac compatibility test, checkpoint-recovery test, long-run convergence test, private-data assessment or controlled comparison with nanochat or llm.c. The README commands above are documentation examples, not commands executed as part of this correction. November's no-snippet result is a recipe failure, not a training failure. Historical issue workarounds are attributed reports rather than current-stack compatibility results, and the advisory scan is not a security review.

A complete Shakespeare sequence on a named hardware and software stack would answer the next practical question: whether data preparation, training, checkpoint saving and sampling work together in that environment. Such a result should retain the actual runtime versions, configuration and generated output alongside the timing. The existing measurements describe setup and repository inspection; the community discussions describe their authors' experiments.

Alternatives

ProjectWhat it isPick it when
nanochat gh↗A training harness covering tokenization, pretraining, finetuning, evaluation and inference.Choose it for the broader training workflow recommended by nanoGPT's own README.
llm.cC/CUDA training implementations with a parallel PyTorch reference.Choose it when studying or changing C and CUDA training code is your purpose.

Sources

  1. nanoGPT README and deprecation notice
  2. nanochat training harness
  3. llm.c training implementation

More llm tools reviews