feat(autodiff): return expansion provenance beside the artifact - #134
Open
AlekseiChirkovVention wants to merge 3 commits into
Open
feat(autodiff): return expansion provenance beside the artifact#134AlekseiChirkovVention wants to merge 3 commits into
AlekseiChirkovVention wants to merge 3 commits into
Conversation
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.
code-tc
approved these changes
Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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;8b1bc03made 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.
f2f9755corrects two expectations that were wrong about the contract, before implementation: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.
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
mainbeforefeat/generated-constant-operator,chore/generic-lowering-reference-consumer,feat/matmul-based-mean-expansion, andfeat/broadcast-scale-gradient-expansion.