Build your own Large Language Model
A GPT-style language model in PyTorch: a tokenizer, attention, transformer blocks, pre-training on a small corpus, and fine-tuning.
- Advanced
- About 30–60 h
- 5 checkpoints
- 2 tutorials · Python
Pick a tutorial, then check yourself at each checkpoint. Work in any language you like.
Choose a tutorialWhy build it
Building a small GPT shows what tokens, context windows, attention and fine-tuning are, which makes the behaviour, cost and limits of production models much easier to reason about.
Before you start: Small models train on a laptop CPU; a GPU, local or rented, makes the later chapters much faster.
You will be able to
- Tokenise text with byte-pair encoding.
- Implement causal self-attention and transformer blocks.
- Pre-train a small model and sample text with temperature.
- Fine-tune for classification or instructions and evaluate the result.
Skills it exercises
- Transformer Architecture
- Tokens & Context
- Efficient PyTorch Training
- LLM Fine-Tuning
- Sequence Models & RNNs
Recommended on Applied AI Engineer and Machine Learning Engineer.
How you know you are there
Work in any language. Each checkpoint ends with something you can run or observe, so you can check it yourself.
- Checkpoint 1Self-check
Tokens and batches
Done when: Text is tokenised with BPE and served as input and target batches from a sliding window.
- Checkpoint 2Self-check
Attention
Done when: Causal multi-head attention is implemented, and a test shows no position can attend to a later one.
- Checkpoint 3Self-check
Pre-training
Done when: A small GPT trains on a public-domain corpus, validation loss falls, and samples become recognisably English.
- Checkpoint 4Self-check
Open weights
Done when: Your model loads the open GPT-2 weights and generates the same text as the reference implementation for a fixed seed.
- Checkpoint 5Self-check
Fine-tuning
Done when: Fine-tuning for spam classification or instruction following improves a stated metric on a held-out set.
Stretch goals
- LoRA fine-tuning.
- A KV cache, with the generation speed-up measured.
Step-by-step guides
Pick one in a language you know (tutorial languages: Python). They open on the author’s site.
- Python
A Large Language Model (LLM)(external site)
Python and PyTorch: the code for Sebastian Raschka's book, chapter by chapter; runs on a laptop.
- Python
Neural Networks: Zero to Hero(external site)
Video: Andrej Karpathy builds a GPT from an empty file.
Practice builds are self-paced: Tech Atlas does not track them or count them as evidence. To show a skill, take its knowledge check from the skill page.
Tutorials come from codecrafters-io/build-your-own-x (CC0, snapshot of 2026-07-14, commit aa17439; links checked on 2026-10-19). Each tutorial belongs to its author and keeps its own licence; Tech Atlas links to it and does not host it. Briefs, checkpoints and the mapping to skills are Tech Atlas editorial drafts.