Higher-Order Derivatives in Modern AI


Training faster, opening the model, and tracing its data

Vishnu Boddeti

Jacobian or Hessian?

Jacobian: input–output sensitivity

\(J_f(x)=[\partial f_i/\partial x_j]\)

One row per output; one column per input.

Which input directions move the representation?

Hessian: local curvature

\(H_f(\theta)=\nabla_\theta^2 f(\theta)\)

It measures how the gradient changes as parameters move.

Which parameter directions are sharp or flat?

At model scale: use operators

\(Jv,\quad u^\top J,\quad Hv\)

Automatic differentiation applies these maps without storing the full matrix.

Ask for the product you need.

Example 1

Sophia uses curvature to pretrain language models faster

What problem does Sophia solve?

Sophia and AdamW validation loss curves for GPT-2 and GPT-NeoX pretraining, plus scaling with model size

Across the reported GPT-2 and GPT-NeoX runs, Sophia reaches the same validation loss in about half as many steps as AdamW.

Sophia keeps a cheap diagonal view of the Hessian

1. GradientAverage the noisy minibatch gradients.\(m_t\approx\mathbb E[g_t]\)
2. CurvatureOccasionally estimate the positive diagonal Hessian.\(h_t\approx\operatorname{diag}(H_t)\)
3. PreconditionDivide each coordinate by its own curvature scale.\(m_t/(\gamma h_t+\varepsilon)\)
4. ClipCap coordinates when curvature is noisy or negative.\(\operatorname{clip}(\cdot,\rho)\)

The second-order information is deliberately incomplete: Sophia trades a full Hessian for an inexpensive diagonal estimate refreshed only every few steps.

Increase curvature contrast and compare one learning rate with Hessian scaling

Move the control: one global step size becomes harder to tune as curvature becomes less uniform.
Second-order scaling lets sharp and flat coordinates make useful progress together.

Example 2

Neural-VSI recovers hidden fields in high-order PDEs

What problem does Neural-VSI solve?

Neural-VSI runtime and recovered stiffness and damping fields compared with a strong-form baseline

The task is system identification: recover the beam's hidden parameter fields from observed motion. The figure shows runtime, stiffness recovery, and damping recovery.

The weak form changes what must be differentiated

Measured fieldSensors provide noisy displacement values.\(u(x,t)\)
Strong PDEThe beam equation contains fourth-order spatial derivatives.\(\partial_x^2(Pu_{xx})\)
Local weak formIntegration by parts transfers derivatives to known test functions.\(\int_{\Omega_i}w\,\mathcal L[u]\,dx\)
Parameter fieldsReusable matrices constrain neural fields for stiffness and damping.\(P_\phi(x),\ C_\psi(x)\)

The model still learns unknown functions, but it no longer asks automatic differentiation to repeatedly construct the highest-order spatial derivatives of the measured field.

Widen the weak-form window and trade spatial detail for noise averaging

A larger local window pools more measurements but blurs rapid spatial changes.
The weak form is not merely faster: it changes the statistical and numerical problem the learner sees.

Example 3

A Jacobian turns one LLM prediction into a local linear map

What does an input-specific LLM Jacobian reveal?

Transformer diagram showing detached nonlinear gates and a Jacobian reconstruction of the predicted output embedding

Freeze the prompt-dependent gates during differentiation: the resulting Jacobian reconstructs the output embedding and can be decomposed with SVD.

The singular vectors answer two different questions

\(f(x+\Delta x)\approx f(x)+J_x\Delta x\)

\(J_x=U\Sigma V^\top\)

The linearization is tied to one prompt and one point in embedding space.

  • Right singular vectors \(v_i\): input-embedding directions to which this prediction is sensitive.
  • Left singular vectors \(u_i\): output features produced by those directions.
  • Singular values \(\sigma_i\): amplification along each paired direction.
  • A steep spectrum means the local computation is effectively low-rank.

Retain more Jacobian singular directions and watch reconstruction saturate

When the spectrum decays quickly, a small subspace explains most of the local map.
Low local rank is an analysis result—not a claim that the entire LLM is globally linear.

Example 4

Influence functions trace an output back to training data

Influence finds examples that teach the same text operation

Most and least influential LoRA training examples for sentence transformation and math reasoning prompts

The most influential examples share the requested transformation or reasoning pattern; the least influential examples do not.

The same influence calculation audits diffusion outputs

Most and least influential LoRA training examples for diffusion style and subject generation

For style and subject generation, the highest-ranked training images visibly match the requested output.

Inverse curvature converts parameter similarity into behavioral influence

Training gradientHow example \(z_i\) pushes the fitted parameters.\(g_i=\nabla_\theta\ell(z_i,\theta)\)
Curvature correctionHow easily the optimum moves in each direction.\((H+\lambda I)^{-1}g_i\)
Test gradientWhich movement matters for the behavior being audited.\(g_{test}^\top\)
Influence scoreRank examples by their predicted local effect.\(-g_{test}^\top(H+\lambda I)^{-1}g_i\)

The formula is a local approximation around the fitted parameters. DataInf exploits LoRA's low-dimensional structure to avoid forming or inverting the full Hessian.

Raise LoRA rank and compare influence fidelity with compute

The low-rank assumption is what makes second-order attribution practical.
Treat influence as evidence for an audit, not as proof of causation by one training item.

Practice problems

Each scenario hides a mathematical structure from this lecture. Identify the structure, justify it, and work through the resulting problem.

Problem 1 Loss landscapes

Is a stationary model a solution or a saddle?

Training stops at a point where the gradient is zero. That sounds promising, but the local surface may be a mountain pass rather than a valley. Should the optimizer settle there or escape?

Model evidence

$L(w_1,w_2)=w_1^2+4w_1w_2+w_2^2$.

  1. Where are the stationary points?
  2. What does the local curvature say about their type?
  3. Can you show one direction that raises the loss and another that lowers it?
Problem 2 Matrix calculus

Differentiate a batch least-squares layer

A prediction head processes a whole batch at once, and the optimizer wants one matrix-shaped gradient. Computing a separate scalar derivative for every entry would miss the structure hiding in the matrix expression.

Model evidence

$F(W)=\frac12\|WX-Y\|_F^2$, $W=\begin{bmatrix}1&0\end{bmatrix}$, $X=\begin{bmatrix}1&0\\1&2\end{bmatrix}$, and $Y=\begin{bmatrix}2&1\end{bmatrix}$.

  1. What is the gradient with respect to $W$ in matrix form?
  2. What does it equal for the supplied matrices?
  3. Does its shape match the parameter it is meant to update?
Problem 3 Generative adversarial networks

Recognize the local geometry of an adversarial game

Near equilibrium, a generator tries to lower a local objective while a discriminator tries to raise it. Their parameters are coupled, so an ordinary “both directions should curve upward” test tells the wrong story.

Model evidence

$V(\theta,\phi)=\theta^2+\theta\phi-\phi^2$.

  1. Where is the simultaneous stationary point?
  2. With the other player fixed, is the point a minimum for the generator and a maximum for the discriminator?
  3. Why is the full Hessian not an ordinary minimization Hessian here?