Confirmed · 1 videos

Understand the backward pass

Learn how gradients actually flow, practice backpropagation by hand, and monitor activation and gradient statistics instead of trusting autograd blindly.

He calls backpropagation a leaky abstraction. Saturated sigmoids, dead ReLUs, exploding RNN gradients and clipping bugs all come from backward-pass behavior that frameworks conceal. Manual practice and statistical diagnostics give practitioners the intuition to debug and to innovate.

Based on Andrej Karpathy's public content. Not affiliated with or endorsed by Andrej Karpathy.

What following it looks like

  • Writes the backward pass for each layer manually, without calling autograd
  • Sums gradient contributions at reused nodes and resets gradients before every backward pass
  • Plots activation and gradient histograms to catch saturation or improper scaling
  • Checks whether ReLU units ever fire across the training set

Evidence · 12 quotes from 1 video

Each quote was matched word for word against the transcript. Tap the time to hear it.

“that's what back propagation is is just a recursive application of chain rule backwards through the computation graph”

50:59always so we just go through and recursively
51:01so we just go through and recursively multiply on the local derivatives and
51:04multiply on the local derivatives and that's what back propagation is is just
51:05that's what back propagation is is just a recursive application of chain rule
51:08a recursive application of chain rule backwards through the computation graph

“if you can write the local gradients you can chain the gradient and you can continue back propagation”

1:39:19that little operation it doesn't matter what that operation is
1:39:21what that operation is and how composite it is
1:39:23and how composite it is if you can write the local gradients you
1:39:24if you can write the local gradients you can chain the gradient and you can
1:39:25can chain the gradient and you can continue back propagation so the design

“as long as you can do forward pass and the backward pass of that little operation it doesn't matter what that operation is”

1:39:10matters is we have some kind of inputs and some kind of an output and this
1:39:11and some kind of an output and this output is a function of the inputs in
1:39:13output is a function of the inputs in some way and as long as you can do
1:39:14some way and as long as you can do forward pass and the backward pass of
1:39:16forward pass and the backward pass of that little operation it doesn't matter

“the design of what those functions are is completely up to”

1:39:23and how composite it is if you can write the local gradients you
1:39:24if you can write the local gradients you can chain the gradient and you can
1:39:25can chain the gradient and you can continue back propagation so the design
1:39:28continue back propagation so the design of what those functions are is
1:39:30of what those functions are is completely up to you

“we just accumulate those gradients and that fixes the issue”

1:26:25detail backward it will deposit its own gradients and then those gradients
1:26:28gradients and then those gradients simply add on top of each other and so
1:26:30simply add on top of each other and so we just accumulate those gradients and
1:26:31we just accumulate those gradients and that fixes the issue okay now before we
1:26:34that fixes the issue okay now before we move on let me actually do a bit of

“the solution there is basically that we have to accumulate these gradients these gradients add”

1:25:19and the solution here if you look at the multivariate case of the chain rule
1:25:22the multivariate case of the chain rule and its generalization there
1:25:23and its generalization there the solution there is basically that we
1:25:26the solution there is basically that we have to accumulate these gradients these
1:25:28have to accumulate these gradients these gradients add

“we need to accumulate those gradients”

1:25:30gradients add and so instead of setting those
1:25:32and so instead of setting those gradients
1:25:34gradients we can simply do plus equals we need to
1:25:37we can simply do plus equals we need to accumulate those gradients
1:25:39accumulate those gradients plus equals plus equals

“we just go through and recursively multiply on the local derivatives”

50:56what the local derivatives are and we just multiply them onto the derivative
50:58just multiply them onto the derivative always
50:59always so we just go through and recursively
51:01so we just go through and recursively multiply on the local derivatives and
51:04multiply on the local derivatives and that's what back propagation is is just

“this is really done so that you understand and refactor out back propagation and chain rule and understanding of neurologic training”

5:52to not have to deal with these n-dimensional tensors that you would use
5:54n-dimensional tensors that you would use in modern deep neural network library so
5:56in modern deep neural network library so this is really done so that you
5:58this is really done so that you understand and refactor out back
6:00understand and refactor out back propagation and chain rule and

“but none of the math changes this is done purely for efficiency”

6:04understanding of neurologic training and then if you actually want to train
6:06and then if you actually want to train bigger networks you have to be using
6:08bigger networks you have to be using these tensors but none of the math
6:09these tensors but none of the math changes this is done purely for
6:11changes this is done purely for efficiency we are basically taking scale

“you can understand how things work uh at the fundamental level and then you can speed it up later”

6:38useful to be dealing with tensors from scratch uh and i think and that's why i
6:40scratch uh and i think and that's why i fundamentally wrote micrograd because
6:42fundamentally wrote micrograd because you can understand how things work uh at
6:44you can understand how things work uh at the fundamental level and then you can
6:46the fundamental level and then you can speed it up later okay so here's the fun

“the only thing that matters is that we know how to differentiate through any one function”

58:24points of abstraction they can be complicated functions but they can be
58:26complicated functions but they can be also very very simple functions like a
58:27also very very simple functions like a plus and it's totally up to us the only
58:30plus and it's totally up to us the only thing that matters is that we know how
58:31thing that matters is that we know how to differentiate through any one

Linked topics