transformer_lens.model_bridge.sources.tl_legacy module

Loader for legacy TransformerLens-format HF repos.

NeelNanda/, ArthurConmy/, and Baidicoot/* repos predate the HF model format: no model_type in config.json (AutoConfig refuses them), weights stored as *.pth state dicts in HookedTransformer property format (or older layouts converted below), and training checkpoints as checkpoints/*_<label>.pth files rather than revisions. This module derives a TransformerBridgeConfig from the repo’s TL-style config.json, fetches and normalizes the state dict, and loads it into a boot_native bridge via convert_tl_checkpoint.

The two legacy layout converters are ports of the HookedTransformer loaders (pretrained/weight_conversions/{neel_solu_old,mingpt}.py), rehomed here so this path survives the 4.0 deletion of the legacy loading stack.

transformer_lens.model_bridge.sources.tl_legacy.boot(model_name: str, checkpoint_index: int | None = None, checkpoint_value: int | None = None, device: str | device | None = None, dtype: dtype = torch.float32, tokenizer: Any | None = None) TransformerBridge

Build a bridge for a legacy TransformerLens-format HF repo.

checkpoint_index / checkpoint_value select a training checkpoint (checkpoints/*_<label>.pth); by default the final weights load. The resolved values are stamped on cfg.checkpoint_index / cfg.checkpoint_value, mirroring the legacy loader.

transformer_lens.model_bridge.sources.tl_legacy.derive_tl_legacy_config(repo_id: str) TransformerBridgeConfig

TransformerBridgeConfig from a legacy TL repo’s config.json.

transformer_lens.model_bridge.sources.tl_legacy.fetch_tl_legacy_state_dict(repo_id: str, cfg: TransformerBridgeConfig, checkpoint_value: int | None = None, dtype: dtype = torch.float32) dict

Download and normalize a legacy repo’s state dict to TL property format.