A minimal automatic differentiation engine for scalar values, built from the ground up to understand how backpropagation and computation graphs actually work.
This project mirrors the core ideas behind PyTorch Autograd, but strips everything down to the bare essentials so the mechanics are completely transparent.
- π§ Custom scalar autograd engine
- π Dynamic computation graph construction
- β Operator overloading (
+,*,**) - π Manual backward functions (chain rule)
- π Gradient accumulation
- π Graphviz visualization of the computation graph
- π Designed purely for learning & clarity
Each scalar value is treated as a node in a directed acyclic graph (DAG).
- Value nodes store:
- numerical data
- gradient
- Operation nodes represent computations (
+,*,**) - Edges encode dependencies between values
During backpropagation:
- gradients flow from output β inputs
- each operation applies the chain rule
- gradients accumulate at leaf nodes
Practice/ βββ ScalarDerivative.ipynb # Main notebook (engine + examples) βββ README.md
a = Value(5, label="A")
b = Value(6, label="B")
c = a * b
d = c + a
d.backward()This builds the computation graph dynamically and computes gradients for a and b.
π Graph Visualization
The computation graph can be rendered using Graphviz, where:
π¦ Rectangular nodes β scalar values (data, grad)
βͺ Circular nodes β operations (+, *)
β‘οΈ Directed edges β data flow
This makes gradient propagation explicit and visual, which is extremely useful for understanding backprop.
π― Why this exists
This project is meant to help you:
truly understand how autograd works internally
demystify backpropagation
see computation graphs instead of just equations
connect math β code β deep learning frameworks
If you understand this notebook, you understand the core of modern deep learning frameworks.
Scalars only (no tensors)
No broadcasting
No vectorization
No performance optimizations
These constraints keep the implementation simple, readable, and educational.
π Inspiration
PyTorch Autograd
micrograd by Andrej Karpathy
Computational graph theory
π Final Note
This project is not about speed or scale.
Itβs about understanding.
If you can build autograd for scalars, you truly understand backpropagation.
β If this helped you, consider starring the repo!