Skip to content

feat(autodiff): return expansion provenance beside the artifact - #134

Open
AlekseiChirkovVention wants to merge 3 commits into
feat/broadcast-scale-gradient-expansionfrom
feat/mean-expansion-provenance
Open

feat(autodiff): return expansion provenance beside the artifact#134
AlekseiChirkovVention wants to merge 3 commits into
feat/broadcast-scale-gradient-expansionfrom
feat/mean-expansion-provenance

Conversation

@AlekseiChirkovVention

Copy link
Copy Markdown
Collaborator

Report what each rewrite did, beside the artifact rather than inside it, and collapse the two
call forms onto a single rewrite implementation.

Goal

Both passes previously returned only the rewritten artifact, so a caller had to diff two
artifacts to learn what changed. Add detailed forms that also return one record per rewritten
region — which nodes were replaced, which were emitted, the value the region carries forward,
and which of the two forms it took.

Why provenance is a sidecar and never a parameter

Operator parameters are configuration: a handler reads them to decide what to emit, and cannot
be expected to tell configuration from bookkeeping. Writing expansion metadata there would
make every emitted node's parameters partly meaningless to the very handler that consumes
them. So the records are returned alongside the artifact, and a test asserts that no emitted
node's parameters carry any key beyond that operator's own.

The two call forms cannot disagree

Each composable pass is now defined as the detailed pass followed by selecting the artifact
field — a one-line delegation, not a parallel implementation. Only one rewrite exists in the
module.

This matters more than it looks. Two independent implementations that agree today are a defect
waiting for the first divergent edit, and nothing in a green test suite would reveal it. The
delegation makes disagreement structurally impossible rather than merely absent.

Both composable passes keep their exact single-positional-artifact signature. That signature is
the hook a separate feature consumes, so it is contract, not convenience.

Test evidence

Level: unit. Tests first: the failing set landed in b59be0c; 8b1bc03 made it pass.

25 cases, all passing. The two already-shipped expansion test files are byte-identical and
still green
— 51 and 27 cases — which is the regression signal that this refactor changed no
behaviour in the passes it rewrote. Focused autodiff suite: 819 → 844, exactly the new items.
Broad non-integration suite: 1095 passed, 9 failed, 1 skipped — the 9 pre-existing and
unrelated, unchanged in count across the whole series.

f2f9755 corrects two expectations that were wrong about the contract, before implementation:

  • The "nothing to rewrite" fixture traced a partial-axis reduction. That is an unsupported
    reduction, which the forward pass fails closed on rather than passing through, so the fixture
    raised instead of exercising the empty case. It now traces an artifact with no reduction node
    at all.
  • The gradient region's recorded source ids named only the division. The matched chain replaces
    both nodes — the broadcast is removed outright and the division's position is where the
    emitted region lands — so both belong in the record. The corrected assertion is strictly
    stronger than the one it replaces.

Two further cases pin that the composable signatures are unchanged. They pass before and after
by design: the criterion is "this did not change", so the assertion exists to catch a
regression in the refactor rather than to drive new behaviour.

Stack position

Stack position 5 of 8 — based on feat/broadcast-scale-gradient-expansion.

Cannot merge into main before feat/generated-constant-operator,
chore/generic-lowering-reference-consumer, feat/matmul-based-mean-expansion, and
feat/broadcast-scale-gradient-expansion.

Pin the sidecar surface: the two pass-name constants and their exact string
values, the three frozen record types and their exact fields, and one region
per rewritten region in artifact order with its source and emitted node ids and
terminal value id.

Assert that no emitted operator parameters gain a bookkeeping key. A handler
receives those parameters as operator configuration and cannot be expected to
tell configuration from bookkeeping, so provenance belongs beside the artifact
and never inside it.

Two cases pin that the composable passes keep their single-positional
signature. They pass before the change as well as after: that signature is the
hook a separate feature consumes, so the assertion exists to catch a regression
in the refactor rather than to drive new behaviour.
The no-rewritable-region fixture traced a partial-axis mean. That is an
unsupported mean, which the forward pass fails closed on rather than leaving
alone, so the fixture raised instead of exercising the empty-region case. Trace
an artifact with no reduction node at all.

The gradient region's recorded source ids named only the division. The matched
chain that gets replaced is both nodes -- the broadcast is removed outright and
the division's position is where the emitted region lands -- so both belong in
the record, in the order the artifact requires for the broadcast's output to
feed the division.

Both corrections fix expectations that were wrong about the contract. No
assertion was weakened to accommodate an implementation.
Report which nodes each rewrite replaced, which it emitted, the value the
region carries forward, and which of the two forms it took, so a caller can
inspect or diff a rewritten artifact rather than infer the change.

The bookkeeping is returned beside the artifact and never written into
operator parameters. A handler receives those parameters as configuration and
cannot be expected to tell configuration from bookkeeping; putting provenance
there would make every emitted node's parameters partly meaningless to its own
handler.

Each composable pass is now defined as the detailed pass followed by selecting
the artifact field. Only one rewrite implementation exists, so the two forms
cannot disagree, and both keep the single positional parameter that lets them
be used directly as an expansion hook.

A gradient-path region is recorded as rank-preserving: only two forms are
admitted, and that region performs no rank change whatever the source
reduction declared.
@AlekseiChirkovVention
AlekseiChirkovVention marked this pull request as ready for review August 28, 2026 06:19
@AlekseiChirkovVention AlekseiChirkovVention self-assigned this Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants