transformer_lens.model_bridge.sources.inspect.wire module

Serialization chokepoint for the Inspect activation wire format.

Activations ride in ModelOutput.metadata["activations"] as a flat {"<layer>:<kind>": {"data": <b64>, "dtype": str, "shape": [...]}} map (keys are hooks.wire_key()). For vllm-lens interop, decode also understands its documented nested {"residual_stream": {layer: ...}} shape (mapped to resid_post) — unverified against a live vllm-lens provider. Numpy-only (no torch) so both the torch-using provider and the torch-free driver import it; the single place to patch on format drift.

transformer_lens.model_bridge.sources.inspect.wire.decode_activations(metadata: Mapping[str, Any] | None, wire_keys: Iterable[str]) dict[str, ndarray]

Pull the requested <layer>:<kind> keys out of metadata["activations"], falling back to the nested residual_stream for resid_post. Missing keys are skipped — the caller decides.

transformer_lens.model_bridge.sources.inspect.wire.decode_array(entry: Any) ndarray

Inverse of encode_array(); passes an already-decoded ndarray through.

transformer_lens.model_bridge.sources.inspect.wire.encode_activations(captured: Mapping[str, ndarray]) dict[str, Any]

{wire_key: array} → the metadata["activations"] payload.

transformer_lens.model_bridge.sources.inspect.wire.encode_array(arr: ndarray) dict[str, Any]

numpy array → {"data": b64, "dtype": str, "shape": [...]}.