Cover of Train Your Own LLM by Zafrullah Khan, Ed.D.

A beginner’s field guide to AI language models

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.


Available

Understand the machine first, then train, fine-tune, and deploy honestly.

Welcome, reader.

This page collects the book's companion resources. Everything you need is printed in the book; what's here is a convenience.

About the book

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.

Who it's for

Curious readers, managers, students: Part I (Chapters 1–3) needs no code. It covers what a model really is, an honest history, and how to decide whether to train one.

Builders: Parts II–IV are hands-on, in Python with tested scripts. They cover your workbench, data, tokenization, training, fine-tuning, LoRA/QLoRA, preferences, a tiny model from scratch, evaluation and deployment.

Part V adds case studies (Chapter 15) and capstone projects (Chapters 16–20). The book is 20 chapters in five parts, 636 pages.

Formats

Three editions on Amazon.

Editions
EditionDetailsList price (US$)Buy
Paperback, black & white 7 × 10 in, 636 pages $44.99 Buy on Amazon (external)
Premium colour paperback 7 × 10 in, 636 pages, full colour $99.99 Buy on Amazon (external)
Kindle ebook Colour ebook $24.99 Buy on Amazon (external)

List prices shown in US dollars; Amazon sets the final price at checkout.

How every chapter works

  1. Learning Objectives
  2. Story
  3. Hands-on Example
  4. Callouts
  5. Chapter Summary
  6. Try It Yourself
  7. Coming Up

Contents

20 chapters in five parts, 636 pages, 7 × 10 in.

Part I Understanding the Machine
  1. 1 What an LLM Really Is, and Whether You Should Train One Chapter 1 code · Chapter 1 toolkit
  2. 2 A Short, Honest History of How We Got Here Chapter 2 code · Chapter 2 toolkit
  3. 3 Your Model, Your Rules: Picking a Project Worth Training Chapter 3 code · Chapter 3 toolkit
Part II Foundations You Can Run
  1. 4 Setting Up Your Workbench Chapter 4 code · Chapter 4 toolkit
  2. 5 Data: The Part That Matters Most Chapter 5 code · Chapter 5 toolkit
  3. 6 Tokenization Up Close Chapter 6 code · Chapter 6 toolkit
  4. 7 How Training Actually Works Chapter 7 code · Chapter 7 toolkit
Part III Build
  1. 8 Your First Fine-Tune Chapter 8 code · Chapter 8 toolkit
  2. 9 Doing More with Less: LoRA and QLoRA Chapter 9 code · Chapter 9 toolkit
  3. 10 Teaching Preferences: DPO and a First Look at RL Chapter 10 code · Chapter 10 toolkit
  4. 11 Training a Tiny Model from Scratch Chapter 11 code · Chapter 11 toolkit
Part IV Measure, Ship, Grow
  1. 12 Is It Good Enough? Evaluating Your Model Chapter 12 code · Chapter 12 toolkit
  2. 13 Launch Day: Your Model Goes Live Chapter 13 code · Chapter 13 toolkit
  3. 14 Where to Go Next Chapter 14 code · Chapter 14 toolkit
Part V Projects and Case Studies
  1. 15 Case Studies from Documented Open Projects Chapter 15 code · Chapter 15 toolkit
  2. 16 Capstone: A Handbook Q&A Assistant Chapter 16 code · Chapter 16 toolkit
  3. 17 Capstone: A Small, Fast Classifier and Extractor Chapter 17 code · Chapter 17 toolkit
  4. 18 Capstone: A Style-Matched Writing Helper Chapter 18 code · Chapter 18 toolkit
  5. 19 Capstone: A Tiny Model That Learns Chess from Scratch Chapter 19 code · Chapter 19 toolkit
  6. 20 Capstone: Your Model on a Laptop or Phone Chapter 20 code · Chapter 20 toolkit

Code downloads

Every listing is printed in the book. These files save you typing. Large files (model checkpoints, datasets you generate) are not included; the scripts recreate them.

The companion code is MIT-licensed, (c) 2026 ai021.ai, Inc.

Companion code, by part

Part I: Understanding the Machine

Part I downloads
ChapterCodeREADMESize
1. What an LLM Really Is, and Whether You Should Train One Chapter 1 code (ZIP, 4.2 KB) Chapter 1 README (TXT, 866 B) 4.2 KB
2. A Short, Honest History of How We Got Here Chapter 2 code (ZIP, 2.0 KB) Chapter 2 README (TXT, 749 B) 2.0 KB
3. Your Model, Your Rules: Picking a Project Worth Training Chapter 3 code (ZIP, 3.3 KB) Chapter 3 README (TXT, 811 B) 3.3 KB

Part II: Foundations You Can Run

Part II downloads
ChapterCodeREADMESize
4. Setting Up Your Workbench Chapter 4 code (ZIP, 6.5 KB) Chapter 4 README (TXT, 1.0 KB) 6.5 KB
5. Data: The Part That Matters Most Chapter 5 code (ZIP, 11.8 KB) Chapter 5 README (TXT, 1.2 KB) 11.8 KB
6. Tokenization Up Close Chapter 6 code (ZIP, 7.6 KB) Chapter 6 README (TXT, 944 B) 7.6 KB
7. How Training Actually Works Chapter 7 code (ZIP, 8.4 KB) Chapter 7 README (TXT, 909 B) 8.4 KB

Part III: Build

Part III downloads
ChapterCodeREADMESize
8. Your First Fine-Tune Chapter 8 code (ZIP, 11.8 KB) Chapter 8 README (TXT, 1.1 KB) 11.8 KB
9. Doing More with Less: LoRA and QLoRA Chapter 9 code (ZIP, 10.6 KB) Chapter 9 README (TXT, 949 B) 10.6 KB
10. Teaching Preferences: DPO and a First Look at RL Chapter 10 code (ZIP, 9.1 KB) Chapter 10 README (TXT, 989 B) 9.1 KB
11. Training a Tiny Model from Scratch Chapter 11 code (ZIP, 4.7 KB) Chapter 11 README (TXT, 916 B) 4.7 KB

Part IV: Measure, Ship, Grow

Part IV downloads
ChapterCodeREADMESize
12. Is It Good Enough? Evaluating Your Model Chapter 12 code (ZIP, 17.0 KB) Chapter 12 README (TXT, 1.1 KB) 17.0 KB
13. Launch Day: Your Model Goes Live Chapter 13 code (ZIP, 12.6 KB) Chapter 13 README (TXT, 1.3 KB) 12.6 KB
14. Where to Go Next Chapter 14 code (ZIP, 2.3 KB) Chapter 14 README (TXT, 813 B) 2.3 KB

Part V: Projects and Case Studies

Part V downloads
ChapterCodeREADMESize
15. Case Studies from Documented Open Projects Chapter 15 code (ZIP, 2.6 KB) Chapter 15 README (TXT, 777 B) 2.6 KB
16. Capstone: A Handbook Q&A Assistant Chapter 16 code (ZIP, 11.3 KB) Chapter 16 README (TXT, 895 B) 11.3 KB
17. Capstone: A Small, Fast Classifier and Extractor Chapter 17 code (ZIP, 12.8 KB) Chapter 17 README (TXT, 1.1 KB) 12.8 KB
18. Capstone: A Style-Matched Writing Helper Chapter 18 code (ZIP, 11.1 KB) Chapter 18 README (TXT, 1.0 KB) 11.1 KB
19. Capstone: A Tiny Model That Learns Chess from Scratch Chapter 19 code (ZIP, 9.5 KB) Chapter 19 README (TXT, 1017 B) 9.5 KB
20. Capstone: Your Model on a Laptop or Phone Chapter 20 code (ZIP, 8.6 KB) Chapter 20 README (TXT, 1.1 KB) 8.6 KB

Checksums are in downloads.json beside the files.

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.

Chapter 1. What an LLM Really Is, and Whether You Should Train One
Chapter 2. A Short, Honest History of How We Got Here
Chapter 3. Your Model, Your Rules: Picking a Project Worth Training
Chapter 4. Setting Up Your Workbench
Chapter 5. Data: The Part That Matters Most
Chapter 6. Tokenization Up Close
Chapter 7. How Training Actually Works
Chapter 8. Your First Fine-Tune
Chapter 9. Doing More with Less: LoRA and QLoRA
Chapter 10. Teaching Preferences: DPO and a First Look at RL
Chapter 11. Training a Tiny Model from Scratch
Chapter 12. Is It Good Enough? Evaluating Your Model
Chapter 13. Launch Day: Your Model Goes Live
Chapter 14. Where to Go Next
Chapter 15. Case Studies from Documented Open Projects

Toolkit links will be added with this chapter.

Chapter 16. Capstone: A Handbook Q&A Assistant

Toolkit links will be added with this chapter.

Chapter 17. Capstone: A Small, Fast Classifier and Extractor

Toolkit links will be added with this chapter.

Chapter 18. Capstone: A Style-Matched Writing Helper

Toolkit links will be added with this chapter.

Chapter 19. Capstone: A Tiny Model That Learns Chess from Scratch

Toolkit links will be added with this chapter.

Chapter 20. Capstone: Your Model on a Laptop or Phone

Toolkit links will be added with this chapter.

Updates as tools change

No updates yet. When a library changes in a way that affects the book, you'll find the fix here.

Errata

No errata reported yet.

Found a mistake? Tell me