Back to Deep Learning Mind Map
中文·English
🧠 Deep LearningID: gradient-check

Gradient Checking

梯度检查
🎯Core Definition
Approximate the derivative numerically and compare it with the analytical gradient: central difference f(x)f(x+ϵ)f(xϵ)2ϵf'(x) \approx \frac{f(x+\epsilon) - f(x-\epsilon)}{2\epsilon}, error O(ϵ2)O(\epsilon^2) (one-sided differencing is only O(ϵ)O(\epsilon)), with ϵ\epsilon typically 10410^{-4}10510^{-5} (smaller and floating-point noise dominates). Measure with relative error gnumganamax(gnum,gana)\frac{|g_{num} - g_{ana}|}{\max(|g_{num}|, |g_{ana}|)}: use the 10710^{-7} order for shallow nets (≤3 layers) and the 10310^{-3} order for deep/large networks, where tiny numerical errors accumulate.
💡Use Cases
verifying the backward pass when hand-writing backprop, implementing custom autograd Functions, or reproducing a paper's new layer/loss; interviews ask for the formula, the error order, and the thresholds.
Key Problems Solved
backward-pass bugs are subtle — training still “learns” (later layers absorb the error), so the bug is nearly invisible; gradient checking turns implementation correctness into an automated numeric test. Caveats: disable dropout/BN randomness, use only a few samples, check one parameter at a time (two forward passes per parameter), so it is run when implementing new ops, not repeatedly during training.
🎯5 High-Frequency Exam Points
1
Write the central-difference gradient formula. Why is the error O(ϵ2)O(\epsilon^2)?
2
How is relative error computed? Why do shallow and deep networks need different thresholds?
3
Why disable dropout/BN randomness and use tiny samples during gradient checking?
4
When is gradient checking appropriate? Why can't it run constantly?
5
What goes wrong if ϵ\epsilon is too large or too small?
📖 In-depth Guide:📄 debugging-and-dl-comp
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "Gradient Checking"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice
Previous CardAutograd Compute GraphNext CardData Augmentation

🔗 More Deep Learning Knowledge Cards

Activation FunctionsAdam & AdamWBatch NormalizationClassic CNN Architectures