Skip to main content

LayerDiagonal

LayerDiagonal(weight, bias, total_weight)

The exact GGN diagonal of one layer, summed over a batch.

Attributes

Name Type Description
weight Tensor sum_n w_n sum_e s_ne (J_n^T v_ne)^2 for the weight, shaped like it.
bias Tensor | None The same for the bias, shaped like it, or None when the layer has none.
total_weight Tensor W, the summed weight of the examples that counted. The diagonal of the per-example average GGN is weight / W.

Methods

Name Description
flat The weight’s diagonal flattened in row-major order, then the bias’s, in one vector.

flat

LayerDiagonal.flat()

The weight’s diagonal flattened in row-major order, then the bias’s, in one vector.

Examples

>>> import torch, hessiankit as hk
>>> d = hk.LayerDiagonal(torch.ones(3, 4), torch.ones(3), torch.tensor(1.0))
>>> d.flat().shape
torch.Size([15])