Skip to main content

core.Curvature

core.Curvature()

One pass over the data, a fold of batches into a statistic S.

R is an Operator for an ordinary curvature, or an intermediate result (an eigenbasis, a subset) for one pass of a staged method.

Attributes

Name Description
requires What the method needs from the model and the likelihood.

Methods

Name Description
finalize The result of the pass.
init The empty statistic, the identity of +.
update Fold one batch into the statistic.

finalize

core.Curvature.finalize(stat, /)

The result of the pass.

Parameters

Name Type Description Default
stat S The statistic over all the data, after all_reduce. required

Returns

Name Type Description
R For an ordinary curvature, an operator holding the per-example average \(\bar{C} = \sum_n w_n C_n / \sum_n w_n\). The posterior multiplies it by scale. For a pass of a staged method, the intermediate result.

Raises

Name Type Description
ValueError Implementations may raise it when the total weight is zero.

init

core.Curvature.init(params, ctx, /)

The empty statistic, the identity of +.

This is the place to refuse a fit before any data.

Parameters

Name Type Description Default
params Params The params the curvature is taken at. required
ctx FitContext The fit’s context. required

Returns

Name Type Description
S A statistic \(e\) with \(e + s = s\) for every statistic \(s\) of this fit.

Raises

Name Type Description
CapabilityError Implementations may raise it when the model or likelihood lacks something the method needs.
StructureError Implementations may raise it when the params or layout don’t fit the method.
ValueError Implementations may raise it when the method’s settings don’t fit the params (e.g. LowRankGGN with rank + oversample above the parameter count).

update

core.Curvature.update(stat, params, batch, generator, ctx, /)

Fold one batch into the statistic.

Pure: it returns a new statistic.

Parameters

Name Type Description Default
stat S The statistic so far. required
params Params The params the curvature is taken at. required
batch Batch The batch to add. Honour batch.weights when requires.weights is True. required
generator torch.Generator The batch’s own generator, on the params’ device. Sampled methods draw from it, e.g. torch.randn(..., generator=generator). required
ctx FitContext The fit’s context. required

Returns

Name Type Description
S stat with the batch folded in, so that updating with batches \(a\), then \(b\) equals adding the statistics of \(a\) and of \(b\).

Raises

Name Type Description
CapabilityError Implementations may raise it when the method needs targets and the batch has none (the empirical Fisher, the Hessian, an observed output Hessian).