transformer_lens.model_bridge.sources.transformers_driver module

HuggingFace transformers Driver.

class transformer_lens.model_bridge.sources.transformers_driver.TransformersDriver(model: Module, adapter: Any, tokenizer: Any)

Bases: DriverBase

Wraps an HF nn.Module. PyTorch hooks fire via module replacement during the real forward; this driver just runs the engine and threads the native output back.

forward(input_ids: TensorLike | None = None, *, capture: tuple[str, ...] = (), intervene: Mapping[str, Callable[[TensorLike], TensorLike] | Mapping[str, Any]] | None = None, max_new_tokens: int = 1, return_logits: bool = True, **kwargs: Any) ForwardResult
named_parameters(prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) Iterator[tuple[str, Tensor]]
parameters() Iterator[Tensor]
set_underlying_model(value: Module) None

Used by weight-processing paths that move the model to a different device. Non-torch drivers don’t implement this.

property underlying_model: Module

Escape hatch for code that needs the raw HF module. Driver-specific.