Skip to main content

curvature.default

curvature.default(params, caps, /, *, likelihood=None, weighted=False)

A method per block, from the probe.

The first that fits, in a fixed order: the dense GGN for blocks of at most DENSE_MAX_PARAMS parameters, KFAC where module hooks reach the layer, the exact diagonal, then the sampled Fisher diagonal. The first and third need vjp and vmap. Plugins never change the choice.

Outputs of more than MAX_DENSE_EVENT entries per example (caps.event_size, e.g. tokens times vocabulary) get only sampled methods: KFAC(fisher="mc") where KFAC fits, else DiagGGN(fisher="mc").

KFAC is skipped when KFAC.supports refuses the block (the likelihood, or a tied tensor) or the batches carry per-example weights. It is skipped on every block once the probe recorded index selections (caps.selected), since check then refuses hook methods for the whole fit. KFAC also needs the layer’s weight in the block, so a bias-only block goes to the next method.

A likelihood without a closed-form output Hessian gets the GGN methods with fisher="mc". One with neither an output Hessian nor sampling (from_log_prob) gets DiagGGN(fisher="empirical") on every block, which needs targets.

Parameters

Name Type Description Default
params Params The parameters to fit. Their blocks are those of Layout.by_module. required
caps Capabilities The probe’s capabilities. required
likelihood Likelihood | None The likelihood. With None, KFAC checks only the tie. None
weighted bool Whether the batches carry per-example weights. False

Returns

Name Type Description
PerBlockCurvature The methods as a PerBlockCurvature. Blocks with the same method share one rule ("*" when there is a single method, else a tuple of block names), so each method runs once per batch over all its blocks.