An exploding gradient occurs when the gradient magnitude becomes excessively large, producing parameter updates that overshoot the intended optimization path. With ||g_t||₂ approaching infinity, even a small learning rate can cause performance degradation or prevent learning; very deep networks are one reported cause. section 5.1.2
Clipping an extreme gradient
With threshold z = 5, g = [1, −2, 1000, 3, −7] becomes [1, −2, 5, 3, −5]. Clipping preserves the indicated direction while limiting the unreasonable step size. section 5.3.3
Gradient clipping addresses the problem by clamping every gradient value to [−5, 5]. In PyTorch, register_hook can apply torch.clamp to each parameter gradient before the optimizer uses it. The technique works with Adam, SGD, and learning-rate schedules, but may worsen results when exploding gradients are absent. section 5.3.3
Figure 5.2 A toy example showing three scenarios for gradient descent. Each is a contour plot of a 2D optimization going from red (high values, bad) to dark green (low values, good). The ideal case is at the top left, where each gradient heads exactly toward the solution. The top right shows noisy gradients that cause the descent to head in not quite the correct direction, requiring more steps. The bottom left shows exploding gradients, where we begin to take steps that are far too large and head away from the solution. The bottom right shows vanishing gradients, where the gradient becomes so small that we have to take an excessive number of steps to get to the solution.
Compare ideal, noisy, exploding, and vanishing gradient-descent paths in a two-dimensional contour plot. section 5.1.2




