Skip to content
AI.info

Neural networks

Gradients: Local Sensitivity in Parameter Space

Develop geometric intuition for partial derivatives, gradient vectors, directional change, and the limits of local first-order information.

By the end you can

Visual

A loss surface around one parameter setting

The parameter vector is a location on a high-dimensional surface whose height is the loss.

Everything this lesson measures — the slope along one coordinate, the gradient vector assembled from all of them, the descent direction — is read at that single point. The rest of the surface is never consulted.

FigureLayers · 4 layers
  1. 01

    Current parameters

    One point in a space with one coordinate per trainable scalar.

  2. 02

    Local slopes

    Partial derivatives describe nearby change along individual coordinates.

  3. 03

    Gradient vector

    All partial derivatives form one direction of steepest local increase.

  4. 04

    Descent direction

    The negative gradient points toward the steepest local decrease under Euclidean geometry.

One derivative holds the others fixed

A partial derivative asks a narrow question. If this one parameter moves a little and the others hold still, how does the loss change? The answer is a local approximation around the current values.

Parameters interact, so separate partial derivatives do not tell the whole story over a large step. Curvature decides how fast the local approximation goes wrong, and curvature is not spread evenly over the surface. Exploding gradients are walls of high curvature. Pascanu and colleagues made that case in 2013, on the reasoning that “when the first derivative explodes, so does the second derivative”. Their fix became the standard one: whenever ‖ĝ‖ ≥ threshold, rescale the gradient to threshold·ĝ/‖ĝ‖. Seven years later four researchers at MIT stopped arguing the point and measured it. They plotted the local gradient-Lipschitz constant against the gradient norm along the training trajectories of AWD-LSTM on Penn Treebank and ResNet20 on CIFAR-10. Their abstract reports what came out: “Further, this smoothness positively correlates with the gradient norm, and contrary to standard assumptions in the literature, it can grow with the norm of the gradient.” The first-order forecast is worst exactly where the arrow is longest. That is why clipping exists at all.

What that curvature usually looks like has also been measured. The obstacle in high-dimensional non-convex optimization is “the proliferation of saddle points, not local minima”. Dauphin and colleagues argued that in 2014, from random matrix theory and from their own experiments. They then searched directly for critical points of a trained network with a Newton method. The search confirmed the theoretical prediction about a critical point’s index. The index is the fraction of negative eigenvalues of the Hessian there, and it “tightly and positively correlates with its error level”. A place where every partial derivative reads zero is, at high error and high dimension, almost never a floor.

A second group reached the same floor from the opposite direction, with no Newton search anywhere in it. The loss of a multilayer ReLU network can be mapped onto the Hamiltonian of a spherical spin glass, which is what Choromanska and colleagues did in 2015. The physics comes with an inheritance: “Results from random matrix theory applied to spherical spin glasses have shown that these functions have a combinatorially large number of saddle points.” They concluded that the low critical values form a band above the global minimum, and that the number of local minima outside that band diminishes exponentially with network size. The minima found inside it are “highly degenerate, with many eigenvalues of the Hessian near zero”. Two different kinds of argument, one answer. A vanishing partial derivative says even less than it appears to.

A derivative is a nearby sensitivity, not a long-range forecast.

Gradient and direction are connected by a dot product

For a small proposed change d, the dot product between gradient and d approximates the loss change, so aligned motion raises loss while opposite motion lowers it locally.

A direction perpendicular to the gradient has zero first-order change. Second-order curvature may still matter.

A zero derivative can also mean the function has gone flat. It need not mean that nothing depends on the coordinate. The smallest demonstration fits on one line, and Sundararajan and colleagues open their 2017 paper on integrated gradients with it: “a one variable, one ReLU network, f(x) = 1 − ReLU(1−x)”. Take the baseline at x = 0 and the input at x = 2: “the function changes from 0 to 1, but because f becomes flat at x = 1, the gradient method gives attribution of 0 to x”. The output has moved the whole distance. The derivative at the input is exactly zero. Their example is about an input coordinate, but the mechanism is the one that also silences a parameter derivative wherever the composed function has saturated. The dot product is telling the truth about an infinitesimal step, and nothing about a finite one.

Comparison

What gradient magnitude can and cannot tell you

Large and small gradients need context before diagnosis.

The small-magnitude case has been photographed. A four-hidden-layer sigmoid network, measured layer by layer by Glorot and Bengio in 2010, did this at the top of the stack: “The top hidden layer quickly saturates at 0 (slowing down all learning), but then slowly desaturates around epoch 100.” For roughly a hundred epochs that layer’s derivatives were near zero. The network was not finished. It was stuck. Their depth-five model “never escaped this regime during training”. Ioffe and Szegedy, at Google, named the mechanism in one line: for a unit driven into saturation, “the gradient flowing down to u will vanish and the model will train slowly”. Convergence and saturation produce the same reading on the same instrument. Only the loss curve and the activation statistics separate them.

The large-magnitude column is the other half of the same lesson. A long gradient is not a licence to take a long step. That is precisely where the MIT group found the local smoothness constant growing with the norm. The clipping threshold is an admission that the first-order picture has already broken down.

FigureComparison · 2 columns

Large magnitude

The local loss is sensitive to a parameter or group under the current scale.

  • May signal useful learning direction
  • Can also indicate instability
  • Depends on parameter units
  • May require clipping or rescaling

Small magnitude

The local loss changes little along the measured coordinates.

  • May indicate convergence
  • Can result from saturation
  • Can reflect cancellation
  • May hide poor conditioning

Steps

A numerical gradient check

Finite differences provide a debugging reference. Use them on small models and selected parameters.

The last step below says to try several values of epsilon, and there is a reason no single value is correct. Two errors run in opposite directions. Truncation error falls as the step h shrinks, and the other one rises. Baydin and colleagues set out the squeeze in a 2018 survey in the Journal of Machine Learning Research, in a section called “What AD Is Not”: “However, as h is decreased, round-off error increases and becomes dominant (Figure 3).” Switching from a one-sided to a central difference does not escape the squeeze. It only “moves the truncation error from first-order to second-order in h”. The same survey prices the method. A Jacobian of f : R^n → R^m by central differences “requires 2mn evaluations”, against reverse-mode automatic differentiation’s m·c·ops(f) with “c < 6 and typically c ~ [2, 3]”. This is a debugging tool, not a training method.

PyTorch 2.14 ships the trade-off as defaults. torch.autograd.gradcheck uses eps=1e-06, atol=1e-05, rtol=0.001, and the documentation says why: “The default values are designed for input of double precision. This check will likely fail if input is of less precision, e.g., FloatTensor.” Run the check in float64, on a handful of coordinates, and read the relative error rather than the absolute difference.

FigureProcess · 5 steps
  1. 1. Freeze randomness

    Disable dropout and control sampled behavior.

  2. 2. Perturb positively

    Evaluate loss at θ+ε along one coordinate.

  3. 3. Perturb negatively

    Evaluate loss at θ−ε using the same data.

  4. 4. Form central difference

    Approximate the derivative by the symmetric loss difference.

  5. 5. Compare with autodiff

    Use relative error and several epsilon values.

Example

Four gradient interpretation traps

Gradient values are shaped by parameterization as well as behavior.

Two of the traps below have been measured by people who went looking for them. In both cases the number is larger than the intuition that the detail is a technicality.

  • Rescaling a parameter and compensating elsewhere can change gradient magnitudes without changing the network function at all. A magnitude comparison between coordinates is then partly a comparison between conventions.
  • A zero gradient at a ReLU boundary depends on the framework’s chosen subgradient convention, and the choice is not free. PyTorch’s autograd notes state the rule that produces it: for a locally convex function it returns “a subgradient of minimum norm”, which at the kink of ReLU is 0 out of the admissible interval [0, 1]. TensorFlow and Jax choose the same value, s = 0. Bertoin and colleagues priced the convention in 2021, and then repriced it: the published figures for the size of the effect were withdrawn by the authors themselves in a 2023 erratum, after three other researchers found a bug in the backward implementation of their modified ReLU. What survives the correction is the bifurcation itself — 43% of parameters affected at 32-bit precision, 100% at 16-bit, none at 64-bit. The magnitude of the difference is smaller by about five orders of magnitude, with no effect on training loss or test accuracy for reasonable values of the convention.
  • Mini-batch gradients are noisy estimates of the full-data gradient, so a single step’s direction is a sample and not the surface.
  • Large gradients in one layer can coexist with tiny gradients in another. A single global norm can look healthy while one layer of the stack learns nothing.
  • Feature attribution gradients answer a different question from parameter gradients used in training, and some of the popular ones answer no question about the model at all. Adebayo and colleagues randomized a trained model’s weights layer by layer in 2018 and reported: “Of the methods we tested, Gradients & GradCAM pass the sanity checks, while Guided BackProp & Guided GradCAM fail.” The plain input gradient changed as the weights were destroyed. Guided BackProp and Guided GradCAM “show no change regardless of model degradation”. Theory reached the same verdict that year. Nie and colleagues proved that Guided BackProp and DeconvNet are performing “(partial) image recovery which is unrelated to the network decisions”, then measured it over 10,000 ImageNet test images: the average L2 distance between the visualizations produced for two different class logits was much larger for the saliency map than for either of them.

Analogy

A local compass on unfamiliar terrain

A hiker uses the slope beneath one boot to choose a downhill direction. The reading is useful nearby, but it cannot reveal a valley hidden beyond a ridge.

Neural training moves in millions or billions of dimensions. Optimizers also add momentum, adaptive scaling, and stochastic estimates beyond one local compass reading.

Gradients are powerful because they are local and cheap, not because they describe the whole landscape.

Key idea

Parameter scale changes the geometry

A gradient is expressed in loss units per parameter unit, and two coordinates with different scales cannot be compared naively.

Normalization, reparameterization, adaptive optimizers, and preconditioning alter how updates use gradient components. None of them changes the underlying fact that first-order information is local.

The geometry can be changed without changing the model at all. In a network of rectifier units the map Tα : (θ1, θ2) ↦ (αθ1, α−1θ2) leaves the computed function untouched for every α > 0, as Dinh and colleagues showed in 2017. The two settings are, in their term, “observationally equivalent”. Meanwhile “Tα has Jacobian determinant α^(n1−n2)”, so the volume of a neighbourhood around the minimum is rescaled by it. They used this to “exploit the particular geometry of parameter space induced by the inherent symmetries that these architectures exhibit to build equivalent models corresponding to arbitrarily sharper minima”. Those models compute exactly the same function as the original.

That is not a curiosity confined to a proof. A tool for drawing loss surfaces needed “filter normalization” invented for it first, before any two surfaces could be compared, and Li and colleagues gave the reason in one sentence in 2018: “When ReLU non-linearities are used, the network remains unchanged if we (for example) multiply the weights in one layer of a network by 10, and divide the next layer by 10.” They record where it leads — “this scale invariance was exploited by Dinh et al. to build pairs of equivalent networks that have different apparent sharpness” — and normalize each direction filter by filter to remove it. Any sharpness or magnitude read off raw parameter geometry is an artifact of the parameterization. The cost of that fact is a preprocessing step you have to perform before the picture means anything. Gradient magnitude is one such quantity.

Gradient magnitude is coordinate-dependent, so “importance” claims require caution.

Key takeaways