Derivatives and Partial Derivatives
A single number that answers one question: if I nudge this input a little, how much does the output move, and in which direction?
Why Does This Exist?
A model learns by changing numbers. To change one sensibly you need to know what changing it does — and "the loss went from 2.31 to 2.29" is useless on its own, because you cannot tell whether that was your nudge or the noise in the batch. What you need is the response per unit of change, isolated to the one number you touched.
That quantity is the derivative, and it is the atom of every training algorithm in use today. Learning rate schedules, Adam, weight decay, gradient clipping, LoRA — all of them are strategies for spending derivatives well. If this page is fuzzy, everything built on it stays fuzzy, which is why it is the first page of the band.
There is a second reason it matters practically. A derivative tells you not just the direction but the sensitivity. When one parameter has a derivative of 0.0001 and another has 400, you are looking at the reason a single global learning rate struggles, and the reason adaptive optimisers were invented.
Think of It Like This
The speedometer, not the odometer
Your odometer says you have driven 180 kilometres. That is the total. It tells you nothing about what is happening right now — you could be parked.
The speedometer is the derivative. It reads the rate at this instant: kilometres per hour, right here. Press the accelerator and it climbs immediately, long before the odometer notices.
Everything about derivatives is in that distinction. The odometer is the function; the speedometer is its derivative. And notice the speedometer is a local reading — it tells you about now, and says nothing about the traffic jam in ten minutes. Derivatives are local too, which is exactly why training takes many small steps instead of one confident leap.
How It Actually Works
Start with the honest definition. The derivative of at a point is what the rise-over-run slope settles down to as you shrink the run to nothing:
In plain words: move a tiny step to the right, see how much the output changed, and divide by the size of the step. The limit says "and keep shrinking that step until the answer stops changing."
That is a definition, not a method. In practice you use rules, and for machine learning you need surprisingly few. The power rule, , covers polynomials. Sums differentiate term by term. Constants differentiate to zero. That is enough for this page; products and compositions are the chain rule's territory.
Reading the sign and the size
Two pieces of information come out, and they get used differently:
- The sign says which way. Positive means the output rises as the input rises, so to reduce the output you decrease the input. This is where training's minus sign comes from.
- The size says how much, per unit. A derivative of 400 means a nudge of 0.001 moves the output by roughly 0.4. A derivative of 0.0001 means that same nudge barely registers.
A derivative of exactly zero is a flat spot — a stationary point. It might be a minimum, a maximum, or a saddle, and the derivative alone cannot tell you which.
Partial derivatives: the same idea, more knobs
Real models have millions of inputs, not one. The extension is almost anticlimactic: differentiate with respect to one variable and treat every other variable as a constant. Nothing else changes.
Write it with a curly instead of a straight to signal that other variables exist and are being held still:
Read as "the change in per unit of , with everything else frozen." The freezing is the whole trick, and it is why the mechanical work is no harder than the single-variable case — a term with no in it is a constant, and constants differentiate to zero.
Collect one partial derivative per parameter into a single vector and you have a gradient, which is the object optimisers actually consume.
Worked example
Take and stand at .
By the power rule, , so . The output climbs four times as fast as the input, right there.
You can see that number on the diagram above as a slope triangle. Step 0.5 to the right along the tangent and it rises by 2, so the slope is . Note that the slope is not a property of the curve as a whole — at it would be 2, and at it would be 0. Local, always.
Now the two-variable case. Take at the point :
For the first, contained no , so it was a constant and vanished. For the second, was the constant. The output is more sensitive to here than to , even though we are further along — that asymmetry comes from the coefficient 3, and it is exactly the kind of imbalance that makes optimisation harder.
Show Me the Code
import numpy as np
def g(x: float, y: float) -> float: return x**2 + 3 * y**2
def partial(f, x: float, y: float, axis: int, h: float = 1e-5) -> float: # Perturb ONE input, hold the other still — that is the whole definition. dx, dy = (h, 0.0) if axis == 0 else (0.0, h) return (f(x + dx, y + dy) - f(x - dx, y - dy)) / (2 * h)
print(partial(g, 2.0, 1.0, axis=0)) # -> 4.000000... (analytic 2x = 4)print(partial(g, 2.0, 1.0, axis=1)) # -> 6.000000... (analytic 6y = 6)print(np.round([partial(g, 2.0, 1.0, axis=a) for a in (0, 1)], 6)) # -> [4. 6.]The axis argument is the "hold everything else still" instruction, written out. Both numbers match the ones derived by hand, which is the point of running it.
Watch Out For
Reading a derivative as a prediction instead of a rate
A derivative of 4 does not mean "the output will increase by 4." It means "the output increases by about 4 units per unit of input, for a small enough step."
That word small is load-bearing, and misreading it is the most common practical error. With at , the derivative predicts that stepping 1 to the right raises the output by 4, giving 8. The true value is . The derivative was not wrong — the step was too big for a straight-line approximation of a curve to hold.
This is precisely why training uses a learning rate to take small steps rather than jumping to where the slope says the bottom is. A large learning rate is a bet that the local slope holds over a long distance, and on a curved surface that bet loses.
Differentiating at a point where the derivative does not exist
Not every function has a derivative everywhere, and ML is full of the exceptions. ReLU has a corner at zero. abs() has one too. The L1 norm has corners along every axis. At a corner the slope from the left and the slope from the right disagree, so there is no single answer.
Frameworks do not error on this. They pick a value — often 0 or 1 — and carry on, so the failure is silent. Usually it is harmless, because landing exactly on the corner in floating point is rare and the subgradient chosen is a legitimate one.
Where it bites is when your data makes the corner common rather than rare. Feed a batch of exact zeros through ReLU, or apply L1 to a tensor that is already sparse, and a large fraction of your gradients come from an arbitrary convention rather than from the mathematics. If a model plateaus with suspiciously many exact zeros in its gradients, this is worth checking before anything else.
The Quick Version
- A derivative is a rate of change: output movement per unit of input movement, measured at one point.
- Its sign gives the direction and its size gives the sensitivity. Training uses both.
- It is local. It describes the slope right here and promises nothing further away, which is why steps are small.
- A partial derivative is the identical idea with other variables held frozen — written rather than .
- Terms without the variable you are differentiating are constants, so they drop to zero. That is most of the work.
- One partial derivative per parameter, collected into a vector, is a gradient.
- Corners (ReLU,
abs, L1) have no derivative. Frameworks silently substitute one.
What to Read Next
- The Chain Rule extends this to functions built out of other functions, which is every neural network.
- Gradients collects these partial derivatives into the vector that optimisers actually follow.
- Norms is where the L1 corner from the second pitfall comes from, and what it buys you.
- Definitions worth a look: Derivative, Partial Derivative, and Stationary Point.
- Related interview question: What does the chain rule actually do during training?