{"course":{"slug":"maths-you-need","title":"The Maths You Actually Need","url":"https://addaly.com/learn/maths-you-need","level":"intermediate","track":"deep"},"lesson":{"slug":"partial-derivatives-and-the-gradient","title":"Many knobs, one derivative each","url":"https://addaly.com/learn/maths-you-need/partial-derivatives-and-the-gradient","position":21,"of":76,"minutes":8,"answer":"A partial derivative is the slope in one variable with all others frozen, and the gradient collects them into a vector that points in the direction of steepest increase.","keyIdea":"A partial derivative is the slope in one variable with all others frozen, and the gradient collects them into a vector that points in the direction of steepest increase."},"body":{"format":"markdown","text":"## Freeze everything else\n\nA loss depends on millions of weights, not one. The extension is simpler than it sounds: to find the partial derivative with respect to one variable, treat every other variable as a constant and differentiate as usual.\n\nTake `f(x, y) = x^2 + 3xy + y^3`.\n\nFor the partial with respect to x, pretend y is a fixed number:\n\n```\nd/dx of x^2   = 2x\nd/dx of 3xy   = 3y        (y is a constant, so this is 3y times x)\nd/dx of y^3   = 0         (no x in it, so it is a constant)\n\ndf/dx = 2x + 3y\n```\n\nNow the same for y, pretending x is fixed:\n\n```\ndf/dy = 0 + 3x + 3y^2 = 3x + 3y^2\n```\n\nEvaluate both at the point (2, 1):\n\n```\ndf/dx = 2(2) + 3(1) = 7\ndf/dy = 3(2) + 3(1) = 9\n```\n\nSo at (2, 1), nudging x up increases f at rate 7, and nudging y up increases it at rate 9.\n\n## The gradient is the collection\n\nStack the partials into a vector and you have the gradient, written `∇f`:\n\n```\ngrad f at (2, 1) = [7, 9]\n```\n\nThis vector has two properties that carry the whole of gradient-based training.\n\n**It points in the direction of steepest increase.** Not \"a direction that increases f\": the steepest one, out of all possible directions. Move against it and you descend as fast as locally possible.\n\n**Its length says how steep.** `||[7, 9]|| = sqrt(49 + 81) = 11.4`. A gradient norm of 11.4 means the function is changing quickly here. A norm near zero means you are somewhere flat.\n\nThat second quantity is the one to watch during training. `grad_norm` in a training log is exactly this, computed over every parameter at once, and its behaviour tells you more about what is going wrong than the loss does.\n\n## Reading the direction claim carefully\n\nWhy is the gradient the *steepest* direction rather than merely an uphill one? Because the rate of change in any unit direction `u` is the dot product `∇f · u`, and from the module on vectors, a dot product with a fixed vector is largest when `u` points the same way as that vector. The gradient is not defined as steepest ascent; it turns out to be it.\n\nThe consequence used everywhere: to go down fastest, step along `−∇f`. That is gradient descent, and the whole of it is\n\n```\nw  <-  w - learning_rate * grad\n```\n\nrepeated. With the gradient `[7, 9]` and a learning rate of 0.1, you move from (2, 1) to `(2 − 0.7, 1 − 0.9) = (1.3, 0.1)`.\n\n## Steepest is local, not global\n\nThe word to hold onto is *locally*. The gradient describes the surface at the exact point you are standing on and says nothing about what is over the hill. In a long, narrow valley (the common case in real loss landscapes) the steepest direction points at the near wall, not along the valley floor. You cross the valley, overshoot slightly, cross back, and progress along the floor is slow.\n\nThat zigzag is the standard picture of ill-conditioning. It is caused by curvature differing wildly between directions, and it is the problem that momentum, Adam and learning-rate schedules all exist to reduce. Nothing is broken when it happens; the gradient is doing exactly what it promised, which is only ever a local promise.\n\n## The scale of it in a real model\n\nFor a model with 7 billion parameters, the gradient is a vector with 7 billion entries: one partial derivative per weight, recomputed on every batch. Stored as 32-bit floats that is 28 GB, which is why the memory arithmetic of training is dominated by gradients and optimiser state rather than by the weights themselves.\n\nNobody computes those partials one at a time. Automatic differentiation gets all of them in roughly the cost of one extra forward pass, which is the subject of the backpropagation lesson two along from here. It is worth pausing on how surprising that is: seven billion derivatives for the price of about two function evaluations.\n\n## Checking your intuition on a real surface\n\n```python\nimport numpy as np\ndef f(v): x, y = v; return x**2 + 3*x*y + y**3\ndef grad(v): x, y = v; return np.array([2*x + 3*y, 3*x + 3*y**2])\n\nv = np.array([2.0, 1.0])\nfor step in range(5):\n    g = grad(v)\n    v = v - 0.05 * g\n    print(step, v.round(3), f(v).round(4), np.linalg.norm(g).round(3))\n```\n\nWatch the third column fall and the fourth shrink. When the gradient norm approaches zero you have arrived somewhere flat, which may be a minimum, and may not be.\n\n## The rule to keep\n\nOne partial derivative per parameter, collected into a vector that points uphill fastest. Its length is the number to watch: a gradient norm that collapses towards zero or explodes towards thousands is telling you about your training long before the loss curve does."},"check":{"question":"During training, the loss is barely moving but the logged gradient norm is large and roughly constant. Which explanation fits the mechanism best?","options":[{"text":"The model has converged to a minimum, where the gradient is naturally flat.","correct":false,"tempting":"At a minimum the gradient norm would be small, not large; these two observations contradict each other."},{"text":"Steps are bouncing across a narrow, steeply-curved valley rather than travelling along it, so each step is large but the net progress is small.","correct":true},{"text":"The gradient is being computed on the wrong loss, since a large gradient always produces a large loss change.","correct":false,"tempting":"A large gradient guarantees a large change only for an infinitesimal step; at a finite learning rate, overshoot can cancel the progress."},{"text":"The learning rate is too small, so the large gradient is being multiplied down to nothing.","correct":false,"tempting":"A too-small learning rate gives slow but steady descent, whereas this pattern is flat loss with persistent large gradients."}]},"prev":{"slug":"derivatives-and-descent","title":"Slopes, and why training is walking downhill","url":"https://addaly.com/learn/maths-you-need/derivatives-and-descent"},"next":{"slug":"the-chain-rule","title":"The chain rule, which is the whole trick","url":"https://addaly.com/learn/maths-you-need/the-chain-rule"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Source and assessment review continues. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'Many knobs, one derivative each', in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/partial-derivatives-and-the-gradient (Accessed: 29 November 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"Many knobs, one derivative each","courseTitle":"The Maths You Actually Need","module":{"index":3,"slug":"change-and-descent","title":"Change, slopes and the walk downhill"},"answer":null,"keyIdea":"A partial derivative is the slope in one variable with all others frozen, and the gradient collects them into a vector that points in the direction of steepest increase.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"freeze-everything-else","runs":[{"text":"Freeze everything else"}]},{"t":"p","runs":[{"text":"A loss depends on millions of weights, not one. The extension is simpler than it sounds: to find the partial derivative with respect to one variable, treat every other variable as a constant and differentiate as usual."}]},{"t":"p","runs":[{"text":"Take "},{"text":"f(x, y) = x^2 + 3xy + y^3","code":true},{"text":"."}]},{"t":"p","runs":[{"text":"For the partial with respect to x, pretend y is a fixed number:"}]},{"t":"code","lang":"","label":"Text","text":"d/dx of x^2   = 2x\nd/dx of 3xy   = 3y        (y is a constant, so this is 3y times x)\nd/dx of y^3   = 0         (no x in it, so it is a constant)\n\ndf/dx = 2x + 3y"},{"t":"p","runs":[{"text":"Now the same for y, pretending x is fixed:"}]},{"t":"code","lang":"","label":"Text","text":"df/dy = 0 + 3x + 3y^2 = 3x + 3y^2"},{"t":"p","runs":[{"text":"Evaluate both at the point (2, 1):"}]},{"t":"code","lang":"","label":"Text","text":"df/dx = 2(2) + 3(1) = 7\ndf/dy = 3(2) + 3(1) = 9"},{"t":"p","runs":[{"text":"So at (2, 1), nudging x up increases f at rate 7, and nudging y up increases it at rate 9."}]},{"t":"h2","id":"the-gradient-is-the-collection","runs":[{"text":"The gradient is the collection"}]},{"t":"p","runs":[{"text":"Stack the partials into a vector and you have the gradient, written "},{"text":"∇f","code":true},{"text":":"}]},{"t":"code","lang":"","label":"Text","text":"grad f at (2, 1) = [7, 9]"},{"t":"p","runs":[{"text":"This vector has two properties that carry the whole of gradient-based training."}]},{"t":"p","runs":[{"text":"It points in the direction of steepest increase.","b":true},{"text":" Not “a direction that increases f”: the steepest one, out of all possible directions. Move against it and you descend as fast as locally possible."}]},{"t":"p","runs":[{"text":"Its length says how steep.","b":true},{"text":" "},{"text":"||[7, 9]|| = sqrt(49 + 81) = 11.4","code":true},{"text":". A gradient norm of 11.4 means the function is changing quickly here. A norm near zero means you are somewhere flat."}]},{"t":"p","runs":[{"text":"That second quantity is the one to watch during training. "},{"text":"grad_norm","code":true},{"text":" in a training log is exactly this, computed over every parameter at once, and its behaviour tells you more about what is going wrong than the loss does."}]},{"t":"h2","id":"reading-the-direction-claim-carefully","runs":[{"text":"Reading the direction claim carefully"}]},{"t":"p","runs":[{"text":"Why is the gradient the "},{"text":"steepest","i":true},{"text":" direction rather than merely an uphill one? Because the rate of change in any unit direction "},{"text":"u","code":true},{"text":" is the dot product "},{"text":"∇f · u","code":true},{"text":", and from the module on vectors, a dot product with a fixed vector is largest when "},{"text":"u","code":true},{"text":" points the same way as that vector. The gradient is not defined as steepest ascent; it turns out to be it."}]},{"t":"p","runs":[{"text":"The consequence used everywhere: to go down fastest, step along "},{"text":"−∇f","code":true},{"text":". That is gradient descent, and the whole of it is"}]},{"t":"code","lang":"","label":"Text","text":"w  <-  w - learning_rate * grad"},{"t":"p","runs":[{"text":"repeated. With the gradient "},{"text":"[7, 9]","code":true},{"text":" and a learning rate of 0.1, you move from (2, 1) to "},{"text":"(2 − 0.7, 1 − 0.9) = (1.3, 0.1)","code":true},{"text":"."}]},{"t":"h2","id":"steepest-is-local-not-global","runs":[{"text":"Steepest is local, not global"}]},{"t":"p","runs":[{"text":"The word to hold onto is "},{"text":"locally","i":true},{"text":". The gradient describes the surface at the exact point you are standing on and says nothing about what is over the hill. In a long, narrow valley (the common case in real loss landscapes) the steepest direction points at the near wall, not along the valley floor. You cross the valley, overshoot slightly, cross back, and progress along the floor is slow."}]},{"t":"p","runs":[{"text":"That zigzag is the standard picture of ill-conditioning. It is caused by curvature differing wildly between directions, and it is the problem that momentum, Adam and learning-rate schedules all exist to reduce. Nothing is broken when it happens; the gradient is doing exactly what it promised, which is only ever a local promise."}]},{"t":"h2","id":"the-scale-of-it-in-a-real-model","runs":[{"text":"The scale of it in a real model"}]},{"t":"p","runs":[{"text":"For a model with 7 billion parameters, the gradient is a vector with 7 billion entries: one partial derivative per weight, recomputed on every batch. Stored as 32-bit floats that is 28 GB, which is why the memory arithmetic of training is dominated by gradients and optimiser state rather than by the weights themselves."}]},{"t":"p","runs":[{"text":"Nobody computes those partials one at a time. Automatic differentiation gets all of them in roughly the cost of one extra forward pass, which is the subject of the backpropagation lesson two along from here. It is worth pausing on how surprising that is: seven billion derivatives for the price of about two function evaluations."}]},{"t":"h2","id":"checking-your-intuition-on-a-real-surface","runs":[{"text":"Checking your intuition on a real surface"}]},{"t":"code","lang":"python","label":"Python","text":"import numpy as np\ndef f(v): x, y = v; return x**2 + 3*x*y + y**3\ndef grad(v): x, y = v; return np.array([2*x + 3*y, 3*x + 3*y**2])\n\nv = np.array([2.0, 1.0])\nfor step in range(5):\n    g = grad(v)\n    v = v - 0.05 * g\n    print(step, v.round(3), f(v).round(4), np.linalg.norm(g).round(3))"},{"t":"p","runs":[{"text":"Watch the third column fall and the fourth shrink. When the gradient norm approaches zero you have arrived somewhere flat, which may be a minimum, and may not be."}]},{"t":"h2","id":"the-rule-to-keep","runs":[{"text":"The rule to keep"}]},{"t":"p","runs":[{"text":"One partial derivative per parameter, collected into a vector that points uphill fastest. Its length is the number to watch: a gradient norm that collapses towards zero or explodes towards thousands is telling you about your training long before the loss curve does."}]}],"check":{"question":[{"text":"During training, the loss is barely moving but the logged gradient norm is large and roughly constant. Which explanation fits the mechanism best?"}],"options":[{"text":[{"text":"The model has converged to a minimum, where the gradient is naturally flat."}],"correct":false,"tempting":[{"text":"At a minimum the gradient norm would be small, not large; these two observations contradict each other."}]},{"text":[{"text":"Steps are bouncing across a narrow, steeply-curved valley rather than travelling along it, so each step is large but the net progress is small."}],"correct":true,"tempting":null},{"text":[{"text":"The gradient is being computed on the wrong loss, since a large gradient always produces a large loss change."}],"correct":false,"tempting":[{"text":"A large gradient guarantees a large change only for an infinitesimal step; at a finite learning rate, overshoot can cancel the progress."}]},{"text":[{"text":"The learning rate is too small, so the large gradient is being multiplied down to nothing."}],"correct":false,"tempting":[{"text":"A too-small learning rate gives slow but steady descent, whereas this pattern is flat loss with persistent large gradients."}]}],"order":[0,1,3,2],"why":null},"prev":{"slug":"derivatives-and-descent","title":"Slopes, and why training is walking downhill","minutes":9},"next":{"slug":"the-chain-rule","title":"The chain rule, which is the whole trick","minutes":8}}}