Tensor by Tensor

02.03 · UNIT 01 · Regression and tensor mechanics · Lesson

Derivatives, autograd, and gradient checking

Autograd records tensor calculations. It can then calculate their local gradients backward.

PLAIN-LANGUAGE INTRODUCTION

What is this?

Autograd records tensor calculations. It can then calculate their local gradients backward.

One simple example

For L=w² at w=3, autograd gives gradient 6. A 0.1 descent step gives w=2.4.

What goes in?

A loss made from tensors that track gradients.

What comes out?

A gradient stored for each tracked parameter.

Why does it matter?

Large models have too many connected derivatives to calculate by hand.

What is it not?

A gradient is not an update. The optimizer chooses how to use it.

WORK THROUGH THE IDEA

See the idea in more detail

  1. Set w=3 and calculate L=w²=9. Autograd records the square operation.
  2. Calling backward() applies the derivative dL/dw=2w. It stores 6 in w.grad.
  3. With learning rate 0.1, descent computes 3−0.1×6 = 2.4.
  4. The new loss is 2.4² = 5.76. This one step lowered the loss from 9.
  5. Common mistake: gradients accumulate. Clear old gradients before an ordinary new batch.
Open the detailed notes ↗