AI News
All projects
Library

Micrograd: a tiny autograd engine and neural net library with a PyTorch-like API

A small Python library that computes gradients through backpropagation over scalar values, then builds neural networks on that engine.

micrograd by karpathy · 19,127 GitHub stars when we found it · added

The README describes micrograd as a tiny autograd engine that implements backpropagation (reverse-mode autodiff) over a dynamically built graph of scalar values. A small neural network library sits on top of it and offers a PyTorch-like API. The author says the engine is about 100 lines and the library about 50. The scalar-only design breaks each neuron into its individual adds and multiplies. It can be installed with pip install micrograd.

Usage is shown in Python: you build a Value object, chain operations, and call backward() to fill in gradients for the inputs. According to the README, the demo.ipynb notebook trains a 2-layer MLP binary classifier with a max-margin SVM loss and SGD on the moon dataset. A second notebook, trace_graph.ipynb, draws the computation graph with graphviz. The README also points to microgpt, a separate single-file GPT trainer that builds on a more efficient version of the engine.

The unit tests use PyTorch as a reference for checking gradients, so running them requires installing PyTorch. The README calls the project potentially useful for educational purposes and says it is released under the MIT license. It is not presented as a production framework. The README makes no speed claims beyond its small size.

In the author's words

Implements backpropagation (reverse-mode autodiff) over a dynamically built DAG and a small neural networks library on top of it with a PyTorch-like API.

From the README or the author's post. We checked that the sentence is there, not that it is true.

When to reach for it

Useful for learning how backpropagation and neural networks work from the ground up. The README says the whole engine fits in about 100 lines and calls the project potentially useful for educational purposes.

See it

AI wrote this entry from the project's own README or its author's post. What the project does, and that AI built it where the entry says so, are the author's statements, quoted here. Nobody at IKANGAI ran or tested it. How this list is made