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_implementationAPI; exotic wrapped models can reject it, so failures fall back to writingconfig._attn_implementation(including nested multimodaltext_config).per_layer=Truealso stamps every submodule’sself_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.