I built microTorch as a small, from-scratch autodiff engine inspired by the way PyTorch handles gradients under the hood. This project is a fun little experiment in understanding how backpropagation actually works, and honestly, it feels pretty amazing to see a tiny neural network train itself using a custom gradient engine written by hand.
The goal here was simple: learn the mechanics of automatic differentiation, reverse-mode backpropagation, and basic neural network building blocks without relying on a heavy framework.
microTorch gives you a minimal implementation of:
- a scalar tensor-like object that stores both data and gradients
- basic operations like addition, multiplication, exponentiation, and ReLU
- automatic gradient tracking through a computational graph
- a simple backward pass with chain rule propagation
- a small neural network stack with neurons, layers, and multi-layer perceptrons
It is intentionally small and educational, but it captures the core ideas behind modern deep learning frameworks.
- engine/pseudoTensor.py: the core autodiff engine
- defines a lightweight tensor object
- tracks operations and gradients
- implements backward propagation
- engine/neural_net.py: simple neural network components
- Neuron
- Layer
- MLP
At the center of the project is a tiny class that behaves like a scalar value with a gradient. Every operation you perform builds a small computation graph, and when you call backward(), the engine walks that graph in reverse to compute gradients.
That means you can compose operations naturally and let the system figure out how each input contributed to the final output.
You can build a tiny network and let it learn through gradient descent in the same spirit as larger frameworks, just in a much more stripped-down form. It is a great way to really understand what is happening when you say "just backpropagate it."
This project is one of those satisfying ones where the core idea is simple, but the moment you see gradients flowing correctly, it clicks. Building something like this from scratch makes the whole field feel a lot less magical.
From the project directory, you can explore the engine directly:
cd engine
pythonThen import the simple network components and start experimenting.
This is not meant to be a production-ready deep learning framework. It is a compact, hands-on implementation meant to teach and inspire curiosity.
If you are interested in the internals of machine learning frameworks, this project is a great place to start.