#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.

Stars
109.3k
License
custom license
Last commit
Nov 2026
Language
Jupyter Notebook
Stars, last 35 weeks+21,279
24 Mar 2026: 87,986 stars31 Mar 2026: 88,507 stars7 Apr 2026: 89,148 stars14 Apr 2026: 89,718 stars21 Apr 2026: 90,179 stars28 Apr 2026: 90,670 stars5 May 2026: 91,033 stars12 May 2026: 93,061 stars19 May 2026: 94,288 stars26 May 2026: 95,191 stars2 Jun 2026: 95,719 stars9 Jun 2026: 96,147 stars16 Jun 2026: 96,541 stars23 Jun 2026: 96,908 stars30 Jun 2026: 97,601 stars7 Jul 2026: 98,113 stars14 Jul 2026: 98,511 stars21 Jul 2026: 98,986 stars28 Jul 2026: 99,552 stars4 Aug 2026: 100,105 stars11 Aug 2026: 102,033 stars18 Aug 2026: 102,606 stars25 Aug 2026: 103,473 stars1 Sept 2026: 103,905 stars8 Sept 2026: 104,376 stars15 Sept 2026: 104,852 stars22 Sept 2026: 105,268 stars29 Sept 2026: 105,672 stars6 Oct 2026: 106,094 stars13 Oct 2026: 106,499 stars20 Oct 2026: 107,029 stars27 Oct 2026: 107,491 stars3 Nov 2026: 107,911 stars10 Nov 2026: 108,381 stars17 Nov 2026: 108,807 stars24 Nov 2026: 109,265 stars

87,986 on 24 Mar 2026109,265 on 24 Nov 2026

From GitHub's daily star counts.

Checked on GitHub.

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
Also in Learning and cookbooks
RankProjectScore
#10ai-infra-bookA quantitative book on AI infrastructure design, with calculation tools Live demo ↗ (opens in a new tab)8.4k starsApache-2.079 out of 100
#11openai-cookbookRunnable notebooks and guides for common tasks with the OpenAI API77.6k starsMIT78 out of 100
#13awesome-ai-appsCollection of 141 runnable LLM agent and RAG example apps17.2k starsMIT77 out of 100
#14ml-for-beginners12-week, 26-lesson classic machine learning course using Scikit-learn Live demo ↗ (opens in a new tab)92.5k starsMIT76 out of 100
#15rag_techniquesCollection of 42 runnable notebooks implementing RAG techniques30.6k starscustom license76 out of 100