Gradient Fields and Directional Derivatives
From computation graphs to LLM, VLM, and agent gradients
Vishnu Boddeti
Example 1
Reverse mode reuses the graph, so one backward sweep produces all parameter gradients at roughly the cost of a few forward evaluations.
Forward: compute and save intermediate values. Backward: revisit the same operations in reverse and apply the chain rule.
\[ \bar z=\sum_{s\in \mathrm{Child}(z)} \left(\frac{\partial s}{\partial z}\right)^{\!\top}\bar s \]
\[ |D_u f(x)|\le \|\nabla f(x)\|_2 \]
For \(f(x,y)=x^2+2y^2\), the gradient is \((2x,4y)\).
Example 2
A brief spike can create an enormous optimizer step. Clipping keeps the direction but caps the step length.

The baseline is small; occasional norms jump by orders of magnitude.

Most sustained spikes disappear after one step.
Clipping is a guardrail for the rare spike—not a replacement for the ordinary gradient.
\[ g_{\mathrm{clip}}=g\min\!\left(1,\frac{c}{\|g\|_2}\right) \]
Example 3
The same derivative can explain local sensitivity or construct a first-order adversarial attack.
Each noisy square is a learned pixel perturbation. The bird still looks unchanged, while its caption moves toward the baseball target.
Example 4
Tool calls are discrete and the reward is delayed, so ordinary backpropagation cannot simply flow through the whole trace.
Gradients train the model inside a step. Policy gradients or another credit-assignment method connect discrete tool calls across steps.
Each scenario hides a mathematical structure from this lecture. Identify the structure, justify it, and work through the resulting problem.
A red team cannot perturb an input arbitrarily; the hardware allows movement only along one physical sensor direction. Before launching an attack, can you predict which way along that line makes the loss rise fastest?
$L(x_1,x_2)=x_1^2+2x_1x_2+3x_2$, the current input is $x=(1,-1)$, and the feasible unit direction is $v=(1,1)/\sqrt2$.
A model first builds nonlinear features and then scores them. Instead of differentiating the whole expression from scratch, you have the local derivative of each stage. How do the two pieces snap together?
$h(x_1,x_2)=(x_1+x_2,x_1x_2)$, $g(z_1,z_2)=z_1^2+z_2$, and $x=(1,2)$.
A response surface predicts model error from data imbalance and label noise. You want to nudge both experimental settings and estimate the effect before running another expensive training job.
$E(a,b)=a^2e^b+ab$, evaluated at $(a,b)=(1,0)$.