Build & use AI

Train Your Own LLM

A Friendly, Practical Guide to How AI Language Models Work, and How to Fine-Tune and Build One Yourself

Zafrullah Khan, Ed.D.636 pages20 chapters in 5 parts7 × 10 inFree companion materials

Choose your edition

No code needed
Part I (Ch. 1–3) is for curious readers, managers and students.
Hands-on builders
Parts II–IV: tested Python, LoRA/QLoRA, DPO, a tiny model from scratch.
Five capstones
From a handbook Q&A assistant to a model on your phone.
The book

Overview

Behind every fluent answer is one simple idea: predicting the next token.

This friendly guide shows how that trick works, then walks you from curiosity to a model you can run. Part I needs no code. Later parts cover fine-tuning on affordable hardware, training a tiny model from scratch, evaluating honestly, and deploying with clear, step-by-step recipes.

Inside every chapter
Learning objectivesStoryHands-on exampleCalloutsChapter summaryTry it yourselfComing up

Contents

20 chapters · 5 parts · Chapters 1–2 are in the free preview
Part IUnderstanding the Machine3 chapters
  1. 1What an LLM Really Is, and Whether You Should Train OneRead free
  2. 2A Short, Honest History of How We Got HereRead free
  3. 3Your Model, Your Rules: Picking a Project Worth Training
Part IIFoundations You Can Run4 chapters
  1. 4Setting Up Your Workbench
  2. 5Data: The Part That Matters Most
  3. 6Tokenization Up Close
  4. 7How Training Actually Works
Part IIIBuild4 chapters
  1. 8Your First Fine-Tune
  2. 9Doing More with Less: LoRA and QLoRA
  3. 10Teaching Preferences: DPO and a First Look at RL
  4. 11Training a Tiny Model from Scratch
Part IVMeasure, Ship, Grow3 chapters
  1. 12Is It Good Enough? Evaluating Your Model
  2. 13Launch Day: Your Model Goes Live
  3. 14Where to Go Next
Part VProjects and Case Studies6 chapters
  1. 15Case Studies from Documented Open Projects
  2. 16Capstone: A Handbook Q&A Assistant
  3. 17Capstone: A Small, Fast Classifier and Extractor
  4. 18Capstone: A Style-Matched Writing Helper
  5. 19Capstone: A Tiny Model That Learns Chess from Scratch
  6. 20Capstone: Your Model on a Laptop or Phone
Free for readers · no signup

Companion hub

Every listing is printed in the book. These files save you typing.

Code is MIT-licensed, © 2026 ai021.ai, Inc. Checksums are in downloads.json beside the files.

Code by chapter

Pick a chapter
Chapter 1 · Part I

What an LLM Really Is, and Whether You Should Train One

See all 20 downloads as a table
ChapterCodeREADME
1. What an LLM Really Is, and Whether You Should Train OneZIP, 4.2 KBTXT
2. A Short, Honest History of How We Got HereZIP, 2.0 KBTXT
3. Your Model, Your Rules: Picking a Project Worth TrainingZIP, 3.3 KBTXT
4. Setting Up Your WorkbenchZIP, 6.5 KBTXT
5. Data: The Part That Matters MostZIP, 12 KBTXT
6. Tokenization Up CloseZIP, 7.6 KBTXT
7. How Training Actually WorksZIP, 8.4 KBTXT
8. Your First Fine-TuneZIP, 12 KBTXT
9. Doing More with Less: LoRA and QLoRAZIP, 11 KBTXT
10. Teaching Preferences: DPO and a First Look at RLZIP, 9.1 KBTXT
11. Training a Tiny Model from ScratchZIP, 4.7 KBTXT
12. Is It Good Enough? Evaluating Your ModelZIP, 17 KBTXT
13. Launch Day: Your Model Goes LiveZIP, 13 KBTXT
14. Where to Go NextZIP, 2.3 KBTXT
15. Case Studies from Documented Open ProjectsZIP, 2.6 KBTXT
16. Capstone: A Handbook Q&A AssistantZIP, 11 KBTXT
17. Capstone: A Small, Fast Classifier and ExtractorZIP, 13 KBTXT
18. Capstone: A Style-Matched Writing HelperZIP, 11 KBTXT
19. Capstone: A Tiny Model That Learns Chess from ScratchZIP, 9.5 KBTXT
20. Capstone: Your Model on a Laptop or PhoneZIP, 8.6 KBTXT

Toolkit by chapter

Chapters 8–14 links are based on the outline and will be confirmed against the final text. Link check, Oct 8, 2026: the 65 links in this list returned HTTP 200.

All toolkit links

Updates

No updates yet. When a library changes in a way that affects the book, the fix appears here.

Errata

No errata reported yet.

Found a mistake? Tell me
Free lessons that pair with this book: The guessing machineWrite the test firstRight vs Checked

About Zafrullah Khan, Ed.D.

Futurist and AI researcher, founder and CEO of ai021.ai, Inc. Thirty years in education, from Durban to South Dakota to Middle Tennessee State University, now building small language models that answer from source-linked knowledge.

Full biography →

List prices in US dollars. Amazon sets the final price at checkout. Questions, errata, companion files

Your bag

Your bag is empty. Add a paperback from the shelf.

    List total$0.00
    Check out on Amazon

    Every paperback lands in your Amazon cart at once. Kindle editions are bought on their own Amazon page. Amazon sets the final price.

    Contact

    Let's talk

    Pick a topic and we'll take it from there.

    Topic