The spelled-out intro to neural networks and backpropagation: building micrograd

16 Aug 2022 · 146 min
2:25:51

In this segment of Andrej Karpathy's tutorial, he walks through the step‑by‑step construction of a minimal autograd engine (micrograd) and uses it to implement a multilayer perceptron (MLP). He starts by defining a Neuron class, showing how to compute a forward pass with a dot product, bias addition, and a non‑linearity. He then builds a Layer as a list of independent neurons and stacks Layers into an MLP that can handle arbitrary architectures. The video demonstrates a forward pass on a tiny binary‑classification dataset, introduces the mean‑squared‑error loss, and explains how backpropagation populates gradients on every parameter. Karpathy shows how to collect all parameters, perform a gradient‑descent update (including the sign convention), and iteratively improve the loss. He highlights a common bug – forgetting to zero gradients between iterations – and fixes it with a zerograd routine. The tutorial proceeds to a more realistic training loop with batching, learning‑rate decay, and L2 regularisation, and compares the micrograd implementation to PyTorch’s API (modules, parameters, backward, zerograd). Finally, he reflects on the broader significance of neural nets, emergent properties in large models, and how micrograd mirrors production‑grade libraries while remaining transparent. The segment ends with a brief look at how to register custom autograd functions in PyTorch.

Chapters

More from Andrej

youtube.com

Skill Issue: Andrej Karpathy on Code Agents, AutoResearch, and the Loopy Era of AI

7mo ago
youtube.com

Andrej Karpathy — “We’re summoning ghosts, not building animals”

1y ago
youtube.com

How I use LLMs

1y ago
youtube.com

CUDA Mode Keynote | Andrej Karpathy | Eureka Labs

2y ago
youtube.com

No Priors Ep. 80 | With Andrej Karpathy from OpenAI and Tesla

2y ago
youtube.com

Let's reproduce GPT-2 (124M)

2y ago
youtube.com

Let's build the GPT Tokenizer

2y ago
youtube.com

[1hr Talk] Intro to Large Language Models

2y ago
youtube.com

Let's build GPT: from scratch, in code, spelled out.

3y ago
youtube.com

Building makemore Part 5: Building a WaveNet

3y ago
youtube.com

Andrej Karpathy: Tesla AI, Self-Driving, Optimus, Aliens, and AGI | Lex Fridman Podcast #333

4y ago
See all content