Skip to main content

LayerRule

LayerRule()

Turns a layer’s input and output gradient into the canonical form.

inputs gives [N, T, G, D_in] and grads gives [N, T, D_out]: N examples, T positions per example, G groups of output channels. Group g holds output channels g * D_out / G to (g + 1) * D_out / G - 1. With d the grads reshaped to [N, T, G, D_out / G], the weight gradient flattened to [D_out, D_in] is einsum("ntgo,ntgi->goi", d, inputs) reshaped to [D_out, D_in].

Methods

Name Description
check Raise UnsupportedLayerError naming name if the rule can’t handle module on x.
grads The gradient at the layer output as [N, T, D_out].
inputs The layer input as [N, T, G, D_in], without a bias column.

check

LayerRule.check(module, x, name, /)

Raise UnsupportedLayerError naming name if the rule can’t handle module on x.

grads

LayerRule.grads(module, g, /)

The gradient at the layer output as [N, T, D_out].

inputs

LayerRule.inputs(module, x, /)

The layer input as [N, T, G, D_in], without a bias column.