The eager LayerNorm rule #
The eager tape checks the shapes of its input, scale, and bias, then saves those tensors in one
LayerNorm node. Its backward closure calls Spec.layerNormBackward and tags each cotangent with
the corresponding parent id.
These theorems inspect that recorded node. The forward value is the actual Spec.layerNorm
output, and applying its backward closure to a correctly shaped cotangent returns the three
blocks of the adjoint Fréchet derivative. The input-read hypotheses describe successful dynamic
shape checks; the derivative identity is proved from the real LayerNorm formula.
Parent ids may coincide. The closure still returns one contribution per argument; accumulation of contributions into a shared parent belongs to the tape traversal. This file concerns the exact real instantiation of the eager tape, whose tensor arithmetic has mathematical semantics.
Recording LayerNorm saves its specified forward value at the returned node id.
The successful lookups retain the original scale and bias tensors and the configured epsilon.
The stored eager backward closure returns the adjoint derivative in input, scale, bias order.
Reading the just-recorded node and invoking its closure both succeed. The resulting array keeps the runtime parent ids, so the equality also checks the correspondence between argument slots and cotangent destinations.