Create your own
Lesson illustration

Partial Derivatives and Gradients of Multivariable Functions

Hello. The previous lesson used SVD to describe linear transformations and low-rank structure. We now shift to the calculus used to optimize machine-learning models: how a scalar quantity such as a loss changes when its inputs or parameters change.

This lesson develops two closely related ideas:

  • a partial derivative, which measures sensitivity to one input while holding the others fixed;
  • a gradient, which collects all of those sensitivities into one vector.

For an ML Engineer interview, be ready to state both the computation and the interpretation: a gradient is not merely “a vector of derivatives”; it is the local direction of steepest increase of a scalar function.


Partial derivatives: one coordinate at a time

A single-variable derivative answers: “If changes slightly, how does change?”

For a function of two variables,

we must specify which coordinate is changing. The partial derivative with respect to , evaluated at , is

Here, remains fixed at . Similarly,

where remains fixed at .

The notation matters:

all denote the partial derivative with respect to .

The practical rule is simple:

When differentiating with respect to one variable, treat every other independent variable as a constant.

Partial Derivatives and the Gradient of a Function

Watch “Partial Derivatives and the Gradient of a Function” from Professor Dave Explains. It gives a concise visual introduction to holding one variable fixed, then builds from partial derivatives to gradients in two and three variables.

Watch the setup for the idea of varying one coordinate at a time. Then watch the two variable example, paying attention to which term becomes constant in each derivative. Continue with the gradient for its vector definition and steepest-ascent interpretation. Finally, use the three variable case to see that adding dimensions changes the number of components, not the underlying procedure.

Consider

To find the partial derivative with respect to , treat as a constant:

The term has no , so it behaves as a constant and vanishes.

To find the partial derivative with respect to , instead treat as a constant:

At the point ,

and

These are local rates of change, not the function value. At , moving in the positive -direction while keeping fixed increases at an instantaneous rate of per unit of . Moving in the positive -direction while keeping fixed increases it at a rate of per unit of .


Partial derivatives as slopes on a surface

For a scalar function of two inputs, forms a surface in three-dimensional space. A partial derivative is the slope of a particular cross-section of that surface.

A surface \(z=f(x,y)\) is sliced by holding one coordinate fixed. The green curve is the resulting one-variable cross-section, and its tangent line at \((a,b,f(a,b))\) has slope \(\frac{\partial f}{\partial x}(a,b)\).

In the image, changing while holding fixed traces the green curve. That curve is an ordinary one-variable function, so its tangent slope is exactly

The analogous -slice gives

This geometric picture is useful, but ML parameter spaces typically have thousands, millions, or billions of coordinates. We cannot visualize their surfaces. Partial derivatives remain meaningful because their definition does not depend on drawing the surface: each one measures what happens when exactly one coordinate changes and the rest are held fixed.

For a scalar function of variables,

there are first partial derivatives:

For example, if

then

and

When differentiating with respect to , both and the coefficient in are treated as constants.


The gradient: all first-order sensitivities together

When the output is scalar, the gradient packages every first partial derivative into a vector:

For a function of variables,

The symbol is called nabla or del. In ML literature, gradients are often written as row vectors, but treating them as column vectors makes the shapes in matrix expressions especially clear. The essential requirement is to keep conventions consistent.

For the earlier function,

the gradient is

At ,

This says that, locally, is more sensitive to a small positive change in than to an equally sized positive change in .

A compact way to express the local behavior of a differentiable function is the first-order approximation:

The approximation says: for a sufficiently small input change , the change in the function is approximately the dot product of the gradient with that input change.

This connects directly to the dot-product material from earlier in the course. The gradient turns a small vector of coordinate changes into an approximate scalar change in the output.


Direction, magnitude, and steepest change

Let be a unit vector indicating a direction. The instantaneous rate of change of in that direction is

Using the dot-product identity,

and because is a unit vector,

Here, is the angle between the gradient and the chosen direction.

Three consequences follow immediately:

  • The directional derivative is largest when points in the same direction as .
  • The maximum rate of increase is
  • The fastest local decrease is in the opposite direction,
At a point on a paraboloid, the gradient projected into the input plane points toward the most rapid local increase in the function, while the negative gradient points toward the most rapid decrease. Directions perpendicular to the gradient produce zero instantaneous change.

A direction perpendicular to the gradient has zero directional derivative:

In two dimensions, these are directions tangent to the function's level curves, where the function remains locally constant. The gradient is normal, or perpendicular, to such level curves.

A zero gradient,

means there is no first-order change in any direction. Such a point is called stationary. It is important not to overinterpret this condition:

  • it may be a local minimum;
  • it may be a local maximum;
  • it may be a saddle point;
  • it may occur on a flat region.

For example,

has

so

But is neither a minimum nor a maximum: moving along the -axis increases , while moving along the -axis decreases it.


Gradients in ML parameter space

In machine learning, the scalar function is usually a loss, objective, or log-likelihood, and the input vector is a parameter vector.

Suppose a model has two parameters:

and, for illustration, its loss is

The gradient with respect to the parameters is

At

the gradient is

Interpret each coordinate carefully:

  • : increasing slightly would locally decrease the loss.
  • : increasing slightly would locally increase the loss.

Thus, the gradient identifies a local uphill direction for the loss. Its negative identifies a local downhill direction. The next lesson will formalize how the chain rule lets us compute these gradients through model computations, and how a gradient-based update uses them.

For a neural network, may represent every weight and bias in the model. The same definition applies:

The dimensionality may be enormous, but each coordinate still answers the same question: How would the scalar loss change if this one parameter changed infinitesimally while all other parameters were fixed?


Calculation discipline and common mistakes

When computing gradients by hand, use this reliable sequence:

  1. Identify the scalar output. A gradient is defined here for a scalar-valued function such as .
  2. Fix the coordinate order. For , use the order consistently.
  3. Differentiate symbolically first. Substitute a point only after finding all partial derivatives.
  4. Treat non-active variables as constants.
  5. Evaluate every component at the same point.
  6. Check the resulting gradient shape. It must have one component per input coordinate.

A useful numerical sanity check for the -th gradient component is the central finite-difference approximation:

Here, is the vector with a in coordinate and zeros elsewhere, and is small. This is conceptually what gradient checking compares against an analytically derived or automatic-differentiation gradient.

Two distinctions are especially worth retaining:

  • A gradient applies to a scalar output. If a function has vector output, its first derivative is generally a Jacobian matrix.
  • A gradient is a local, first-order description. It need not predict the effect of a large parameter change, especially on a strongly curved or non-smooth loss surface.

Most ML objectives are differentiable almost everywhere. Some common components, such as the ReLU activation at zero, are not differentiable at isolated points; frameworks select a conventional subgradient there. The standard gradient machinery still applies broadly, but it is useful to know that “a partial derivative exists everywhere” is stronger than practical ML requires.


Key takeaways

A partial derivative measures the change in a function as one coordinate varies and all other coordinates remain fixed:

The gradient collects every first partial derivative of a scalar function:

It provides the first-order approximation

points in the direction of maximum local increase, and has magnitude equal to that maximum rate of increase. In an ML loss landscape, each gradient coordinate is the local sensitivity of loss to one parameter.

Next, you will apply the chain rule through a small computational graph and use the resulting gradient in a gradient-descent update—the core calculation underlying backpropagation and training.

Can't find a good explanation? Sign up and we'll make it for you

Sign up