๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #28

Partial Derivatives

A neural network's loss doesn't depend on just one number โ€” it depends on every weight simultaneously, often millions of them. A partial derivative measures how the loss changes with respect to just one of those weights, holding all the others fixed.

Notation and Definition

\[ \frac{\partial f}{\partial x} = \lim_{h \to 0} \frac{f(x+h, y) - f(x, y)}{h} \]

The symbol \(\partial\) (instead of \(d\)) signals "this function has more than one input, and we're only varying \(x\), treating every other input as a constant for this calculation."

Numerical Example

\[ f(x, y) = x^2 y + 3y \] \[ \frac{\partial f}{\partial x} = 2xy \qquad (\text{treat } y \text{ as a constant}) \] \[ \frac{\partial f}{\partial y} = x^2 + 3 \qquad (\text{treat } x \text{ as a constant}) \]

At \((x,y) = (2,1)\): \(\frac{\partial f}{\partial x} = 2(2)(1) = 4\), and \(\frac{\partial f}{\partial y} = 2^2+3 = 7\).

Code

import torch

x = torch.tensor(2.0, requires_grad=True)
y = torch.tensor(1.0, requires_grad=True)

f = x**2 * y + 3*y
f.backward()

print(x.grad)   # tensor(4.) -- df/dx
print(y.grad)   # tensor(7.) -- df/dy

Where This Shows Up in Deep Learning

A network's loss \(L(w_1, w_2, \ldots, w_n)\) is a function of every single weight. Training needs \(\frac{\partial L}{\partial w_i}\) for every weight \(w_i\) โ€” a whole collection of partial derivatives, one per parameter. Collecting all of them into a single vector is exactly what the next note, Gradient, does.

Common Mistakes

  • Forgetting to treat other variables as constants when computing one partial derivative โ€” mixing them up (e.g. accidentally differentiating \(y\) too when computing \(\partial f/\partial x\)) is the most common manual-calculation error.
  • Assuming partial derivatives require computing them one at a time by hand in real deep learning code โ€” in practice, autograd computes every partial derivative for every parameter automatically and in parallel in a single .backward() call.

Interview Relevance

Q: "Why does a neural network need partial derivatives instead of a single derivative?" Because the loss is a function of many weights simultaneously (potentially millions), not a single variable. A partial derivative isolates how the loss changes with respect to one specific weight, holding all others fixed โ€” exactly the per-parameter update signal training needs.

Practice Question

For \(f(x, y) = 3x^2y^3\), compute \(\frac{\partial f}{\partial x}\) and \(\frac{\partial f}{\partial y}\), then evaluate both at \((x,y) = (1,2)\).

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Partial Derivatives โ€“ FAQs

Quick answers about learning Partial Derivatives in Deep Learning.

This free note from CodingNow 2.0 explains Partial Derivatives in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Partial Derivatives, is 100% free with no signup required.
With focused practice, most students grasp Partial Derivatives in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now