WHY decompose? Because we only know how to differentiate simple operations easily. If we express the whole computation as a chain of simple ops, the chain rule glues the local derivatives together into the full derivative.
Evaluate the graph left-to-right, storing every intermediate value. Why store them? The local derivatives usually depend on the values (e.g. dxdsinx=cosx needs x).
L=21(y^−t)2, y^=σ(z), z=wx+b, with σ(z)=1+e−z1.
Goal:∂L/∂w. Chain through the graph:
∂w∂L=∂L/∂y^(y^−t)⋅∂y^/∂zσ(z)(1−σ(z))⋅∂z/∂wx
Why∂L/∂y^=y^−t? Derivative of 21(y^−t)2.
Whyσ′(z)=σ(1−σ)? Standard sigmoid identity (derive: σ′=(1+e−z)2e−z=σ(1−σ)).
Why∂z/∂w=x? z=wx+b is linear in w.
Autograd computes exactly these three numbers in the backward pass and multiplies them. No calculus by you.
Recall Feynman: explain to a 12-year-old
Imagine a machine made of tiny gears (add, multiply, sin). You turn the input knob and out pops an answer. Now you ask: "If I wiggle this one gear a little, how much does the final answer wiggle?" Autograd answers this by starting at the output and walking backward gear-by-gear, at each gear multiplying by how sensitive it is to its neighbor. If one gear connects to two others, you add up both wiggle-effects. Do this once and you learn how every knob affects the answer — so you know which way to nudge each knob to make the answer better.
A directed acyclic graph whose nodes are variables and whose edges are elementary operations with known local derivatives; it decomposes a complex function into differentiable primitives.
Why store intermediate values during the forward pass?
Local derivatives usually depend on those values (e.g. d/dx sin x = cos x needs x), so backprop reuses them.
What is the adjoint (bar) of a node?
The sensitivity ∂(final output)/∂(that node) — how much the output changes if the node wiggles.
State the reverse-mode update rule.
For each edge u→v: uˉ+=vˉ⋅∂v/∂u, seeded with fˉ=1.
Why do we accumulate (+=) adjoints?
A node feeding multiple children affects the output through several paths; the multivariable chain rule sums those contributions.
Why is reverse mode preferred for neural nets?
Cost scales with number of outputs; loss has one scalar output but millions of inputs, so one backward pass gives all gradients ≈ cost of one forward pass.
Is autograd the same as finite differences?
No. Autograd applies exact local derivative rules (no step size h), so it has no truncation error; finite differences approximate.
Relationship between backprop and autograd?
Backpropagation is reverse-mode automatic differentiation applied to neural networks — same algorithm.
Derivative of the sigmoid σ(z)?
σ(z)(1−σ(z)).
Why zero gradients each training step?
Because .grad accumulates (+=), leftover gradients from previous batches would otherwise add up incorrectly.
Dekho, ek neural network basically ek bahut bada nested function hai — chhote-chhote operations (add, multiply, sin, exp) ek ke baad ek lage hue hote hain. Is puri cheez ko ek picture ki tarah likh lo jise computational graph kehte hain: nodes matlab variables, aur edges matlab operations. Har chhote operation ka derivative hume aata hai, bas unko chain rule se jodna hai.
Autograd ka kaam do steps mein hota hai. Pehle forward pass — left se right chalke saare intermediate values calculate karke store kar lo (store isliye kyunki cos x jaise derivatives ko x ki value chahiye hoti hai). Fir backward pass — output se shuru karo, seed lagao fˉ=1, aur peeche ki taraf har node ko batao "tu final answer ke liye kitna zimmedar hai" (isko adjoint kehte hain). Rule simple hai: uˉ+=vˉ⋅∂v/∂u.
Sabse important baat: agar ek node do jagah use ho raha hai, to uske gradients ko add karo (isliye +=), kyunki wo output ko do raaste se affect karta hai — yahi multivariable chain rule hai. Aur ek badi galti: log samajhte hain autograd numerical (finite difference) hai — nahi bhai, ye exact hai, koi h wala approximation nahi.
Isse kyun farak padta hai? Loss ek scalar (ek output) hota hai lekin weights millions mein. Reverse mode ek hi backward pass mein saare weights ke gradients de deta hai — cost lagbhag ek forward pass jitni. Yahi wajah hai ki deep learning practically train ho pata hai. Backprop koi alag jaadu nahi — ye bas neural net pe lagaya gaya reverse-mode autograd hai.