What is a partial derivative?
A partial derivative measures how a function of several variables changes when one input moves and all the others are held fixed. For f(x, y) it is written ∂f/∂x or ∂f/∂y. Collecting every partial derivative of a scalar function into one vector gives the gradient, ∇f, which points in the direction of steepest increase.
A neural network's loss is a scalar function of all its weights, so training needs one partial derivative per weight. Backpropagation computes that whole gradient, and optimizers such as SGD and Adam use it to update every parameter at once. The same idea underlies sensitivity analysis, feature attributions such as saliency maps, and physics simulations.
Key ideas
- A partial derivative changes one input and holds all the others fixed.
- The gradient ∇f is the vector of all partial derivatives of a scalar function.
- The gradient points in the direction of steepest increase, and its length is that steepest slope.
- The gradient is perpendicular to the contour lines of the function.
- Zero gradient marks a critical point, which can be a minimum, maximum, or saddle.
- Gradient descent steps opposite to the gradient, scaled by the learning rate.
Common questions
What is the difference between a partial derivative and a total derivative?
A partial derivative holds the other inputs fixed. A total derivative lets them change too, when they depend on the same underlying variable. If x and y both depend on t, then df/dt = (∂f/∂x)(dx/dt) + (∂f/∂y)(dy/dt), which adds up the effect through every path.
Does the order of partial derivatives matter?
For smooth functions it does not. Schwarz's theorem (also called Clairaut's) says ∂²f/∂x∂y = ∂²f/∂y∂x whenever both second partials are continuous. For f = x² + xy + y², both mixed partials equal 1.
What does a large partial derivative tell you about a feature?
It says the output is locally sensitive to that input: a small change there moves f a lot. Saliency maps for image models use this, showing ∂(class score)/∂(pixel) as a heatmap. The measure is local and depends on the input's scale, so a large value is not proof that a feature matters globally.
How do you get partial derivatives in PyTorch?
Mark the inputs with requires_grad=True, compute a scalar output, and call .backward() on it. Each input's .grad attribute then holds the partial derivative of the output with respect to that input. torch.autograd.grad returns the same values without storing them on the tensors.
Related explainers
- Derivatives — The calculus behind gradient descent
- The Chain Rule — How derivatives compose through layers
- Matrix Calculus & Jacobians — Partial derivatives, gradients, and the Jacobian — calculus for vectors
- Gradient Descent — Optimizing by following the slope downhill
- Optimizers — SGD, momentum, and Adam — smarter gradient descent
- Backpropagation — How networks learn from their mistakes
References
- Deisenroth, Faisal & Ong, "Mathematics for Machine Learning", ch. 5 Vector Calculus
- Goodfellow, Bengio & Courville, "Deep Learning", ch. 4 Numerical Computation
- Simonyan, Vedaldi & Zisserman (2013), "Deep Inside Convolutional Networks: Visualising Image Classification Models and Saliency Maps"
Last updated