transformer_lens.utilities.attn_implementation module

attn_implementation.

Shared helper for forcing eager attention on a loaded HuggingFace model.

transformer_lens.utilities.attn_implementation.force_eager_attention(model: Any, *, per_layer: bool = False) None

Switch a pre-loaded model to eager attention so attention hooks can fire.

Prefers the public set_attn_implementation API; exotic wrapped models can reject it, so failures fall back to writing config._attn_implementation (including nested multimodal text_config). per_layer=True also stamps every submodule’s self_attn.config — some models keep per-layer config copies that the top-level write never reaches.

Best-effort by design: never raises, silently no-ops on objects exposing neither the public API nor a config.