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
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.
Contents
20 chapters · 5 parts · Chapters 1–2 are in the free previewPart IUnderstanding the Machine3 chapters
Part IIFoundations You Can Run4 chapters
- 4Setting Up Your Workbench
- 5Data: The Part That Matters Most
- 6Tokenization Up Close
- 7How Training Actually Works
Part IIIBuild4 chapters
- 8Your First Fine-Tune
- 9Doing More with Less: LoRA and QLoRA
- 10Teaching Preferences: DPO and a First Look at RL
- 11Training a Tiny Model from Scratch
Part IVMeasure, Ship, Grow3 chapters
- 12Is It Good Enough? Evaluating Your Model
- 13Launch Day: Your Model Goes Live
- 14Where to Go Next
Part VProjects and Case Studies6 chapters
- 15Case Studies from Documented Open Projects
- 16Capstone: A Handbook Q&A Assistant
- 17Capstone: A Small, Fast Classifier and Extractor
- 18Capstone: A Style-Matched Writing Helper
- 19Capstone: A Tiny Model That Learns Chess from Scratch
- 20Capstone: Your Model on a Laptop or Phone
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
What an LLM Really Is, and Whether You Should Train One
A Short, Honest History of How We Got Here
Your Model, Your Rules: Picking a Project Worth Training
Setting Up Your Workbench
Data: The Part That Matters Most
Tokenization Up Close
How Training Actually Works
Your First Fine-Tune
Doing More with Less: LoRA and QLoRA
Teaching Preferences: DPO and a First Look at RL
Training a Tiny Model from Scratch
Is It Good Enough? Evaluating Your Model
Launch Day: Your Model Goes Live
Where to Go Next
Capstone: A Tiny Model That Learns Chess from Scratch
See all 20 downloads as a table
| Chapter | Code | README |
|---|---|---|
| 1. What an LLM Really Is, and Whether You Should Train One | ZIP, 4.2 KB | TXT |
| 2. A Short, Honest History of How We Got Here | ZIP, 2.0 KB | TXT |
| 3. Your Model, Your Rules: Picking a Project Worth Training | ZIP, 3.3 KB | TXT |
| 4. Setting Up Your Workbench | ZIP, 6.5 KB | TXT |
| 5. Data: The Part That Matters Most | ZIP, 12 KB | TXT |
| 6. Tokenization Up Close | ZIP, 7.6 KB | TXT |
| 7. How Training Actually Works | ZIP, 8.4 KB | TXT |
| 8. Your First Fine-Tune | ZIP, 12 KB | TXT |
| 9. Doing More with Less: LoRA and QLoRA | ZIP, 11 KB | TXT |
| 10. Teaching Preferences: DPO and a First Look at RL | ZIP, 9.1 KB | TXT |
| 11. Training a Tiny Model from Scratch | ZIP, 4.7 KB | TXT |
| 12. Is It Good Enough? Evaluating Your Model | ZIP, 17 KB | TXT |
| 13. Launch Day: Your Model Goes Live | ZIP, 13 KB | TXT |
| 14. Where to Go Next | ZIP, 2.3 KB | TXT |
| 15. Case Studies from Documented Open Projects | ZIP, 2.6 KB | TXT |
| 16. Capstone: A Handbook Q&A Assistant | ZIP, 11 KB | TXT |
| 17. Capstone: A Small, Fast Classifier and Extractor | ZIP, 13 KB | TXT |
| 18. Capstone: A Style-Matched Writing Helper | ZIP, 11 KB | TXT |
| 19. Capstone: A Tiny Model That Learns Chess from Scratch | ZIP, 9.5 KB | TXT |
| 20. Capstone: Your Model on a Laptop or Phone | ZIP, 8.6 KB | TXT |
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
- Chapter 1. What an LLM Really Is, and Whether You Should Train One PyTorchTransformers (v5 release notes)TRL v1SmolLM2-135MSmolLM3-3BnanochatPEFT: quantization (QLoRA)
- Chapter 2. A Short, Honest History of How We Got Here SmolLM (open training recipes)Hugging Face smol-courseOSI Open Source AI Definition
- Chapter 3. Your Model, Your Rules: Picking a Project Worth Training Hub model cardsAccelerate memory estimatorApache License 2.0MIT License
- Chapter 4. Setting Up Your Workbench PyTorch installuvvenvTransformersDatasetsPEFTTRLhuggingface_hub CLIAccelerate memory estimatorbitsandbytesTrackioGoogle Colab FAQKaggle GPU tips
- Chapter 5. Data: The Part That Matters Most DatasetsDataset cardsChat templatesTRL dataset formatsdatatrovedatabricks-dolly-15ksmoltalkultrafeedback_binarized
- Chapter 6. Tokenization Up Close TokenizersHugging Face LLM course: tokenizersChat templatesPEFT: LoRA guide
- Chapter 7. How Training Actually Works PyTorch optimization tutorialPyTorch reproducibility notesTransformers TrainerEfficient training on one GPU
- Chapter 8. Your First Fine-Tune TRL SFTTrainer
- Chapter 9. Doing More with Less: LoRA and QLoRA PEFTbitsandbytes
- Chapter 10. Teaching Preferences: DPO and a First Look at RL TRL DPO TrainerTRL GRPO Trainer
- Chapter 11. Training a Tiny Model from Scratch TinyStories datasetnanochat
- Chapter 12. Is It Good Enough? Evaluating Your Model lm-evaluation-harnesslighteval
- Chapter 13. Launch Day: Your Model Goes Live llama.cppOllamaLM StudioMLX-LMvLLMSGLangDockerHF Inference EndpointsModalRunPodGradio
- Chapter 14. Where to Go Next AcceleratePyTorch FSDP
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 meList prices in US dollars. Amazon sets the final price at checkout. Questions, errata, companion files