What is micrograd and why did Andrej Karpathy build it?

Andrej Karpathy said micrograd is a tiny autograd engine that implements backpropagation. He built it to show how neural network training works under the hood in a form people can understand intuitively. The point is not production efficiency; it is to make the math and chain rule concrete before scaling up to tensor libraries like PyTorch or JAX.

“Micrograd is basically an autograd engine. Autograd is short for automatic gradient, and really what it does is it implements backpropagation. Now, backpropagation is this algorithm that allows you to efficiently evaluate the gradient of some kind of a loss function with respect to the weights of a neural network, and what that allows us to do then is we can iteratively tune the weights of that neural network to minimize the loss function and therefore improve the accuracy of the network. So backpropagation would be at the mathematical core of any modern deep neural network library, like say PyTorch or JAX. So the functionality of micrograd is, I think, best illustrated by an example, so…”
— Andrej Karpathy, Educational talk, 2021-11 · at 0:44
Andrej Karpathy: Andrej Karpathy on Neural Networks: Building Micrograd

Key takeaways

  • Start with the simplest possible version of backpropagation.
  • Understand the core idea before worrying about performance.
  • Use tiny tools to make complex systems legible.

Context

In a 2021 educational talk, Karpathy introduced micrograd as he walked through neural network training from first principles. The quote above is taken word for word from the recording's transcript.

In the transcript

…take you through building of micrograd. Now, micrograd is this library that I released on GitHub about two years ago, but at the time I only uploaded the source code, and you'd have to go in by yourself and really figure out how it works. So in this lecture, I will take you through it step by step and kind of comment on all the pieces of it, so what

Micrograd is basically an autograd engine. Autograd is short for automatic gradient, and really what it does is it implements backpropagation. Now, backpropagation is this algorithm that allows you to efficiently evaluate the gradient of some kind of a loss function with respect to the weights of a neural network, and what that allows us to do then is we can iteratively tune the weights of that neural network to minimize the loss function and therefore improve the accuracy of the network. So backpropagation would be at the mathematical core of any modern deep neural network library, like say PyTorch or JAX. So the functionality of micrograd is, I think, best illustrated by an example, so…

if we just scroll down here, you'll see that micrograd basically allows you to build out mathematical expressions, and um, here what we are doing is we have an expression that we're building out where you have two inputs, a and b, and you'll see that a and b are negative four and two, but we are wrapping those values into this value object that we are going to build…

Read the full transcript of Educational talk, 2021-11

Topics

What others said about neural networks

More questions about Andrej Karpathy

All Andrej Karpathy answers · All Andrej Karpathy recordings

How this answer was made: the quote is checked word for word against the transcript of the recording and confirmed as the speaker's own words; the summary above it was drafted with AI from that transcript and quality-checked. Methodology and corrections.

Search every transcript
Open the full search page →