# LayerRule

``` python
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](#hessiankit.LayerRule.check) | Raise `UnsupportedLayerError` naming `name` if the rule can’t handle `module` on `x`. |
| [grads](#hessiankit.LayerRule.grads) | The gradient at the layer output as `[N, T, D_out]`. |
| [inputs](#hessiankit.LayerRule.inputs) | The layer input as `[N, T, G, D_in]`, without a bias column. |

### check

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

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

### grads

``` python
LayerRule.grads(module, g, /)
```

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

### inputs

``` python
LayerRule.inputs(module, x, /)
```

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