Phase 14 / Autodiff & JAX internals
JVPs, VJPs, and higher-order derivatives
Revision v0.18.1 · Updated since your last visit. Review the changes; your progress is saved.
Lesson · about 105 minutes · CPU practice
Compute and interpret JVP and VJP products with correct domains and shapes. Verify the adjoint dot-product identity against a hand-derived Jacobian.
Phase study guide: preparation, milestones and project evidence
Before you start
Before this: Read your first jaxpr
Hardware: CPU
Setup help: Python, notebook, or Cloud TPU VM
Use the tested CPU packages (the recorded environment uses Python 3.14.3). Other Python versions require separate checks. Hardware receipts apply only to their recorded source, environment, hardware, and cases; they do not qualify every lesson or TPU configuration. See the TPU performance and hardware evidence guide. The optional Cloud TPU specialization explains target-specific execution boundaries. Logical CPU devices practice partitioning; they do not simulate TPU performance.
Download the repository ZIP or use your existing checkout. Extract it and open a terminal in the folder containing requirements-cpu.txt. The beginner ZIP is separate; these lessons use the full repository folder.
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements-cpu.txtpy -3 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements-cpu.txtAfter activation, run the complete worked example from that same folder:
python phases/14-internals/02-jvps-vjps-and-higher-order-derivatives/code/main.py.\.venv\Scripts\python.exe phases/14-internals/02-jvps-vjps-and-higher-order-derivatives/code/main.pyFor an incremental build, create main.py in your own practice folder, append each build block in order, and run python main.py with this environment active. Keep that file separate from the downloaded reference solution.
Download this lesson’s notebook. Open it with a Python kernel using the course environment. Run cells from the top after restarting the kernel; experiments depend on earlier definitions.
For local Jupyter, first install the course requirements using the Local Python steps, then use your environment’s Python to start Jupyter:
python -m pip install jupyterlab
python -m jupyter lab.\.venv\Scripts\python.exe -m pip install jupyterlab
.\.venv\Scripts\python.exe -m jupyter labSelect the downloaded internals-02.ipynb file in JupyterLab. The notebook contains reference solutions; make your prediction and attempt each practice task before opening them. Restart the kernel before changing logical device setup.
The worked reference for this lesson is CPU-validated. Some references explicitly configure logical CPU devices; setting JAX_PLATFORMS does not adapt them to a TPU. Follow the execution matrix and reviewed multi-host example before attempting a target run.
For accelerator preparation, study TPU setup, observed runtime receipts, checkpointed jobs and precision and retained traces. Current receipts cover bounded v5e1 launch, resume, and precision checks; four single-device Pallas cases; and a four-device v5e collective fixture. Each receipt is limited to its recorded source, environment, cases, and hardware. It does not qualify all lessons or TPU configurations. Cloud provisioning is optional for CPU learning.
Check: JVP [-0.96, 1.52527319], VJP [1.49212199, -2.6], adjoint scalar approximately 2.57054639. The independently derived Hessian-vector product agrees.
Revisit the guided CPU setup · Open 19: TPU Setup. Package instructions are CPU instructions; Windows and accelerator environments need their own validation.
What you will be able to do
- Compute and interpret JVP and VJP products with correct domains and shapes.
- Verify the adjoint dot-product identity against a hand-derived Jacobian.
- Compute an exact Hessian-vector product and distinguish it from a Gauss–Newton approximation.
The problem
A large model may have millions of inputs or outputs, but you often need only one sensitivity direction. How can we compute the useful product without constructing the full Jacobian—and verify that forward, reverse and higher-order calculations agree?
The idea
A JVP asks how an input direction changes outputs. A VJP asks how an output sensitivity pulls back to inputs. Both use the same local derivative, but their vectors belong to different spaces.
Forward and reverse products answer complementary questions
For a map from three inputs to two outputs, the Jacobian has shape . A JVP consumes a three-component direction and returns two components. A VJP consumes a two-component cotangent and returns three.
Check the adjoint relation using independent dot products. It connects both directions without requiring the full Jacobian to be materialized.
When reading product bars, name the vector's space before interpreting its coordinates. A square example can hide a transpose mistake because both vectors have the same length. Add an unequal-dimension case to expose that ambiguity.
At the recorded point , the Jacobian is , with rows for outputs and columns for inputs. Thus the plotted JVP for is , a vector in output space. Keep that row/column convention beside the shapes: it makes a transposition error easier to spot than a square-shaped label alone.
JVP and VJP use different vector spaces
Predict: Does a VJP simply return the same vector as a JVP?
Read each row as a map between spaces: JVP takes through to ; VJP takes through to . The diagram’s three-to-two shape example is a shape lesson, while the executed numerical fixture happens to be two-to-two. Preserve that distinction; a nonsquare check is what catches swapped spaces.
Separate the point from the direction
For , the point determines a Jacobian. The direction says how the inputs will move near that point. JVP returns both the original output and . It does not evaluate the nonlinear function at ; its approximation becomes meaningful when multiplied by a sufficiently small displacement.
A VJP answers a different directional question
The cotangent weights changes in the two outputs. Pulling it back gives , a vector in input space. It is the gradient of the scalar function when is fixed. The pullback closes over the forward computation at this specific point; it must be rebuilt when the point changes.
Check the adjoint identity with independent values
The scalar can be computed either by pushing the direction first or pulling the measurement first. The two orders must agree: . Here JVP is approximately , VJP is , and both scalar products are about . This identity alone is insufficient if both rules share a mistake; the explicit Jacobian adds an independent oracle.
Count directions before choosing a Jacobian strategy
Forward mode naturally produces a Jacobian column for each input basis direction; reverse mode produces a row for each output basis direction. Many inputs and one scalar output often favor reverse mode, whereas a small number of input directions may favor forward products. Real runtime also depends on intermediates, batching and device behavior. This lesson verifies mathematical products, not a universal timing rule.
Curvature includes the changing Jacobian
For , the gradient is . Differentiating again gives . The first term is positive semidefinite and is often used as a Gauss–Newton approximation; it is exact only when the residual-weighted term vanishes. Forward-over-reverse differentiation computes without building every Hessian entry.
Use finite differences as a second perspective
A central difference of gradients approximates the Hessian-vector product, while a central difference of function outputs approximates the JVP. Sweep perturbations and retain a range of agreement; making the perturbation arbitrarily small causes cancellation. Float64 is explicitly enabled for these CPU comparisons. Non-smooth points and custom derivative rules require their own mathematical interpretation.
Forward and reverse products live in different spaces
Predict before looking: Should a JVP and VJP have equal coordinates just because this example has two inputs and two outputs?
Read the figure
The upper panel’s horizontal labels are output coordinates and its vertical unit is directional output change; JAX and analytic overlap at . The lower panel labels input coordinates and measures input cotangents; JAX and analytic overlap at . The two pairs agree within their own spaces, but their vectors are not interchangeable. Next check the scalar adjoint products, both about 2.57055.
Connect it to the computation
The recorded Jacobian maps a two-coordinate input direction to two output coordinates here, so shape alone cannot expose a transpose mistake. The independent products do: . Use an unequal input/output-size example when teaching the shape contract, then retain this fixture’s explicit Jacobian as the numerical check. These bars show derivative values, not execution cost.
Figure data and execution details
Open full-size figureDownload data and provenance
The notebook contains the data experiment, plotting code, and recorded figure output. Rerun it to test your changes.
Your build: Create a separate main.py in your practice folder. Append each block in order and run python main.py in the lesson environment. The downloaded script is the complete reference, so keep it separate from your attempt.
1 Define a small vector map and derive its Jacobian
Create main.py for the first block, then append subsequent blocks in order using your course CPU environment.
# Step 1 — Define a small vector map and derive its Jacobian: The map has two inputs and two outputs.
import jax
# Enable 64-bit arithmetic before importing jax.numpy or creating arrays.
jax.config.update("jax_enable_x64", True)
import jax.numpy as jnp
import numpy as np
def mapping(x):
a,b=x
return jnp.array([a*b,jnp.sin(a)+b*b])
x=jnp.array([0.4,-0.7])
v=jnp.array([1.2,-0.3])
u=jnp.array([0.5,2.0])
# Transfer the device result to the host for an independent NumPy comparison.
a,b=np.asarray(x)
jacobian=np.array([[b,a],[np.cos(a),2*b]])
expected_value=np.array([a*b,np.sin(a)+b*b])The map has two inputs and two outputs. Its Jacobian rows correspond to output coordinates, and columns to input coordinates.
Explain the APIs in this step
jnp.array(values, dtype=...): Constructs a JAX array from Python/NumPy values.
2 Push a direction forward and pull a measurement backward
Create main.py for the first block, then append subsequent blocks in order using your course CPU environment.
# Step 2 — Push a direction forward and pull a measurement backward
value,jvp=jax.jvp(mapping,(x,),(v,))
value_again,pullback=jax.vjp(mapping,x)
vjp,=pullback(u)
np.testing.assert_allclose(value,expected_value,rtol=1e-12)
# Transfer the device result to the host for an independent NumPy comparison.
np.testing.assert_allclose(jvp,jacobian@np.asarray(v),rtol=1e-12)
# Transfer the device result to the host for an independent NumPy comparison.
np.testing.assert_allclose(vjp,jacobian.T@np.asarray(u),rtol=1e-12)
left=float(jnp.vdot(u,jvp))
right=float(jnp.vdot(vjp,v))
np.testing.assert_allclose(left,right,rtol=1e-12)
print("Jacobian:",jacobian)
print("JVP:",np.asarray(jvp),"VJP:",np.asarray(vjp),"adjoint pair:",left,right)The VJP returns one cotangent per input argument, hence the one-element tuple. The dot-product identity checks that forward and reverse products represent adjoint linear maps.
Explain the APIs in this step
jax.jvp(fn, primals, tangents): Computes a function value and Jacobian-vector product for the supplied primal values and tangent directions.jax.vjp(fn, *primals): Computes a function value and a pullback for vector-Jacobian products.np.testing.assert_allclose(actual, desired, rtol=..., atol=...): Checks a host-side numerical expectation and raisesAssertionErrorwhen values differ beyond tolerance.
3 Compute curvature without materializing a Hessian
Create main.py for the first block, then append subsequent blocks in order using your course CPU environment.
# Step 3 — Compute curvature without materializing a Hessian
def objective(z):
return 0.5*jnp.vdot(mapping(z),mapping(z))
gradient=jax.grad(objective)(x)
hvp=jax.jvp(jax.grad(objective),(x,),(v,))[1]
y=expected_value
hessian_0=np.array([[0.,1.],[1.,0.]])
hessian_1=np.array([[-np.sin(a),0.],[0.,2.]])
hessian=jacobian.T@jacobian+y[0]*hessian_0+y[1]*hessian_1
np.testing.assert_allclose(gradient,jacobian.T@y,rtol=1e-12)
# Transfer the device result to the host for an independent NumPy comparison.
np.testing.assert_allclose(hvp,hessian@np.asarray(v),rtol=1e-12)
np.testing.assert_allclose(hessian,hessian.T,atol=1e-12)
print("Hessian-vector product:",np.asarray(hvp))For squared residuals, the Hessian includes a Jacobian-transpose-Jacobian term and residual-weighted second derivatives. Dropping the latter is an approximation, not the exact Hessian.
Explain the APIs in this step
jax.grad(loss_fn)(params, ...): Transforms a scalar-output function into one returning the gradient PyTree with the same structure asparams.jax.jvp(fn, primals, tangents): Computes a function value and Jacobian-vector product for the supplied primal values and tangent directions.np.testing.assert_allclose(actual, desired, rtol=..., atol=...): Checks a host-side numerical expectation and raisesAssertionErrorwhen values differ beyond tolerance.
View the cumulative build in main.py
These blocks append in order to your separate practice file.
# Step 1 — Define a small vector map and derive its Jacobian: The map has two inputs and two outputs.
import jax
# Enable 64-bit arithmetic before importing jax.numpy or creating arrays.
jax.config.update("jax_enable_x64", True)
import jax.numpy as jnp
import numpy as np
def mapping(x):
a,b=x
return jnp.array([a*b,jnp.sin(a)+b*b])
x=jnp.array([0.4,-0.7])
v=jnp.array([1.2,-0.3])
u=jnp.array([0.5,2.0])
# Transfer the device result to the host for an independent NumPy comparison.
a,b=np.asarray(x)
jacobian=np.array([[b,a],[np.cos(a),2*b]])
expected_value=np.array([a*b,np.sin(a)+b*b])
# Step 2 — Push a direction forward and pull a measurement backward
value,jvp=jax.jvp(mapping,(x,),(v,))
value_again,pullback=jax.vjp(mapping,x)
vjp,=pullback(u)
np.testing.assert_allclose(value,expected_value,rtol=1e-12)
# Transfer the device result to the host for an independent NumPy comparison.
np.testing.assert_allclose(jvp,jacobian@np.asarray(v),rtol=1e-12)
# Transfer the device result to the host for an independent NumPy comparison.
np.testing.assert_allclose(vjp,jacobian.T@np.asarray(u),rtol=1e-12)
left=float(jnp.vdot(u,jvp))
right=float(jnp.vdot(vjp,v))
np.testing.assert_allclose(left,right,rtol=1e-12)
print("Jacobian:",jacobian)
print("JVP:",np.asarray(jvp),"VJP:",np.asarray(vjp),"adjoint pair:",left,right)
# Step 3 — Compute curvature without materializing a Hessian
def objective(z):
return 0.5*jnp.vdot(mapping(z),mapping(z))
gradient=jax.grad(objective)(x)
hvp=jax.jvp(jax.grad(objective),(x,),(v,))[1]
y=expected_value
hessian_0=np.array([[0.,1.],[1.,0.]])
hessian_1=np.array([[-np.sin(a),0.],[0.,2.]])
hessian=jacobian.T@jacobian+y[0]*hessian_0+y[1]*hessian_1
np.testing.assert_allclose(gradient,jacobian.T@y,rtol=1e-12)
# Transfer the device result to the host for an independent NumPy comparison.
np.testing.assert_allclose(hvp,hessian@np.asarray(v),rtol=1e-12)
np.testing.assert_allclose(hessian,hessian.T,atol=1e-12)
print("Hessian-vector product:",np.asarray(hvp))Run the example
python3 phases/14-internals/02-jvps-vjps-and-higher-order-derivatives/code/main.pyAbout this command
This shortcut uses an activated macOS/Linux course environment in the repository folder. For Windows, use the explicit interpreter command in “Setup help” above. The script includes worked examples and reference solutions.
Inspect the complete assembled example
# Step 1 — Define a small vector map and derive its Jacobian: The map has two inputs and two outputs.
import jax
# Enable 64-bit arithmetic before importing jax.numpy or creating arrays.
jax.config.update("jax_enable_x64", True)
import jax.numpy as jnp
import numpy as np
def mapping(x):
a,b=x
return jnp.array([a*b,jnp.sin(a)+b*b])
x=jnp.array([0.4,-0.7])
v=jnp.array([1.2,-0.3])
u=jnp.array([0.5,2.0])
# Transfer the device result to the host for an independent NumPy comparison.
a,b=np.asarray(x)
jacobian=np.array([[b,a],[np.cos(a),2*b]])
expected_value=np.array([a*b,np.sin(a)+b*b])
# Step 2 — Push a direction forward and pull a measurement backward
value,jvp=jax.jvp(mapping,(x,),(v,))
value_again,pullback=jax.vjp(mapping,x)
vjp,=pullback(u)
np.testing.assert_allclose(value,expected_value,rtol=1e-12)
# Transfer the device result to the host for an independent NumPy comparison.
np.testing.assert_allclose(jvp,jacobian@np.asarray(v),rtol=1e-12)
# Transfer the device result to the host for an independent NumPy comparison.
np.testing.assert_allclose(vjp,jacobian.T@np.asarray(u),rtol=1e-12)
left=float(jnp.vdot(u,jvp))
right=float(jnp.vdot(vjp,v))
np.testing.assert_allclose(left,right,rtol=1e-12)
print("Jacobian:",jacobian)
print("JVP:",np.asarray(jvp),"VJP:",np.asarray(vjp),"adjoint pair:",left,right)
# Step 3 — Compute curvature without materializing a Hessian
def objective(z):
return 0.5*jnp.vdot(mapping(z),mapping(z))
gradient=jax.grad(objective)(x)
hvp=jax.jvp(jax.grad(objective),(x,),(v,))[1]
y=expected_value
hessian_0=np.array([[0.,1.],[1.,0.]])
hessian_1=np.array([[-np.sin(a),0.],[0.,2.]])
hessian=jacobian.T@jacobian+y[0]*hessian_0+y[1]*hessian_1
np.testing.assert_allclose(gradient,jacobian.T@y,rtol=1e-12)
# Transfer the device result to the host for an independent NumPy comparison.
np.testing.assert_allclose(hvp,hessian@np.asarray(v),rtol=1e-12)
np.testing.assert_allclose(hessian,hessian.T,atol=1e-12)
print("Hessian-vector product:",np.asarray(hvp))Expected result: JVP [-0.96, 1.52527319], VJP [1.49212199, -2.6], adjoint scalar approximately 2.57054639. The independently derived Hessian-vector product agrees.
Recorded output and runtime details
Reference output captured from executing the complete lesson script (code/main.py) and its assertions in the course CPU environment.
Jacobian: [[-0.7 0.4 ]
[ 0.92106099 -1.4 ]]
JVP: [-0.96 1.52527319] VJP: [ 1.49212199 -2.6 ] adjoint pair: 2.570546385606924 2.570546385606924
Hessian-vector product: [ 1.74991568 -3.38303348]
Jacobian: [[-0.7 0.4 ]
[ 0.92106099 -1.4 ]]
JVP: [-0.96 1.52527319] VJP: [ 1.49212199 -2.6 ] adjoint pair: 2.570546385606924 2.570546385606924
Hessian-vector product: [ 1.74991568 -3.38303348]
Forward columns and reverse rows agree
Exact HVP: [ 1.74991568 -3.38303348] Gauss-Newton product: [ 2.07686964 -2.51938247]
Changed-point adjoint verified
Direction linearity holds; the Jacobian changes with the base point
Bilinear Hessian symmetry and finite-difference product verified
PASS: internals-02
Download execution record · The notebook includes executed cells and figure outputs. Compare your run with these values; timings depend on the machine.
Reconstruct columns and rows independently
# Experiment — Reconstruct columns and rows independently
basis=jnp.eye(2)
columns=jax.vmap(lambda direction:jax.jvp(mapping,(x,),(direction,))[1])(basis).T
# Vectorize across the batch dimension with `jax.vmap` (`rows`).
rows=jax.vmap(lambda weighting:pullback(weighting)[0])(basis)
np.testing.assert_allclose(columns,jacobian,rtol=1e-12)
np.testing.assert_allclose(rows,jacobian,rtol=1e-12)
print("Forward columns and reverse rows agree")Expected: Both reconstructed matrices equal the hand-derived Jacobian.
The transpose in the forward construction is necessary: vmap first stacks one directional result per input basis vector.
Separate exact curvature from Gauss–Newton
# Experiment — Separate exact curvature from Gauss–Newton
gauss_newton=jacobian.T@jacobian
approximation=gauss_newton@np.asarray(v)
assert np.linalg.norm(np.asarray(hvp)-approximation)>0.1
eps=1e-4
fd=(np.asarray(jax.grad(objective)(x+eps*v))-np.asarray(jax.grad(objective)(x-eps*v)))/(2*eps)
np.testing.assert_allclose(hvp,fd,rtol=1e-7,atol=1e-8)
print("Exact HVP:",np.asarray(hvp),"Gauss-Newton product:",approximation)Expected: The approximation differs visibly; the finite-difference gradient check matches the exact HVP.
Residuals are nonzero, and both output functions have second derivatives. Calling the approximation the Hessian would erase those contributions.
Make it yours
Where to put your code: Modify your own main.py, or use the Make it yours cell in your downloaded notebook. Run your attempt in the declared environment and verify your prediction before opening the reference solution.
Repeat the Jacobian, JVP, VJP and adjoint checks at with and . Explain which quantities belong to input and output space.
Show a writing guide and starter scaffold
How to write this exercise code
Learner-only inputs, outputs, checks and hints
Inputs
- Vector function mapping R² to R².
- Changed base point x=(-0.2, 0.8), tangent v=(-0.5, 1.3), and output cotangent u=(1.1, -0.4).
Outputs
- Jacobian, JVP, VJP, and adjoint inner products at the changed point.
Invariants to check
- JVP belongs to output space and VJP belongs to input space.
- The two adjoint inner products agree within numerical tolerance.
Hints
- Use the changed primal and seeds for every transform.
- Check each result shape before comparing scalar inner products.
import jax
import jax.numpy as jnp
def inspect_changed_linearization(function, x, v, u):
# TODO: compute Jacobian, JVP, VJP, and both adjoint inner products.
raise NotImplementedError("Check primal, tangent, and cotangent spaces separately")Reveal the reference solution
# Exercise solution
changed_x=jnp.array([-0.2,0.8])
changed_v=jnp.array([-0.5,1.3])
changed_u=jnp.array([1.1,-0.4])
# Transfer the device result to the host for an independent NumPy comparison.
a2,b2=np.asarray(changed_x)
j2=np.array([[b2,a2],[np.cos(a2),2*b2]])
fj=jax.jvp(mapping,(changed_x,),(changed_v,))[1]
rj=jax.vjp(mapping,changed_x)[1](changed_u)[0]
np.testing.assert_allclose(fj,j2@changed_v,rtol=1e-12)
np.testing.assert_allclose(rj,j2.T@changed_u,rtol=1e-12)
np.testing.assert_allclose(jnp.vdot(changed_u,fj),jnp.vdot(rj,changed_v),rtol=1e-12)
print("Changed-point adjoint verified")Test linearity at a fixed point
Practice
Check the JVP of against the same combination of separate JVPs. Then show why changing the base point is a different operation.
Show a writing guide and starter scaffold
How to write this practice solution
Learner-only inputs, outputs, checks and hints
Inputs
- A fixed base point, tangent directions v and w, and f(v,w)=2v-w.
Outputs
- JVP for a combined direction and sum of separate JVPs.
Invariants to check
- The base point remains fixed for the linearity comparison.
- Changing the base point is not tangent linearity.
Hints
- Use jax.jvp at one shared primal input.
- Compare one combined seed with the linear combination of separate seeds.
import jax
import jax.numpy as jnp
def check_jvp_linearity(function, base, v, w):
# TODO: compare combined and separate JVPs at the same base.
raise NotImplementedError("Test tangent linearity without changing the primal point")Show a hint
A derivative is linear in its direction at a fixed base point.
Reveal reference solution and reasoning
# Test linearity at a fixed point (Practice): Linearity in the tangent is a local property.
w=jnp.array([-0.6,0.9])
product=lambda direction:jax.jvp(mapping,(x,),(direction,))[1]
np.testing.assert_allclose(product(2*v-w),2*product(v)-product(w),rtol=1e-12)
shifted=jax.jvp(mapping,(x+w,),(v,))[1]
assert np.linalg.norm(np.asarray(shifted-product(v)))>0.1
print("Direction linearity holds; the Jacobian changes with the base point")Linearity in the tangent is a local property. A nonlinear function need not use the same linear map at different points.
Check curvature symmetry without a full Hessian
Challenge
For two directions , verify , then verify one product with finite differences.
Show a writing guide and starter scaffold
How to write this practice solution
Learner-only inputs, outputs, checks and hints
Inputs
- A scalar-valued twice-differentiable function, base point, and directions v,w.
Outputs
- Both mixed Hessian directional products and a finite-difference check.
Invariants to check
- Mixed products agree within a stated tolerance.
- Finite differences independently check one Hessian-vector product.
Hints
- Compute Hessian-vector products with forward-over-reverse or jvp(grad).
- Perturb the gradient along one direction for the finite-difference comparison.
import jax
import jax.numpy as jnp
def check_hessian_symmetry(function, point, v, w, epsilon):
# TODO: compare the two mixed products and finite-difference one product.
raise NotImplementedError("Verify curvature symmetry without materializing the Hessian")Show a hint
Compose jvp with grad and compare scalar products.
Reveal reference solution and reasoning
# Check curvature symmetry without a full Hessian (Challenge): For this smooth scalar objective, mixed partials agree.
w=jnp.array([0.2,0.9])
hw=jax.jvp(jax.grad(objective),(x,),(w,))[1]
np.testing.assert_allclose(jnp.vdot(w,hvp),jnp.vdot(v,hw),rtol=1e-12)
eps=1e-4
fdw=(jax.grad(objective)(x+eps*w)-jax.grad(objective)(x-eps*w))/(2*eps)
np.testing.assert_allclose(hw,fdw,rtol=1e-7,atol=1e-8)
print("Bilinear Hessian symmetry and finite-difference product verified")For this smooth scalar objective, mixed partials agree. Symmetry is a useful invariant, but an independent derivative check is still necessary.
Diagnose the result
If a product has the wrong shape, identify whether its seed lives in input or output space. If basis reconstruction is transposed, inspect which index vmap stacks first. If an HVP differs from J-transpose-J times the direction, calculate the residual-weighted second-derivative term before blaming autodiff.
Carry forward
- Separate the point from the direction
- A VJP answers a different directional question
- Check the adjoint identity with independent values
- Count directions before choosing a Jacobian strategy
- Curvature includes the changing Jacobian
- Use finite differences as a second perspective
Keep your evidence
Hand-derived Jacobian/Hessian, adjoint scalar, changed-point checks, finite-difference HVP and a Gauss–Newton distinction. Keep the environment, observed outputs and your explanation of the figure.
Save your modified code, its output, and an explanation of your prediction. Checkpoint answers and exercise evidence are tracked separately.
Saved in this browser. Export or back up your portfolio anytime in My learning.
Reference execution: CPU validation only. This worked reference is validated on CPU. Accelerator compatibility requires a separate source review and target execution receipt. Use the execution matrix to review device selection and data ownership before adapting a separate target program. Execution matrix and target qualification.