Skip to main content

core.probe

core.probe

Capability probe: run the model once and record what works.

Functions

Name Description
probe Run the model on the first two examples and record what works.

probe

core.probe.probe(model, lik, batch, /, params=None)

Run the model on the first two examples and record what works.

The probe records the forward order and the output size per example, then tries vjp, the VJP of a VJP, jvp and vmap(grad) on the first two examples. vmap(grad) goes through the likelihood’s log_prob when the batch has targets, else through the sum of the outputs. The double VJP must also agree with the plain one, which catches a backward that silently returns zeros when differentiated. The order pass runs once under no_grad.

A HasOutputCheck likelihood (each such leaf of a tree) checks the order pass’s outputs, with or without targets, before any transform is tried; what it raises propagates, except an AttributeError or TypeError on outputs that are not a tensor, which becomes a StructureError (see Raises). With targets, the likelihood’s log_prob runs on those outputs too. Any other failure is recorded as a missing capability, except the errors under Raises, which propagate.

Parameters

Name Type Description Default
model ModelFn The model as a function of the params. required
lik LikelihoodTree The likelihood, or a mapping of them. A likelihood mapping needs outputs and targets that are mappings with its keys. required
batch Batch The batch whose first two examples are probed. required
params Params | None The params the transforms are taken with respect to; every other parameter stays fixed and is never cloned or differentiated. None means every module parameter. An empty mapping skips the transforms (all False, “not probed”). The probed names are literal: a tied tensor probed under one name and fitted under another is refused. Names that are not the module’s own parameters (a Selection’s "fc.weight[idx]") are recorded as selected. None

Returns

Name Type Description
Capabilities The Capabilities: which transforms work, with the failure messages of those that don’t, the module order, the hooked Linear and Conv2d types, the event size, the tied names, and the probed and selected names.

Raises

Name Type Description
StructureError The likelihood is a mapping and the outputs or targets are not mappings with its keys; a leaf’s check or log_prob fails with an AttributeError or TypeError on outputs that are not a tensor (a dict reaching a tensor likelihood), and the error names the likelihood and the output type; or the model, the likelihood or a transform raises a StructureError (a likelihood whose shapes don’t fit the outputs, say).
ValueError The likelihood’s log_prob raises it on the order pass’s outputs (targets outside the support, say). It propagates with a note naming the likelihood and the output type.