transformer_lens.utilities.aliases module¶
Utilities for handling hook aliases in the bridge system.
- transformer_lens.utilities.aliases.collect_aliases_recursive(module: Any, prefix: str = '') Dict[str, str]¶
Recursively collect all aliases from a module and its children. This unified function collects both: - Named hook aliases: old_hook_name -> new_hook_name - Cache aliases: component_name -> component_name.hook_out (from empty string keys) :param module: The module to collect aliases from :param prefix: Path prefix for building full names
- Returns:
Dictionary mapping all alias names to target names
- transformer_lens.utilities.aliases.resolve_alias(target_object: Any, requested_name: str, aliases: Dict[str, str] | Dict[str, str | List[str]]) Any | None¶
Resolve a hook alias to the actual hook object.
- Parameters:
target_object – The object to get the resolved attribute from
requested_name – The name being requested (potentially an alias)
aliases – Dictionary mapping alias names to target names
- Returns:
The resolved hook object if alias found, None otherwise