Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

microTorch

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.

What this project does

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.

Project structure

  • 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

How it works

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.

Example idea

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."

Why I made this

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.

Getting started

From the project directory, you can explore the engine directly:

cd engine
python

Then import the simple network components and start experimenting.

Notes

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.

About

Auto Diff engine inspired by PyTorch.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages