A tiny autograd engine built on NumPy for fast, matrix-driven backpropagation — the from-scratch work of the AGI notebook, packaged so anyone can install it.
It implements a minimal Value computation graph, inspired by karpathy/micrograd, but where micrograd differentiates scalar by scalar, this one vectorises every operation over full NumPy matrices — so training is significantly faster. @, +, -, , sum and tanh all carry a backward pass.
On top of the engine sit a small DenseLayer / MLP API and a Trainer with automatic checkpointing and five optimisers: SGD, Momentum, RMSProp, Adam, and Adam-M** — a modified Adam derived and tuned as part of this project.
pip install micrograd_hk
from micrograd_hk import Value, DenseLayer, MLP, Trainer
m = MLP(shape=[1, 3], nouts=[8, 8, 1])
trainer = Trainer(m, xs_matrix, ys_matrix)
final_loss, y_pred = trainer.train(lr=0.01, iterations=3000, optimizer="adam_m")
There is a runnable Colab demo if you would rather read it than install it. MIT licensed, Python 3.8+.
Highlights
- Matrix-first `Value` autograd engine with a full backward pass
- Vectorised over NumPy matrices, not scalar by scalar
- `DenseLayer` and `MLP` building blocks
- Five optimisers: SGD, Momentum, RMSProp, Adam and a custom Adam-M
- `Trainer` with automatic checkpoint save and load
- Written before touching PyTorch — the maths first, the framework after