Show HN: Microcrad – Micrograd Reimplemented in C
----
- 3 days ago | 15 points | 2 comments
- URL: https://github.com/oraziorillo/microcrad
- Discussions: https://news.ycombinator.com/item?id=48570364
- Summary: microcrad is an educational C re-implementation of Andrej Karpathy's micrograd. It is a tiny scalar-valued automatic differentiation engine with a small neural network library built on top. The core abstraction is `Value`, a node in a computation graph that wraps a double and tracks operands via pointers. Operations such as addition, multiplication, power, exponential, logarithm, and ReLU create new values linked into the graph. Backpropagation uses a topological sort and applies the chain rule in reverse to compute gradients. Because C lacks garbage collection, memory is managed through reference counting: operations retain their operands, and releasing the root cascades to free unreachable nodes. The library provides Neuron, Layer, and MLP structures for building feed-forward ReLU networks, plus utility vectors and sets for internal graph traversal. It is not intended for production use but for learning how backpropagation works at the scalar level. The repository includes tests, a toy regression example, and an MNIST conceptual demo, with builds handled by a simple Makefile requiring only a C compiler and libm.
Simplicity scales better than cleverness" — Graphic Designer in Bakersfield