Skip to content

bryantjandra/micograd

Repository files navigation

Micrograd

A scalar-valued autograd engine and neural network library built from scratch, following Andrej Karpathy's micrograd lecture.

I built this in order to deeply understand how AI and neural networks actually work under the hood. Before being able to truly reason about models, training, and why things go wrong, I believe we need to understand the true fundamentals (what a gradient is, how backpropagation flows through a computation graph, how a network actually learns, etc.).


Files

File Description
engine.py The Value class — wraps a scalar, builds the computation graph, runs backprop
nn.py Neuron, Layer, MLP — neural network abstractions built on Value
train.py Full training loop on a toy dataset — forward pass, loss, backpropagation, gradient descent
demo_backprop.py Step-by-step manual backpropagation with numerical verification
demo_pytorch.py Side-by-side comparison of micrograd vs PyTorch gradients

Quickstart

# train the network
python train.py

# see manual backprop walkthrough
python demo_backprop.py

# compare with PyTorch (requires torch)
python demo_pytorch.py

Dependencies

  • Python 3.x (stdlib only for engine.py and nn.py)

About

karpathy's micrograd, a scalar-valued autograd engine and neural network library built from scratch.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors