differentiation-core
Routes scalar and array differentiation, higher-order derivatives, and gradient checking for Autograd's core AD operators.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- differentiation-core
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Routes scalar and array differentiation, higher-order derivatives, and gradient checking for Autograd's core AD operators.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md4.9 KB
- 参考文档references/troubleshooting.md3.9 KB
- 参考文档references/workflows.md6.9 KB
- 脚本scripts/differentiation_smoke.py4.1 KB
03 SKILL.md 正文
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
gradorvalue_and_gradfor a scalar loss." - "I need
jacobianorelementwise_gradfor a vector-valued output." - "I need a Hessian-vector product,
make_vjp, ormake_jvp." - "I want to verify a derivative with
check_grads." - "My function has
if/whilebranches and I want to know whether Autograd can still differentiate it."
Read first
references/api-reference.mdfor operator selection, return conventions, and mode relationships.references/workflows.mdfor scalar-loss, vector-output, higher-order, complex, and gradient-checking recipes.references/troubleshooting.mdfor scalar-output errors, argnum confusion, shape mismatches, holomorphic warnings, and checkpoint tradeoffs.scripts/differentiation_smoke.pyfor 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_pointbelong 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, ormake_vjp. - Use forward mode when the input is scalar or you want one directional derivative:
derivormake_jvp. - Use
jacobianwhen you need the full output-to-input sensitivity tensor. - Use
elementwise_gradwhen the function is real-valued and elementwise so the Jacobian is diagonal or column-summed. - Use
hessian,hessian_tensor_product,hessian_vector_product, ormake_ggnvpwhen you need curvature without writing the matrix explicitly. - Use
holomorphic_gradonly for complex-holomorphic functions. - Use
checkpointwhen the function is deep and memory is the bottleneck. - Use
grad_and_auxwhen the function returns a scalar loss plus extra side information.
Core rules
gradandvalue_and_gradrequire a real scalar output.jacobianworks on scalar or array outputs and returns a tensor with output shape first and input shape last.elementwise_gradis 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_vjpexposes the reverse-mode pullback;make_jvpexposes the forward-mode pushforward.- Higher-order derivatives are usually formed by composing these operators.
grad_and_auxdifferentiates only the first output and returns the auxiliary payload unchanged.checkpointrecomputes forward intermediates during the backward pass to trade time for memory.
Typical route
- Start with
gradfor a scalar loss. - If the output is vector-valued, switch to
jacobianorelementwise_grad. - If you need both the value and the gradient, use
value_and_grad. - If you need a directional derivative, use
derivormake_jvp. - If you need a pullback from output cotangents, use
make_vjp. - If you need curvature information, use
hessianor 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_gradsbefore trusting a new workflow.
Reliability notes
- Use
check_gradsfor a single function andcombo_checkwhen 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.mdinstead 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.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).