This Optimization concept is the current object: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.
Optimization
Gradient Clipping & Explosion Prevention
How to stop one extreme batch from blowing up training: clip the gradient norm, bound the update, and keep moving in roughly the same direction.
Concept Structure
Gradient Clipping & Explosion Prevention
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Commit a prediction against the code witness.
Learner Contract
What this page should let you do.
2 prerequisites listed; refresh them before leaning on the math or code.
Explain the mechanism, trace the main notation, and answer the prediction probe against the code witness.
Read the intuition before the notation; the math should name a mechanism you already felt.
Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.
Claim/source review status
Claim review not recorded
No structured claim checks yet; source metadata is not enough to establish support.Metadata-derived; review may be AI-assisted. Not a human certification.01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
Most batches are boring. A few are not.
On those bad batches, the gradient can spike because activations, logits, or long chains of Jacobians produce an unusually large backpropagated signal. If you apply that gradient naively, one step can throw the model far away from the regime where training had been stable.
Gradient clipping is a simple guardrail:
- let normal gradients pass untouched,
- when a gradient is too large, scale it back before taking the optimizer step.
The point is not to "fix" the optimization problem permanently. The point is to stop rare outliers from destroying the run.
Norm clipping is usually the right mental model: keep the direction of the gradient, but cap its magnitude.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Let be the gradient and let be the clipping threshold.
Global norm clipping defines
Equivalently,
If your optimizer step is , then whenever clipping activates,
So clipping puts a hard cap on the update size.
Why can gradients explode in the first place? In a deep network, gradients are products of Jacobians:
If those Jacobians repeatedly amplify norms, backpropagated signals can grow exponentially with depth or sequence length.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import numpy as np
g = np.array([6.0, 8.0, 0.0]) # norm = 10
c = 5.0
lr = 1e-2
scale = min(1.0, c / np.linalg.norm(g))
g_clip = scale * g
print("raw grad norm :", np.linalg.norm(g))
print("clipped grad norm:", np.linalg.norm(g_clip))
print("raw step norm :", np.linalg.norm(lr * g))
print("clipped step norm:", np.linalg.norm(lr * g_clip))
This keeps the update direction the same but limits the step size to lr * c.
04
Interactive Demo
Use the authored prediction probe to test the mechanism without a live widget.
Prediction check: the raw gradient has norm 10 and the threshold is 5. Predict the scale factor and the clipped step norm before running the code, then change c to 2 and verify that the direction stays fixed while the update length shrinks.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
How to stop one extreme batch from blowing up training: clip the gradient norm, bound the update, and keep moving in roughly the same direction.
Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Gradient Clipping & Explosion Prevention should make visible.
Visual Inquiry
Make the image answer a mathematical question
How to stop one extreme batch from blowing up training: clip the gradient norm, bound the update, and keep moving in roughly the same direction.
Which visible object should carry the first intuition?
Pick the cue that should make Gradient Clipping & Explosion Prevention easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Add source metadata before treating this page as source-grounded.
Claim Review
How to stop one extreme batch from blowing up training: clip the gradient norm, bound the update, and keep moving in roughly the same direction.
Source IDs and witness objects are attached for review; they are not proof by themselves.
Add source metadata before claiming support.
Use equation, code, and demo objects to check whether the source support is operational.
Source support candidates
No structured source note is attached yet.
Practice Loop
Try the idea before it explains itself
How to stop one extreme batch from blowing up training: clip the gradient norm, bound the update, and keep moving in roughly the same direction.
Before touching the demo, predict one visible change that should happen in Gradient Clipping & Explosion Prevention.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to an exact object
Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.Open the draft below to save one note and next action in this browser.
Gradient Clipping & Explosion Prevention
What is the smallest example that makes Gradient Clipping & Explosion Prevention click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays locally in this browser for concept:optimization/gradient-clipping.
- Definition, prerequisite, and contrast concept links
- The equation or code witness that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Gradient Clipping & Explosion Prevention Object key: concept:optimization/gradient-clipping Context: Optimization Anchor id: concept/concept-notebook/optimization/gradient-clipping Open question: What is the smallest example that makes Gradient Clipping & Explosion Prevention click without losing the math? Evidence to inspect: - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/optimization/gradient-clipping
concept:optimization/gradient-clipping