🤖 AI Summary
Existing interpretability tools face a trade-off: custom implementations (e.g., TransformerLens) offer unified interfaces but require manual architecture-specific adaptation, risking numerical fidelity loss; conversely, direct Hugging Face integration (e.g., NNsight) preserves model fidelity yet lacks cross-model standardization. This work introduces *nnterp*, a lightweight framework that—without compromising fidelity—unifies mechanistic interpretability analysis across 50+ Transformer variants for the first time. Its core innovation lies in wrapping NNsight while incorporating TransformerLens-style APIs, enabling standardized access to internal states (e.g., attention probabilities) via automatic module renaming, architecture-agnostic hook injection, and built-in validation. nnterp supports 16 architectural families, integrates established methods (e.g., Logit Lens, PatchScope), and provides a local compatibility verification suite. It significantly enhances plug-and-play usability and cross-model transfer efficiency of interpretability techniques.
📝 Abstract
Mechanistic interpretability research requires reliable tools for analyzing transformer internals across diverse architectures. Current approaches face a fundamental tradeoff: custom implementations like TransformerLens ensure consistent interfaces but require coding a manual adaptation for each architecture, introducing numerical mismatch with the original models, while direct HuggingFace access through NNsight preserves exact behavior but lacks standardization across models. To bridge this gap, we develop nnterp, a lightweight wrapper around NNsight that provides a unified interface for transformer analysis while preserving original HuggingFace implementations. Through automatic module renaming and comprehensive validation testing, nnterp enables researchers to write intervention code once and deploy it across 50+ model variants spanning 16 architecture families. The library includes built-in implementations of common interpretability methods (logit lens, patchscope, activation steering) and provides direct access to attention probabilities for models that support it. By packaging validation tests with the library, researchers can verify compatibility with custom models locally. nnterp bridges the gap between correctness and usability in mechanistic interpretability tooling.