Understand the Architecture Adapter concept
mainAn Architecture Adapter is a Python class that extends ArchitectureAdapter. It is used by the TransformerBridge system to translate HuggingFace (HF) models into TransformerLens models. An adapter provides three essential pieces of information:
- Config attributes: Set on
self.cfgduring__init__(e.g., normalization type, positional embedding type, GQA parameters). - Component mapping: A dictionary
self.component_mappingthat maps TransformerLens canonical names (likeembed,blocks,attn.q) toGeneralizedComponentBridge instances pointing to specific HF module paths. - Weight processing conversions: A dictionary
self.weight_processing_conversionscontaining tensor-reshape rules to translate HF weight layouts to TransformerLens layouts during loading.
Once an adapter is registered, you can use boot_transformers("<your-model>") to obtain a fully hooked TransformerLens model with weights loaded from HuggingFace.