Extend primitives

From VectorSpaceLab/AREX-Skill · View interactive version

Extend primitives is an AI agent skill from the GitHub repository VectorSpaceLab/AREX-Skill. Route custom primitive authoring, staged VJP/JVP closures, deprecated wrapper compatibility, and gradient checking.

How to use this skill

Skill file

extend-primitives

Use this sub-skill when a user needs to make a new primitive differentiable or extend an existing primitive with custom reverse- or forward-mode rules.

Route here for

Route elsewhere for

Evidence anchors

autograd/extend.py, autograd/core.py, autograd/test_util.py, docs/updateguide.md, docs/tutorial.md, examples/define_gradient.py, tests/test_wrappers.py

Bundled runtime files

Operating guidance

  1. Start from autograd.extend.primitive.
  2. Register a staged VJP/JVP rule immediately after the primitive is defined.
  3. Use the staged maker to capture only the forward-pass values needed by the derivative.
  4. Prefer defvjp_argnums / defjvp_argnums when one cached calculation should serve several argnums.
  5. Use None only when a rule is intentionally zeroed; omit the argnum entirely when you want the missing-path NotImplementedError.
  6. Validate tiny fixtures with check_grads; use combo_check when several positional or keyword combinations need coverage.
  7. Keep deprecated wrapper APIs only for compatibility with existing code and test fixtures; new authoring should use the staged API.

Quick smoke

Run python scripts/custom_primitive_smoke.py before handing off a draft.

Cross-links

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.