Skip to content

transformers

transformers

TransformersModel

TransformersModel(*args, config_model: Type[PretrainedConfig] = None, automodel: Type[AutoModel] = AutoModel, **kwargs)

Bases: HuggingFaceModel

NNsight wrapper for HuggingFace Transformers models.

Adds AutoConfig / AutoModel support on top of :class:HuggingFaceModel. Handles config loading, meta-tensor initialization via from_config, and full weight loading via from_pretrained.

PARAMETER DESCRIPTION
*args

Forwarded to :class:HuggingFaceModel. The first positional argument is typically a repo ID string or a pre-loaded torch.nn.Module.

DEFAULT: ()

config_model

An explicit HuggingFace config instance to use instead of loading one from the repo. Defaults to None (auto-loaded).

TYPE: Optional[Type[PretrainedConfig]] DEFAULT: None

automodel

The AutoModel class to use for loading (e.g. AutoModelForCausalLM). Defaults to AutoModel.

TYPE: Type[AutoModel] DEFAULT: AutoModel

**kwargs

Forwarded to from_pretrained / from_config.

DEFAULT: {}

ATTRIBUTE DESCRIPTION
config

The model's HuggingFace configuration.

TYPE: PretrainedConfig

automodel

The AutoModel class used for loading.

TYPE: Type[AutoModel]

config instance-attribute

config: PretrainedConfig = config_model

automodel instance-attribute

automodel = automodel if not isinstance(automodel, str) else getattr(modeling_auto, automodel)