An educational light deep learning framework built step by step from scratch. Inspired by Karpathy’s micrograd, but expanded into a full journey.
This repository is structured as a staged learning + engineering journey. Each stage builds on the previous one, gradually transforming a toy autograd engine into a portfolio-grade deep learning framework.
-
Similar reproduction of Karpathy’s Micrograd with some small differences.
-
Implements a scalar-based autograd engine with:
Valueclass (forward/backward)- Core ops:
+,-,*,/,^,tanh - Computation graph visualization (Graphviz)
- Minimal
Neuron,Layer,MLP
Goal: Polish into a professional-grade mini-framework.
-
Core API:
Module,Parameter,SequentialLinear,Dropout, activations (ReLU, Tanh, LeakyReLU)
-
Training utilities:
- SGD, Adam optimizers
- LR schedulers (step, cosine)
- Gradient clipping, early stopping
-
Reliability:
- Save/load checkpoints
- Deterministic seeds
-
Metrics: accuracy, precision/recall, confusion matrix
-
Docs site (mkdocs)
-
Examples: XOR, Spiral, MNIST (≥95% acc), CIFAR-10 tiny baseline
-
Packaged on PyPI (
pip install vhgrad) -
CI tests (GitHub Actions)
pip install vhgrad # after vhgrad stage is releasedfrom vhgrad import MLP, SGD, mse
# simple 2-3-1 MLP
model = MLP(2, [3, 1])
opt = SGD(model.parameters(), lr=0.1)
for epoch in range(1000):
ypred = [model(x) for x in xs]
loss = mse(ys, ypred)
opt.zero_grad()
loss.backward()
opt.step()- XOR: ≥95% acc within 5k steps
- Spiral: ≥90% acc
- MNIST (1k subset): ≥90% acc ≤10 epochs
- MNIST (10k subset): ≥95% acc ≤20 epochs
- Speedup: ≥5× vs scalar baseline
- micrograd: scalar engine reproduces tutorial
- vhgrad: polished framework, docs, PyPI, ≥95% MNIST acc, CI tests
— free to use, learn from, and extend.
- Original inspiration: Andrej Karpathy’s micrograd
- Built by Virvi Huta