Run a gradient check¶
Compute the analytical gradients with backpropagation, then pass them with the
model parameters, input data, labels, and cost function to gradient_check. The
function computes numerical gradients and returns their relative difference from
the supplied analytical gradients. See the
training techniques API reference for the exact
interface, then interpret the result using the
gradient check tolerances.
Common issues and debugging tips¶
- Regularization: Don't forget to include regularization terms in both forward and backward pass
- Dropout: Turn off dropout during gradient checking
- Batch Normalization: Use the same batch for both forward passes
- Numerical Precision: Use double precision (float64) for gradient checking
- Random Initialization: Use fixed random seed for reproducibility
Development practice¶
- Essential during development
- Use only on small subsets of data
- Disable all stochastic elements (dropout, batch norm in training mode)
Always implement gradient checking first, then optimize for performance.
For why the comparison works, see How gradient checking works.