Differentiation Core
Use this sub-skill when a task is about Autograd's core differentiation operators: scalar gradients, Jacobians, directional derivatives, Hessians, VJP/JVP pullbacks, generalized Gauss-Newton products, complex holomorphic derivatives, checkpointing, or numerical gradient checks.
Trigger examples
- "I need
grad or value_and_grad for a scalar loss."
- "I need
jacobian or elementwise_grad for a vector-valued output."
- "I need a Hessian-vector product,
make_vjp, or make_jvp."
- "I want to verify a derivative with
check_grads."
- "My function has
if/while branches and I want to know whether Autograd can still differentiate it."
Read first
references/api-reference.md for operator selection, return conventions, and mode relationships.
references/workflows.md for scalar-loss, vector-output, higher-order, complex, and gradient-checking recipes.
references/troubleshooting.md for scalar-output errors, argnum confusion, shape mismatches, holomorphic warnings, and checkpoint tradeoffs.
scripts/differentiation_smoke.py for a runnable smoke that exercises the core operators without plotting.
Boundary routing
- Wrapper behavior, NumPy/SciPy support,
A.dot(B) / in-place / container pitfalls, and optional dependency questions belong in ../numpy-scipy-primitives/SKILL.md.
primitive, defvjp, defjvp, and custom VJP/JVP mechanics belong in ../extend-primitives/SKILL.md.
- Optimizer wiring, flattening, and
fixed_point belong in ../optimization-workflows/SKILL.md.
How to choose an operator
- Use reverse mode when the output is a real scalar and the input is large:
grad, value_and_grad, or make_vjp.
- Use forward mode when the input is scalar or you want one directional derivative:
deriv or make_jvp.
- Use
jacobian when you need the full output-to-input sensitivity tensor.
- Use
elementwise_grad when the function is real-valued and elementwise so the Jacobian is diagonal or column-summed.
- Use
hessian, hessian_tensor_product, hessian_vector_product, or make_ggnvp when you need curvature without writing the matrix explicitly.
- Use
holomorphic_grad only for complex-holomorphic functions.
- Use
checkpoint when the function is deep and memory is the bottleneck.
- Use
grad_and_aux when the function returns a scalar loss plus extra side information.
Core rules
grad and value_and_grad require a real scalar output.
jacobian works on scalar or array outputs and returns a tensor with output shape first and input shape last.
elementwise_grad is not a general Jacobian helper; it returns the column-sum/diagonal behavior used for elementwise real functions.
- Control flow is transparent to Autograd: the executed Python path matters, not the unexecuted branches.
make_vjp exposes the reverse-mode pullback; make_jvp exposes the forward-mode pushforward.
- Higher-order derivatives are usually formed by composing these operators.
grad_and_aux differentiates only the first output and returns the auxiliary payload unchanged.
checkpoint recomputes forward intermediates during the backward pass to trade time for memory.
Typical route
- Start with
grad for a scalar loss.
- If the output is vector-valued, switch to
jacobian or elementwise_grad.
- If you need both the value and the gradient, use
value_and_grad.
- If you need a directional derivative, use
deriv or make_jvp.
- If you need a pullback from output cotangents, use
make_vjp.
- If you need curvature information, use
hessian or a Hessian-vector product helper.
- If the function is complex-valued and holomorphic, use
holomorphic_grad.
- If the function is deep and memory-bound, wrap it with
checkpoint.
- Validate the chosen operator with
check_grads before trusting a new workflow.
Reliability notes
- Use
check_grads for a single function and combo_check when you want the same assertion to cover several positional or keyword combinations.
- When a derivative shape looks wrong, inspect the primal input and output shapes before changing the operator.
- When the function is intentionally branchy, choose a test point away from the branch threshold.
- When the failure message names a missing VJP or JVP rule for a primitive, route to
../extend-primitives/SKILL.md instead of trying to solve it here.
What this sub-skill does not cover
- Built-in NumPy/SciPy wrapper behavior and compatibility traps live in
../numpy-scipy-primitives/SKILL.md.
- Defining new primitives or VJP/JVP rules lives in
../extend-primitives/SKILL.md.
- Optimizer flattening and structured parameter updates live in
../optimization-workflows/SKILL.md.
Fastest sanity check
Run scripts/differentiation_smoke.py when you need a quick end-to-end check that the bundled differentiation guidance still matches the installed package.
1---2name: differentiation-core3description: "Routes scalar and array differentiation, higher-order derivatives,4 and gradient checking for Autograd's core AD operators."5disable-model-invocation: true6metadata:7 source: https://skillmd.com/skills/vectorspacelab/differentiation-core8 disco-role: operating9license: MIT10---1112# Differentiation Core1314Use this sub-skill when a task is about Autograd's core differentiation operators: scalar gradients, Jacobians, directional derivatives, Hessians, VJP/JVP pullbacks, generalized Gauss-Newton products, complex holomorphic derivatives, checkpointing, or numerical gradient checks.1516## Trigger examples1718- "I need `grad` or `value_and_grad` for a scalar loss."19- "I need `jacobian` or `elementwise_grad` for a vector-valued output."20- "I need a Hessian-vector product, `make_vjp`, or `make_jvp`."21- "I want to verify a derivative with `check_grads`."22- "My function has `if`/`while` branches and I want to know whether Autograd can still differentiate it."2324## Read first2526- `references/api-reference.md` for operator selection, return conventions, and mode relationships.27- `references/workflows.md` for scalar-loss, vector-output, higher-order, complex, and gradient-checking recipes.28- `references/troubleshooting.md` for scalar-output errors, argnum confusion, shape mismatches, holomorphic warnings, and checkpoint tradeoffs.29- `scripts/differentiation_smoke.py` for a runnable smoke that exercises the core operators without plotting.3031## Boundary routing3233- Wrapper behavior, NumPy/SciPy support, `A.dot(B)` / in-place / container pitfalls, and optional dependency questions belong in `../numpy-scipy-primitives/SKILL.md`.34- `primitive`, `defvjp`, `defjvp`, and custom VJP/JVP mechanics belong in `../extend-primitives/SKILL.md`.35- Optimizer wiring, flattening, and `fixed_point` belong in `../optimization-workflows/SKILL.md`.3637## How to choose an operator3839- Use reverse mode when the output is a real scalar and the input is large: `grad`, `value_and_grad`, or `make_vjp`.40- Use forward mode when the input is scalar or you want one directional derivative: `deriv` or `make_jvp`.41- Use `jacobian` when you need the full output-to-input sensitivity tensor.42- Use `elementwise_grad` when the function is real-valued and elementwise so the Jacobian is diagonal or column-summed.43- Use `hessian`, `hessian_tensor_product`, `hessian_vector_product`, or `make_ggnvp` when you need curvature without writing the matrix explicitly.44- Use `holomorphic_grad` only for complex-holomorphic functions.45- Use `checkpoint` when the function is deep and memory is the bottleneck.46- Use `grad_and_aux` when the function returns a scalar loss plus extra side information.4748## Core rules4950- `grad` and `value_and_grad` require a real scalar output.51- `jacobian` works on scalar or array outputs and returns a tensor with output shape first and input shape last.52- `elementwise_grad` is not a general Jacobian helper; it returns the column-sum/diagonal behavior used for elementwise real functions.53- Control flow is transparent to Autograd: the executed Python path matters, not the unexecuted branches.54- `make_vjp` exposes the reverse-mode pullback; `make_jvp` exposes the forward-mode pushforward.55- Higher-order derivatives are usually formed by composing these operators.56- `grad_and_aux` differentiates only the first output and returns the auxiliary payload unchanged.57- `checkpoint` recomputes forward intermediates during the backward pass to trade time for memory.5859## Typical route60611. Start with `grad` for a scalar loss.622. If the output is vector-valued, switch to `jacobian` or `elementwise_grad`.633. If you need both the value and the gradient, use `value_and_grad`.644. If you need a directional derivative, use `deriv` or `make_jvp`.655. If you need a pullback from output cotangents, use `make_vjp`.666. If you need curvature information, use `hessian` or a Hessian-vector product helper.677. If the function is complex-valued and holomorphic, use `holomorphic_grad`.688. If the function is deep and memory-bound, wrap it with `checkpoint`.699. Validate the chosen operator with `check_grads` before trusting a new workflow.7071## Reliability notes7273- Use `check_grads` for a single function and `combo_check` when you want the same assertion to cover several positional or keyword combinations.74- When a derivative shape looks wrong, inspect the primal input and output shapes before changing the operator.75- When the function is intentionally branchy, choose a test point away from the branch threshold.76- When the failure message names a missing VJP or JVP rule for a primitive, route to `../extend-primitives/SKILL.md` instead of trying to solve it here.7778## What this sub-skill does not cover7980- Built-in NumPy/SciPy wrapper behavior and compatibility traps live in `../numpy-scipy-primitives/SKILL.md`.81- Defining new primitives or VJP/JVP rules lives in `../extend-primitives/SKILL.md`.82- Optimizer flattening and structured parameter updates live in `../optimization-workflows/SKILL.md`.8384## Fastest sanity check8586Run `scripts/differentiation_smoke.py` when you need a quick end-to-end check that the bundled differentiation guidance still matches the installed package.