#1212th of 171 in Learning and cookbooks
llms-from-scratch
Book code for building, pretraining and finetuning a GPT-style LLM in PyTorch
Run it:Vast.ai ↗ (opens in a new tab)Clore.ai ↗ (opens in a new tab)Affiliate links, no effect on a rank.
Watch puts llms-from-scratch on your watch list: its new releases and known problems since your last visit. Kept in this browser, no account.llms-from-scratch is on your watch list. Its new releases and problems show there.
- Stars
- 109.3k
- License
- custom license
- Last commit
- Nov 2026
- Language
- Jupyter Notebook
87,986 on 24 Mar 2026109,265 on 24 Nov 2026
From GitHub's daily star counts.
Checked on GitHub.
- Gemma 3 270M re-implemented in pure PyTorch for local tinkering (opens in a new tab) (417 points, Aug 2025)
- Finetuning an LLM-Based Spam Classifier with LoRA from Scratch (opens in a new tab) (14 points, May 2024)
- Implementing a ChatGPT-like LLM from scratch, step by step (opens in a new tab) (739 points, Jan 2024)
Overview
Official code for the book Build a Large Language Model (From Scratch). Jupyter notebooks walk through a tokenizer, attention, a GPT model, pretraining, classification finetuning, instruction finetuning, DPO and LoRA in plain PyTorch, with no external LLM libraries. Bonus folders cover Llama 3.2, Qwen3, Gemma 3, Olmo 3, KV cache, GQA and MoE.
Who it is for: Engineers learning how LLMs work by coding one in PyTorch
Strengths
- Chapter notebooks with exercise solutions, plus a 17-hour companion video course
- Implements everything in plain PyTorch without external LLM libraries
- Main chapter code runs on a laptop and uses a GPU automatically if present
- Bonus folders cover KV cache, GQA, MoE, DPO and several open model architectures
Weaknesses
- Tied to a print book; extensions to main chapter code are not accepted
- Trains small educational models, not production-scale ones
- License is detected as NOASSERTION, so terms need checking in the repo
- Study material only; not a library or tool to deploy
What it needs
- GPU optional
- Needs PyTorch, Jupyter, Ollama (optional, chapter 7 evaluation)
- Models: GPT-2, Llama 3.2, Qwen3, Gemma 3, Olmo 3
Also in Learning and cookbooks
See all 171| Rank | Project | Score |
|---|---|---|
| #10 | ai-infra-bookA quantitative book on AI infrastructure design, with calculation tools | 79 out of 100 |
| #11 | openai-cookbookRunnable notebooks and guides for common tasks with the OpenAI API | 78 out of 100 |
| #13 | awesome-ai-appsCollection of 141 runnable LLM agent and RAG example apps | 77 out of 100 |
| #14 | ml-for-beginners12-week, 26-lesson classic machine learning course using Scikit-learn | 76 out of 100 |
| #15 | rag_techniquesCollection of 42 runnable notebooks implementing RAG techniques | 76 out of 100 |