From the creator of Agent Memory - #1 Persistent memory ⭐
which naturally works with any agents or chat assistants.
░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒
84% of students already use AI tools. Only 18% feel prepared to use them professionally. This curriculum closes that gap.
503 lessons. 20 phases. ~320 hours. Python, TypeScript, Rust, Julia. Every lesson ships a reusable artifact: a prompt, a skill, an agent, an MCP server. Free, open source, MIT.
You don't just learn AI. You build it. End-to-end. By hand.
150,639 readers · 241,669 page views in the last 30 days · as of 2026-06-07
How this works
Most AI material teaches in scattered pieces. A paper here, a fine-tuning post there, a flashy agent demo somewhere else. The pieces rarely line up. You ship a chatbot but can't explain its loss curve. You hook a function to an agent but can't say what attention does inside the model that's calling it.
This curriculum is the spine. 20 phases, 503 lessons, four languages: Python, TypeScript, Rust, Julia. Linear algebra at one end, autonomous swarms at the other. Every algorithm gets built from raw math first. Backprop. Tokenizer. Attention. Agent loop. By the time PyTorch shows up, you already know what it's doing under the hood.
Each lesson runs the same loop: read the problem, derive the math, write the code, run the test, keep the artifact. No five-minute videos, no copy-paste deploys, no hand-holding. Free, open source, and built to run on your own laptop.
░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒
The shape of the curriculum
Twenty phases stack on top of each other. Math is the floor. Agents and production are the roof. Skip ahead if you already know the lower layers, but don't skip and then wonder why something at the top is breaking.
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#fafaf5','primaryTextColor':'#1a1a1a','primaryBorderColor':'#3553ff','lineColor':'#3553ff','fontFamily':'JetBrains Mono','fontSize':'12px'}}}%%
flowchart TB
P0["Phase 0 — Setup & Tooling"] --> P1["Phase 1 — Math Foundations"]
P1 --> P2["Phase 2 — ML Fundamentals"]
P2 --> P3["Phase 3 — Deep Learning Core"]
P3 --> P4["Phase 4 — Vision"]
P3 --> P5["Phase 5 — NLP"]
P3 --> P6["Phase 6 — Speech & Audio"]
P3 --> P9["Phase 9 — RL"]
P5 --> P7["Phase 7 — Transformers"]
P7 --> P8["Phase 8 — GenAI"]
P7 --> P10["Phase 10 — LLMs from Scratch"]
P10 --> P11["Phase 11 — LLM Engineering"]
P10 --> P12["Phase 12 — Multimodal"]
P11 --> P13["Phase 13 — Tools & Protocols"]
P13 --> P14["Phase 14 — Agent Engineering"]
P14 --> P15["Phase 15 — Autonomous Systems"]
P15 --> P16["Phase 16 — Multi-Agent & Swarms"]
P14 --> P17["Phase 17 — Infrastructure & Production"]
P15 --> P18["Phase 18 — Ethics & Alignment"]
P16 --> P19["Phase 19 — Capstone Projects"]
P17 --> P19
P18 --> P19
░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒
The shape of a lesson
Each lesson lives in its own folder, with the same structure across the entire curriculum:
phases/<NN>-<phase-name>/<NN>-<lesson-name>/
├── code/ runnable implementations (Python, TypeScript, Rust, Julia)
├── docs/
│ └── en.md lesson narrative
└── outputs/ prompts, skills, agents, or MCP servers this lesson produces
Every lesson follows six beats. The Build It / Use It split is the spine — you implement the algorithm from scratch first, then run the same thing through the production library. You understand what the framework is doing because you wrote the smaller version yourself.
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#fafaf5','primaryTextColor':'#1a1a1a','primaryBorderColor':'#3553ff','lineColor':'#3553ff','fontFamily':'JetBrains Mono','fontSize':'13px'}}}%%
flowchart LR
M["MOTTO<br/><sub>one-line core idea</sub>"] --> Pr["PROBLEM<br/><sub>concrete pain</sub>"]
Pr --> C["CONCEPT<br/><sub>diagrams & intuition</sub>"]
C --> B["BUILD IT<br/><sub>raw math, no frameworks</sub>"]
B --> U["USE IT<br/><sub>same thing in PyTorch / sklearn</sub>"]
U --> S["SHIP IT<br/><sub>prompt · skill · agent · MCP</sub>"]
Getting started
Three ways in. Pick one.
Option A — read. Open any completed lesson on aiengineeringfromscratch.com or expand a phase under Contents. No setup, no cloning.
Option B — clone and run.
git clone https://github.com/rohitg00/ai-engineering-from-scratch.git
cd ai-engineering-from-scratch
python phases/01-math-foundations/01-linear-algebra-intuition/code/vectors.pyOption C — find your level (recommended). Skip ahead intelligently. Inside Claude, Cursor, Codex, OpenClaw, Hermes, or any agent with the curriculum skills installed:
/find-your-levelTen questions. Maps your knowledge to a starting phase, builds a personalized path with hour estimates. After each phase:
/check-understanding 3 # quiz yourself on phase 3
ls phases/03-deep-learning-core/05-loss-functions/outputs/
# ├── prompt-loss-function-selector.md
# └── prompt-loss-debugger.mdPrerequisites
- You can write code (any language; Python helps).
- You want to understand how AI actually works, not just call APIs.
Built-in agent skills (Claude, Cursor, Codex, OpenClaw, Hermes)
| Skill | What it does |
|---|---|
/find-your-level |
Ten-question placement quiz. Maps your knowledge to a starting phase and produces a personalized path with hour estimates. |
/check-understanding <phase> |
Per-phase quiz, eight questions, with feedback and specific lessons to review. |
░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒
Read it as a book
The whole course compiles into a six-volume book series. EPUB and PDF are built by CI from the same lesson sources and attached to every GitHub release; the links below always resolve to the newest release. Volume numbers index the series, not versions: each copy carries a dated edition stamp, and older editions stay downloadable from their release.
| Vol | Title | Phases | Download |
|---|---|---|---|
| 1 | Foundations · Math, Tooling, and Classical Machine Learning | 00-02 | EPUB · PDF |
| 2 | Deep Learning · Networks, Vision, and Speech | 03, 04, 06 | EPUB · PDF |
| 3 | Language · NLP Foundations and the Transformer | 05, 07 | EPUB · PDF |
| 4 | Large Language Models · Generation, Reinforcement, Pretraining, and Engineering | 08-11 | EPUB · PDF |
| 5 | Agents · Multimodality, Protocols, Autonomy, and Swarms | 12-16 | EPUB · PDF |
| 6 | Production · Infrastructure, Safety, and Capstones | 17-19 | EPUB · PDF |
The book is the snapshot; this repository is the living edition. Every chapter ends with links back to the lesson's animated figures, quiz, and runnable code. Build locally with python3 scripts/build_book.py (pandoc required); pipeline details in book/README.md.
░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒
Every lesson ships something
Other curricula end with "congratulations, you learned X." Each lesson here ends with a reusable tool you can install or paste into your daily workflow.
Install the lot with
python3 scripts/install_skills.py. Real tools, not homework. By the end of the curriculum, you have a portfolio of 503 artifacts you actually understand because you built them.
FIG_002 · A worked sample
Phase 14, lesson 1: the agent loop. ~120 lines of pure Python, no dependencies.
|
def run(query, tools):
history = [user(query)]
for step in range(MAX_STEPS):
msg = llm(history)
if msg.tool_calls:
for call in msg.tool_calls:
result = tools[call.name](**call.args)
history.append(tool_result(call.id, result))
continue
return msg.content
raise StepLimitExceeded |
---
name: agent-loop
description: ReAct-style loop for any tool list
phase: 14
lesson: 01
---
Implement a minimal agent loop that...
You are an agent debugger. Given the trace
of an agent run, identify the step where
the agent went wrong and explain why... |
░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒░░░▒▒▒
Contents
Twenty phases. Click any phase to expand its lesson list.
Phase 0: Setup & Tooling 12 lessons
Get your environment ready for everything that follows.
| # | Lesson | Type | Lang |
|---|---|---|---|
| 01 | Dev Environment | Build | Python |
| 02 | Git & Collaboration | Learn | — |
| 03 | GPU Setup & Cloud | Build | Python |
| 04 | APIs & Keys | Build | Python |
| 05 | Jupyter Notebooks | Build | Python |
| 06 | Python Environments | Build | Shell |
| 07 | Docker for AI | Build | Docker |
| 08 | Editor Setup | Build | — |
| 09 | Data Management | Build | Python |
| 10 | Terminal & Shell | Learn | — |
| 11 | Linux for AI | Learn | — |
| 12 | Debugging & Profiling | Build | Python |
Phase 1 — Math Foundations 22 lessons The intuition behind every AI algorithm, through code.
Phase 2 — ML Fundamentals 18 lessons Classical ML — still the backbone of most production AI.
| # | Lesson | Type | Lang |
|---|---|---|---|
| 01 | What Is Machine Learning | Learn | Python |
| 02 | Linear Regression from Scratch | Build | Python |
| 03 | Logistic Regression & Classification | Build | Python |
| 04 | Decision Trees & Random Forests | Build | Python |
| 05 | Support Vector Machines | Build | Python |
| 06 | KNN & Distance Metrics | Build | Python |
| 07 | Unsupervised Learning: K-Means, DBSCAN | Build | Python |
| 08 | Feature Engineering & Selection | Build | Python |
| 09 | Model Evaluation: Metrics, Cross-Validation | Build | Python |
| 10 | Bias, Variance & the Learning Curve | Learn | Python |
| 11 | Ensemble Methods: Boosting, Bagging, Stacking | Build | Python |
| 12 | Hyperparameter Tuning | Build | Python |
| 13 | ML Pipelines & Experiment Tracking | Build | Python |
| 14 | Naive Bayes | Build | Python |
| 15 | Time Series Fundamentals | Build | Python |
| 16 | Anomaly Detection | Build | Python |
| 17 | Handling Imbalanced Data | Build | Python |
| 18 | Feature Selection | Build | Python |
Phase 3 — Deep Learning Core 13 lessons Neural networks from first principles. No frameworks until you build one.
| # | Lesson | Type | Lang |
|---|---|---|---|
| 01 | The Perceptron: Where It All Started | Build | Python |
| 02 | Multi-Layer Networks & Forward Pass | Build | Python |
| 03 | Backpropagation from Scratch | Build | Python |
| 04 | Activation Functions: ReLU, Sigmoid, GELU & Why | Build | Python |
| 05 | Loss Functions: MSE, Cross-Entropy, Contrastive | Build | Python |
| 06 | Optimizers: SGD, Momentum, Adam, AdamW | Build | Python |
| 07 | Regularization: Dropout, Weight Decay, BatchNorm | Build | Python |
| 08 | Weight Initialization & Training Stability | Build | Python |
| 09 | Learning Rate Schedules & Warmup | Build | Python |
| 10 | Build Your Own Mini Framework | Build | Python |
| 11 | Introduction to PyTorch | Build | Python |
| 12 | Introduction to JAX | Build | Python |
| 13 | Debugging Neural Networks | Build | Python |
Phase 4 — Computer Vision 28 lessons From pixels to understanding — image, video, 3D, VLMs, and world models.
Phase 5 — NLP: Foundations to Advanced 29 lessons Language is the interface to intelligence.
Phase 6 — Speech & Audio 17 lessons Hear, understand, speak.
| # | Lesson | Type | Lang |
|---|---|---|---|
| 01 | Audio Fundamentals: Waveforms, Sampling, FFT | Learn | Python |
| 02 | Spectrograms, Mel Scale & Audio Features | Build | Python |
| 03 | Audio Classification | Build | Python |
| 04 | Speech Recognition (ASR) | Build | Python |
| 05 | Whisper: Architecture & Fine-Tuning | Build | Python |
| 06 | Speaker Recognition & Verification | Build | Python |
| 07 | Text-to-Speech (TTS) | Build | Python |
| 08 | Voice Cloning & Voice Conversion | Build | Python |
| 09 | Music Generation | Build | Python |
| 10 | Audio-Language Models | Build | Python |
| 11 | Real-Time Audio Processing | Build | Python |
| 12 | Build a Voice Assistant Pipeline | Build | Python |
| 13 | Neural Audio Codecs — EnCodec, SNAC, Mimi, DAC | Learn | Python |
| 14 | Voice Activity Detection & Turn-Taking | Build | Python |
| 15 | Streaming Speech-to-Speech — Moshi, Hibiki | Learn | Python |
| 16 | Voice Anti-Spoofing & Audio Watermarking | Build | Python |
| 17 | Audio Evaluation — WER, MOS, MMAU, Leaderboards | Learn | Python |
Phase 7 — Transformers Deep Dive 14 lessons The architecture that changed everything.
| # | Lesson | Type | Lang |
|---|---|---|---|
| 01 | Why Transformers: The Problems with RNNs | Learn | Python |
| 02 | Self-Attention from Scratch | Build | Python |
| 03 | Multi-Head Attention | Build | Python |
| 04 | Positional Encoding: Sinusoidal, RoPE, ALiBi | Build | Python |
| 05 | The Full Transformer: Encoder + Decoder | Build | Python |
| 06 | BERT — Masked Language Modeling | Build | Python |
| 07 | GPT — Causal Language Modeling | Build | Python |
| 08 | T5, BART — Encoder-Decoder Models | Learn | Python |
| 09 | Vision Transformers (ViT) | Build | Python |
| 10 | Audio Transformers — Whisper Architecture | Learn | Python |
| 11 | Mixture of Experts (MoE) | Build | Python |
| 12 | KV Cache, Flash Attention & Inference Optimization | Build | Python |
| 13 | Scaling Laws | Learn | Python |
| 14 | Build a Transformer from Scratch | Build | Python |
| 15 | Attention Variants — Sliding Window, Sparse, Differential | Build | Python |
| 16 | Speculative Decoding — Draft, Verify, Repeat | Build | Python |
Phase 8 — Generative AI 14 lessons Create images, video, audio, 3D, and more.
| # | Lesson | Type | Lang |
|---|---|---|---|
| 01 | Generative Models: Taxonomy & History | Learn | Python |
| 02 | Autoencoders & VAE | Build | Python |
| 03 | GANs: Generator vs Discriminator | Build | Python |
| 04 | Conditional GANs & Pix2Pix | Build | Python |
| 05 | StyleGAN | Build | Python |
| 06 | Diffusion Models — DDPM from Scratch | Build | Python |
| 07 | Latent Diffusion & Stable Diffusion | Build | Python |
| 08 | ControlNet, LoRA & Conditioning | Build | Python |
| 09 | Inpainting, Outpainting & Editing | Build | Python |
| 10 | Video Generation | Build | Python |
| 11 | Audio Generation | Build | Python |
| 12 | 3D Generation | Build | Python |
| 13 | Flow Matching & Rectified Flows | Build | Python |
| 14 | Evaluation: FID, CLIP Score | Build | Python |
| 19 | Visual Autoregressive Modeling (VAR): Next-Scale Prediction | Build | Python |
Phase 9 — Reinforcement Learning 12 lessons The foundation of RLHF and game-playing AI.
| # | Lesson | Type | Lang |
|---|---|---|---|
| 01 | MDPs, States, Actions & Rewards | Learn | Python |
| 02 | Dynamic Programming | Build | Python |
| 03 | Monte Carlo Methods | Build | Python |
| 04 | Q-Learning, SARSA | Build | Python |
| 05 | Deep Q-Networks (DQN) | Build | Python |
| 06 | Policy Gradients — REINFORCE | Build | Python |
| 07 | Actor-Critic — A2C, A3C | Build | Python |
| 08 | PPO | Build | Python |
| 09 | Reward Modeling & RLHF | Build | Python |
| 10 | Multi-Agent RL | Build | Python |
| 11 | Sim-to-Real Transfer | Build | Python |
| 12 | RL for Games | Build | Python |
Phase 10 — LLMs from Scratch 22 lessons Build, train, and understand large language models.
| # | Lesson | Type | Lang | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 01 | Tokenizers: BPE, WordPiece, SentencePiece | Build | Python, Rust | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 02 | Building a Tokenizer from Scratch | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 03 | Data Pipelines for Pre-Training | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 04 | Pre-Training a Mini GPT (124M) | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 05 | Distributed Training, FSDP, DeepSpeed | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 06 | Instruction Tuning — SFT | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 07 | RLHF — Reward Model + PPO | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 08 | DPO — Direct Preference Optimization | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 09 | Constitutional AI & Self-Improvement | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | Evaluation — Benchmarks, Evals | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | Quantization: INT8, GPTQ, AWQ, GGUF | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | Inference Optimization | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | Building a Complete LLM Pipeline | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | Open Models: Architecture Walkthroughs | Learn | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | Speculative Decoding and EAGLE-3 | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | Differential Attention (V2) | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | Native Sparse Attention (DeepSeek NSA) | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | Multi-Token Prediction (MTP) | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | DualPipe Parallelism | Learn | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | DeepSeek-V3 Architecture Walkthrough | Learn | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | Jamba — Hybrid SSM-Transformer | Learn | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | Async and Hogwild! Inference | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | Speculative Decoding and EAGLE | Build | Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Recent activitycommits and pull requests
Recent open issuesview all
Discussionsall 1
Releases and announcements1 total
Code frequencyadditions and deletionsCommits per weeklast 52 weeksWhen work happensweekday and hourWho is committinglast 52 weeksMaintainer commits1,551 (94%) Community commits106 (6%) 1,657 commits in total over the last year. Trending appearances
Related repositories
|