nanogpt

Train and fine-tune minimalist GPT models in PyTorch from scratch.

5|2|Updated Aug 10, 2026
One-click install
npx skills add https://github.com/MedTiLab/Auto-meta-analysis --skill nanogpt-medtilab
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: nanogpt
Source: https://github.com/MedTiLab/Auto-meta-analysis/tree/main/skills/model-architecture/nanogpt
Command: npx skills add https://github.com/MedTiLab/Auto-meta-analysis --skill nanogpt-medtilab

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, transformers, datasets, tiktoken, wandb, and includes references (resource) components.

What problem does it solve? Learning how GPT models work internally is difficult when production frameworks hide implementation behind layers of abstraction, making it hard to experiment with transformer architecture or train a language model on limited hardware. ## Core Features & Use Cases - Minimal GPT Implementation: A complete GPT-2 architecture in roughly 300 lines of readable PyTorch code covering attention, MLP blocks, and autoregressive generation. - Flexible Training Pipelines: Train character-level models on Shakespeare in minutes on CPU, reproduce GPT-2 124M on OpenWebText with multi-GPU DDP, or fine-tune from OpenAI pretrained checkpoints. - Custom Dataset Support: Prepare your own text corpora with character-level or BPE tokenization saved as memory-mapped binary files. - Use Case: A student wants to understand transformers hands-on, so they train a small character-level model on Shakespeare in five minutes on a laptop CPU, then inspect the attention and training loop code line by line. ## Quick Start Train a small GPT model on the Shakespeare dataset using nanoGPT and then generate sample text from the trained checkpoint.

Frequently Asked Questions about nanogpt

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I train a GPT model from scratch with nanoGPT?▼

Prepare a dataset with the provided prepare.py script to create train.bin and val.bin token files, then run train.py with a config file. For a quick start, train a character-level model on Shakespeare in about five minutes on CPU.

How to fine-tune pretrained GPT-2 on a custom dataset?▼

Set init_from to gpt2, gpt2-medium, gpt2-large, or gpt2-xl in your config to load OpenAI weights automatically. Use a lower learning rate around 3e-5, add dropout for regularization, and point the dataset parameter at your prepared token files.

nanoGPT vs HuggingFace Transformers for training language models?▼

nanoGPT is best for learning and experimentation since the entire model and training loop fit in about 600 lines of hackable PyTorch. HuggingFace Transformers suits production use with many pretrained architectures and high-level APIs.

Can nanoGPT train on CPU without a GPU?▼

Yes, the character-level Shakespeare config trains on CPU in about five minutes with a small 6-layer, 384-dimensional model. Larger models like GPT-2 124M require GPUs, roughly four days on eight A100s.

Why does nanoGPT run out of CUDA memory during training?▼

CUDA out of memory occurs when batch size or context length exceeds VRAM. Reduce batch_size and block_size, increase gradient_accumulation_steps to keep the effective batch, and enable bfloat16 dtype to cut memory usage roughly in half.

What are the limitations of nanoGPT for production use?▼

nanoGPT lacks the abstractions, model zoo, and deployment tooling of production frameworks. For large-scale distributed training use Megatron-LM, and for production-ready multi-architecture support consider LitGPT or HuggingFace Transformers.