transformer_lens.model_bridge.sources.inspect.hooks module

Canonical hook names ↔ (layer, kind) for the Inspect HF provider.

Torch-free; shared by the provider (capture/intervene) and the driver (supported set, decode). Covers the d_model-shaped decoder-layer boundaries plus the head-split attention hooks (q/k/v/z, pattern) where the provider’s structural probe finds the projections; attn_scores, embed, and ln_final (fold-LN convention) stay non-fireable.

Names are TransformerBridge-native (blocks.{i}.hook_out, .attn.hook_out, …), not the HookedTransformer aliases. A bridge cache carries both with identical values, so parity vs boot_transformers still resolves.

Which boundaries are actually fireable is decided per-model by the provider’s structural self-check, not a hand-kept architecture list: it locates attn/mlp and probes whether the resid_pre + attn_out derivation holds, gating resid_mid otherwise; head-split kinds need separate q/k/v projections (q/k/v), a locatable out-projection (z), or eager attention (pattern). supported_hook_points(n_layers, kinds=...) filters to that set.

transformer_lens.model_bridge.sources.inspect.hooks.all_hook_points(n_layers: int) frozenset[str]

Every hook name the registry can serve (boundaries + head-split) — the universe a driver subtracts its supported set from to build non_fireable_hook_points.

transformer_lens.model_bridge.sources.inspect.hooks.name_from_wire_key(key: str) str | None

Inverse of wire_keyresolve: "<layer>:<kind>" → the canonical hook name, or None if the kind is unknown.

transformer_lens.model_bridge.sources.inspect.hooks.nonfireable_hook_points(n_layers: int) frozenset[str]

Hooks no provider configuration can fire (embed, ln_final, pre-softmax scores). Head-split q/k/v/z/pattern are conditionally fireable and belong here only when a model’s structural probe gates them — the driver handles that subtraction.

transformer_lens.model_bridge.sources.inspect.hooks.resolve(name: str) tuple[int, str] | None

Canonical hook name → (layer, kind), or None if not a fireable hook.

transformer_lens.model_bridge.sources.inspect.hooks.supported_hook_points(n_layers: int, kinds: Iterable[str] | None = None) frozenset[str]

Fireable hook names across all layers. kinds=None means all boundary kinds (head-split kinds are opt-in — a provider must detect and list them explicitly); pass the provider’s detected kinds to gate (e.g. drop resid_mid for parallel).

transformer_lens.model_bridge.sources.inspect.hooks.wire_key(layer: int, kind: str) str

Stable key for one captured boundary in the activation payload.