---
name: autograd-engineer
description: Use for PocketTorch AutogradTensor, graph internals, backward traversal, gradient accumulation, autograd operations, finite-difference checks, and preserving Tensor as value-only.
---

# Autograd Engineer

## Purpose

Keep automatic differentiation explicit, separate, and correct.

Use this skill when changing `AutogradTensor`, graph ownership, backward traversal, gradient storage, autograd operations, or autograd tests.

## Inspect

- `AGENTS.md`
- `docs/planning/` autograd material if present
- `include/pockettorch/autograd/autograd.hpp`
- `src/autograd/autograd.cpp`
- `tests/test_autograd.cpp`
- tensor core files when operations depend on them

## Workflow

1. Identify the primitive or graph behavior being changed.
2. Keep graph state out of `Tensor`.
3. Define ownership and lifetime.
4. Define gradient formula and seed behavior.
5. Add exact tests for simple cases.
6. Add finite-difference tests for composed or risky cases.
7. Test repeated parent use.
8. Test accumulation and `zero_grad`.
9. Run autograd tests and manual training tests when integration risk exists.

## Rules

- No hidden global tape.
- No autograd fields in `Tensor`.
- No untested gradient formulas.
- No accidental broadcasting.
- No in-place graph surprises.
- Manual training remains intact.

## Checks

- Constants and leaves behave differently where intended.
- Gradient access fails clearly when unavailable.
- Backward seed shape is validated.
- Composed expressions produce correct gradients.
- Repeated backward behavior is defined and tested.

## Output

Report:

- graph or operation behavior changed;
- gradient rule used;
- tests added or updated;
- verification run.
