LAB NOTEBOOK No. 01 · PROJECT · INDIA — UTC+5:30Code · repositoryOn PyPI · shipped
Code · repository · On PyPI · shipped

micrograd_hk

⑂ Code · repository·A tiny autograd engine on NumPy — a Value graph with vectorised backprop and gradient descent, written before touching a
View code on GitHub ↗ ← Back to archive

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
autograd NumPy backprop Adam-M PyPI MIT
Jupyter Notebook 80.3% · Python 19.7%
Optimisers
5
Python
3.8+
License
MIT
FAQ — micrograd_hk
How is this different from micrograd?tap ↕

micrograd differentiates one scalar at a time. micrograd_hk keeps the same minimal Value graph but vectorises every operation over NumPy matrices, so a network trains in a fraction of the time while the code stays readable.

What is Adam-M?tap ↕

A modified Adam developed and tuned inside this project, selected with optimizer="adam_m". SGD, Momentum, RMSProp and standard Adam ship alongside it.

Can I try it without installing anything?tap ↕

Yes — open demo.ipynb in Colab from the repo badge and run it top to bottom.

View code on GitHub ↗ ← All projects GitHub ↗