Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions transformer_lens/model_bridge/transformer_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Dict,
Iterator,
List,
Expand Down Expand Up @@ -252,10 +251,54 @@ def __setstate__(self, state: dict[str, Any]) -> None:
super().__setstate__(state)
self.cfg._bind_bridge(self)

# boot_transformers / list_supported_models / check_model_support are
# attached by sources.transformers.__init__ (setattr on this class) so the
# source package owns its own boot entry point.
boot_transformers: ClassVar[Callable[..., "TransformerBridge"]]
# Source packages attach these entry points at runtime. Declaring their
# signatures only while type checking keeps the bridge -> sources import
# direction intact while exposing the public API to typed callers.
if TYPE_CHECKING:

@staticmethod
def boot_transformers(
model_name: str,
hf_config_overrides: Optional[dict] = None,
device: Optional[Union[str, torch.device]] = None,
dtype: torch.dtype = torch.float32,
tokenizer: Optional[PreTrainedTokenizerBase] = None,
load_weights: bool = True,
trust_remote_code: bool = False,
model_class: Optional[Any] = None,
hf_model: Optional[Any] = None,
n_ctx: Optional[int] = None,
revision: Optional[str] = None,
code_revision: Optional[str] = None,
checkpoint_index: Optional[int] = None,
checkpoint_value: Optional[int] = None,
device_map: Optional[Union[str, dict[str, Union[str, int]]]] = None,
n_devices: Optional[int] = None,
max_memory: Optional[dict[Union[str, int], Union[str, int]]] = None,
offload_folder: Optional[str] = None,
) -> "TransformerBridge":
...

@staticmethod
def boot_native(
config: Union[TransformerBridgeConfig, dict[str, Any]],
tokenizer: Optional[Any] = None,
device: Optional[Union[str, torch.device]] = None,
dtype: Optional[torch.dtype] = None,
model_name: str = "native",
) -> "TransformerBridge":
...

@staticmethod
def boot_tl_legacy(
model_name: str,
checkpoint_index: Optional[int] = None,
checkpoint_value: Optional[int] = None,
device: Optional[Union[str, torch.device]] = None,
dtype: torch.dtype = torch.float32,
tokenizer: Optional[Any] = None,
) -> "TransformerBridge":
...

@property
def original_model(self) -> nn.Module:
Expand Down
Loading