Plan
Plan(
method,
layers,
uncovered,
output_shape,
event_axes,
output_positions,
fisher,
fisher_reason,
mc_samples,
form,
form_reason,
backward_passes,
memory,
dtype,
)What hk.kfac or hk.diagonal would compute on a batch, and why, without computing.
str(plan) gives a short table.
Attributes
| Name | Type | Description |
|---|---|---|
| method | Method | "kfac" or "diagonal". |
| layers | Mapping[str, LayerInfo] | The layers, by path, in the model’s order. |
| uncovered | Mapping[str, str] | Trainable parameters no layer covers, by name, each with the reason. |
| output_shape | tuple[int, …] | The output’s shape on the batch. |
| event_axes | tuple[int, …] | The likelihood’s event axes of the output. |
| output_positions | int | P, the output’s positions per example: the product of the sizes of its axes that are neither the batch nor an event axis. |
| fisher | Fisher | "exact", "mc" or "empirical". |
| fisher_reason | str | Why: "given", or the count against EXACT_MAX_PASSES. |
| mc_samples | int | None | The samples per example for "mc", else None. |
| form | Literal['expand', 'reduce'] | None | KFAC’s "expand" or "reduce"; None for the diagonal. |
| form_reason | str | None | Why, or None for the diagonal. |
| backward_passes | int | Backward passes of the batch, one per output factor. |
| memory | int | Bytes of the result in dtype. |
| dtype | torch.dtype | The dtype the sums accumulate in. |
Examples
>>> import torch, hessiankit as hk
>>> from torch import nn
>>> model = nn.Sequential(nn.Linear(4, 8), nn.ReLU(), nn.Linear(8, 3))
>>> batch = (torch.randn(16, 4), torch.randint(0, 3, (16,)))
>>> p = hk.plan(model, batch, hk.Categorical())
>>> list(p.layers), p.fisher, p.form, p.backward_passes
(['0', '2'], 'exact', 'reduce', 3)