Skip to main content

core.Capabilities

core.Capabilities(
    vjp=False,
    vjp_twice=False,
    jvp=False,
    vmap=False,
    hooked_types=dict[str, type[nn.Module]](),
    module_order=(),
    tied=dict[str, tuple[str, ...]](),
    event_size=None,
    failures=dict[str, str](),
    probed=None,
    selected=frozenset(),
)

What the probe found. Each capability is independent of the others.

Parameters

Name Type Description Default
vjp bool torch.func.vjp works. False
vjp_twice bool The VJP of a VJP works and agrees with the VJP. Fails on kernels without a double backward (PyTorch’s fused attention) or a custom autograd.Function that has none. False
jvp bool torch.func.jvp works. False
vmap bool torch.func.vmap works. False
hooked_types Mapping[str, type[nn.Module]] Module type of each Linear and Conv2d module whose forward hook fired in the probe. dict[str, type[nn.Module]]()
module_order tuple[str, …] Parameterized modules: the root module first, as "<root>" (ROOT_BLOCK), when it owns parameters, then the others in the order their forward finished. ()
tied Mapping[str, tuple[str, …]] Each name of a parameter tensor that has several names (tied weights), mapped to all of them. dict[str, tuple[str, ...]]()
event_size int | None Output entries per example (summed over output leaves). None when not probed. None
failures Mapping[str, str] Each failed capability mapped to the failing op. dict[str, str]()
probed frozenset[str] | None Parameter names the vjp, jvp and vmap checks covered. None means every parameter. The names are literal: a tied tensor probed under one name and fitted under another is refused. None
selected frozenset[str] Probed names that end in "[idx]": the "fc.weight[idx]" parameters of a Selection. frozenset()

Attributes

Name Description
hooked Names of the modules in hooked_types.
selected_blocks Block names (module paths, or ROOT_BLOCK) of the selected parameters.

Methods

Name Description
check Check that these capabilities meet req.
unprobed No capabilities, each marked not probed: what a fit without caps assumes.
was_probed Whether a capability was tried.

check

core.Capabilities.check(req, what, blocks=None)

Check that these capabilities meet req.

Hook-based methods are refused first, with or without blocks, when parameters were selected: hooks see a module’s own parameters, not some of their entries.

Parameters

Name Type Description Default
req Requirements What the method needs. required
what str Name of the method, used in the error message. required
blocks Iterable[str] | None Default-layout block names, i.e. module paths. With req.hooks, each block’s module must have been reached by hooks and be of a required type. None skips that check. None

Raises

Name Type Description
CapabilityError Naming what and the missing capabilities, and whether they were not probed or failed. Also raised when req.hooks is set and parameters were selected, or a block in blocks was not reached by hooks or is not of a required type.

unprobed

core.Capabilities.unprobed()

No capabilities, each marked not probed: what a fit without caps assumes.

Returns

Name Type Description
Capabilities Capabilities whose failures map each of TRANSFORMS to NOT_PROBED.

was_probed

core.Capabilities.was_probed(name, /)

Whether a capability was tried.

Parameters

Name Type Description Default
name str Capability name, e.g. "vjp". required

Returns

Name Type Description
bool False when failures marks name as NOT_PROBED, as unprobed() and a probe with subset={} do.