transformer_lens.model_bridge.generalized_components.opaque_block module

Generic opaque block bridge for non-SSM, non-standard-transformer architectures.

class transformer_lens.model_bridge.generalized_components.opaque_block.OpaqueBlockBridge(name: str, config: Any | None = None, submodules: Dict[str, GeneralizedComponent] | None = None, hook_alias_overrides: Dict[str, str] | None = None)

Bases: GeneralizedComponent

Generic block bridge that delegates a full block forward unchanged.

Exposes hook_resid_pre / hook_resid_post (aliases of hook_in / hook_out) on the residual stream only — no assumptions are made about the block’s internal structure.

Use this for architectures whose block internals do not follow a standard SSM or transformer pre-norm flow, e.g.:

  • Post-residual (sandwich-norm) blocks like Raven / Huginn.

  • Attention-free recurrent blocks like RWKV-7.

  • Any custom block where hook_mixer_in / hook_mixer_out would be semantically wrong or structurally absent.

For SSM architectures (Mamba, Falcon-H1) use SSMBlockBridge, which extends this class and adds the hook_mixer_in / hook_mixer_out aliases pointing at mixer.hook_in / mixer.hook_out.

forward(*args: Any, **kwargs: Any) Any

Delegate to the HF block with hook_in/hook_out wrapped around it.

hook_aliases: Dict[str, str | List[str]] = {'hook_resid_post': 'hook_out', 'hook_resid_pre': 'hook_in'}
hook_out_is_single_residual_stream: bool = True
is_list_item: bool = True
real_components: Dict[str, tuple]
training: bool