AutoModel
Last updated
Last updated
( *args**kwargs )
This is a generic model class that will be instantiated as one of the base model classes of the library when created with the class method or the class method.
This class cannot be instantiated directly using __init__()
(throws an error).
from_config
( **kwargs )
Parameters
config () — The model class to instantiate is selected based on the configuration class:
configuration class: (Audio Spectrogram Transformer model)
configuration class: (ALBERT model)
configuration class: (ALIGN model)
configuration class: (AltCLIP model)
configuration class: (Autoformer model)
configuration class: (Bark model)
configuration class: (BART model)
configuration class: (BEiT model)
configuration class: (BERT model)
configuration class: (Bert Generation model)
configuration class: (BigBird model)
configuration class: (BigBird-Pegasus model)
configuration class: (BioGpt model)
configuration class: (BiT model)
configuration class: (Blenderbot model)
configuration class: (BlenderbotSmall model)
configuration class: (BLIP-2 model)
configuration class: (BLIP model)
configuration class: (BLOOM model)
configuration class: (BridgeTower model)
configuration class: (BROS model)
configuration class: (CLIP model)
configuration class: (CLIPSeg model)
configuration class: (CTRL model)
configuration class: (CamemBERT model)
configuration class: (CANINE model)
configuration class: (Chinese-CLIP model)
configuration class: (CLAP model)
configuration class: (CodeGen model)
configuration class: (Conditional DETR model)
configuration class: (ConvBERT model)
configuration class: (ConvNeXT model)
configuration class: (ConvNeXTV2 model)
configuration class: (CPM-Ant model)
configuration class: (CvT model)
configuration class: (DPR model)
configuration class: (DPT model)
configuration class: (Data2VecAudio model)
configuration class: (Data2VecText model)
configuration class: (Data2VecVision model)
configuration class: (DeBERTa model)
configuration class: (DeBERTa-v2 model)
configuration class: (Decision Transformer model)
configuration class: (Deformable DETR model)
configuration class: (DeiT model)
configuration class: (DETA model)
configuration class: (DETR model)
configuration class: (DiNAT model)
configuration class: (DINOv2 model)
configuration class: (DistilBERT model)
configuration class: (DonutSwin model)
configuration class: (EfficientFormer model)
configuration class: (EfficientNet model)
configuration class: (ELECTRA model)
configuration class: (EnCodec model)
configuration class: (ERNIE model)
configuration class: (ErnieM model)
configuration class: (ESM model)
configuration class: (FNet model)
configuration class: (FairSeq Machine-Translation model)
configuration class: (Falcon model)
configuration class: (FlauBERT model)
configuration class: (FLAVA model)
configuration class: (FocalNet model)
configuration class: or (Funnel Transformer model)
configuration class: (GLPN model)
configuration class: (OpenAI GPT-2 model)
configuration class: (GPTBigCode model)
configuration class: (GPT-J model)
configuration class: (GPT Neo model)
configuration class: (GPT NeoX model)
configuration class: (GPT NeoX Japanese model)
configuration class: (GPTSAN-japanese model)
configuration class: (GIT model)
configuration class: (Graphormer model)
configuration class: (GroupViT model)
configuration class: (Hubert model)
configuration class: (I-BERT model)
configuration class: (IDEFICS model)
configuration class: (ImageGPT model)
configuration class: (Informer model)
configuration class: (Jukebox model)
configuration class: (LED model)
configuration class: (LayoutLM model)
configuration class: (LayoutLMv2 model)
configuration class: (LayoutLMv3 model)
configuration class: (LeViT model)
configuration class: (LiLT model)
configuration class: (LLaMA model)
configuration class: (LongT5 model)
configuration class: (Longformer model)
configuration class: (LUKE model)
configuration class: (LXMERT model)
configuration class: (M2M100 model)
configuration class: (mBART model)
configuration class: (M-CTC-T model)
configuration class: (MPNet model)
configuration class: (MT5 model)
configuration class: (Marian model)
configuration class: (MarkupLM model)
configuration class: (Mask2Former model)
configuration class: (MaskFormer model)
MaskFormerSwinConfig
configuration class: MaskFormerSwinModel
(MaskFormerSwin model)
configuration class: (MEGA model)
configuration class: (Megatron-BERT model)
configuration class: (MGP-STR model)
configuration class: (Mistral model)
configuration class: (MobileBERT model)
configuration class: (MobileNetV1 model)
configuration class: (MobileNetV2 model)
configuration class: (MobileViT model)
configuration class: (MobileViTV2 model)
configuration class: (MPT model)
configuration class: (MRA model)
configuration class: (MVP model)
configuration class: (NAT model)
configuration class: (Nezha model)
configuration class: (NLLB-MOE model)
configuration class: (Nyströmformer model)
configuration class: (OPT model)
configuration class: (OneFormer model)
configuration class: (OpenAI GPT model)
configuration class: (OpenLlama model)
configuration class: (OWL-ViT model)
configuration class: (PLBart model)
configuration class: (Pegasus model)
configuration class: (PEGASUS-X model)
configuration class: (Perceiver model)
configuration class: (Persimmon model)
configuration class: (PoolFormer model)
configuration class: (ProphetNet model)
configuration class: (PVT model)
configuration class: (QDQBert model)
configuration class: (Reformer model)
configuration class: (RegNet model)
configuration class: (RemBERT model)
configuration class: (ResNet model)
configuration class: (RetriBERT model)
configuration class: (RoCBert model)
configuration class: (RoFormer model)
configuration class: (RoBERTa model)
configuration class: (RoBERTa-PreLayerNorm model)
configuration class: (RWKV model)
configuration class: (SEW model)
configuration class: (SEW-D model)
configuration class: (SAM model)
configuration class: (SegFormer model)
configuration class: (Speech2Text model)
configuration class: (SpeechT5 model)
configuration class: (Splinter model)
configuration class: (SqueezeBERT model)
configuration class: (SwiftFormer model)
configuration class: (Swin2SR model)
configuration class: (Swin Transformer model)
configuration class: (Swin Transformer V2 model)
configuration class: (SwitchTransformers model)
configuration class: (T5 model)
configuration class: (Table Transformer model)
configuration class: (TAPAS model)
configuration class: (Time Series Transformer model)
configuration class: (TimeSformer model)
TimmBackboneConfig
configuration class: TimmBackbone
(TimmBackbone model)
configuration class: (Trajectory Transformer model)
configuration class: (Transformer-XL model)
configuration class: (TVLT model)
configuration class: (UMT5 model)
configuration class: (UniSpeech model)
configuration class: (UniSpeechSat model)
configuration class: (VAN model)
configuration class: (ViT model)
configuration class: (ViT Hybrid model)
configuration class: (ViTMAE model)
configuration class: (ViTMSN model)
configuration class: (VideoMAE model)
configuration class: (ViLT model)
configuration class: (VisionTextDualEncoder model)
configuration class: (VisualBERT model)
configuration class: (VitDet model)
configuration class: (VITS model)
configuration class: (ViViT model)
configuration class: (Wav2Vec2 model)
configuration class: (Wav2Vec2-Conformer model)
configuration class: (WavLM model)
configuration class: (Whisper model)
configuration class: (X-CLIP model)
configuration class: (XGLM model)
configuration class: (XLM model)
configuration class: (XLM-ProphetNet model)
configuration class: (XLM-RoBERTa model)
configuration class: (XLM-RoBERTa-XL model)
configuration class: (XLNet model)
configuration class: (X-MOD model)
configuration class: (YOLOS model)
configuration class: (YOSO model)
Instantiates one of the base model classes of the library from a configuration.
Examples:
Copied
from_pretrained
( *model_args**kwargs )
Parameters
pretrained_model_name_or_path (str
or os.PathLike
) — Can be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like bert-base-uncased
, or namespaced under a user or organization name, like dbmdz/bert-base-german-cased
.
A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) — Will be passed along to the underlying model __init__()
method.
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model is loaded by supplying a local directory as pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.
cache_dir (str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.
from_tf (bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument).
force_download (bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.
resume_download (bool
, optional, defaults to False
) — Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.
proxies (Dict[str, str]
, optional) — A dictionary of proxy servers to use by protocol or endpoint, e.g., {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}
. The proxies are used on each request.
output_loading_info(bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.
local_files_only(bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model).
revision (str
, optional, defaults to "main"
) — The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so revision
can be any identifier allowed by git.
trust_remote_code (bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine.
code_revision (str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so revision
can be any identifier allowed by git.
kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
If a configuration is provided with config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)
Instantiate one of the base model classes of the library from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
maskformer-swin — MaskFormerSwinModel
(MaskFormerSwin model)
timm_backbone — TimmBackbone
(TimmBackbone model)
The model is set in evaluation mode by default using model.eval()
(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode with model.train()
Examples:
Copied
Note: Loading a model from its configuration file does not load the model weights. It only affects the model’s configuration. Use to load the model weights.
A path to a directory containing model weights saved using , e.g., ./my_model_directory/
.
config (, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model was saved using and is reloaded by supplying the save directory.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using and is not a simpler option.
If a configuration is not provided, kwargs
will be first passed to the configuration class initialization function (). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.
albert — (ALBERT model)
align — (ALIGN model)
altclip — (AltCLIP model)
audio-spectrogram-transformer — (Audio Spectrogram Transformer model)
autoformer — (Autoformer model)
bark — (Bark model)
bart — (BART model)
beit — (BEiT model)
bert — (BERT model)
bert-generation — (Bert Generation model)
big_bird — (BigBird model)
bigbird_pegasus — (BigBird-Pegasus model)
biogpt — (BioGpt model)
bit — (BiT model)
blenderbot — (Blenderbot model)
blenderbot-small — (BlenderbotSmall model)
blip — (BLIP model)
blip-2 — (BLIP-2 model)
bloom — (BLOOM model)
bridgetower — (BridgeTower model)
bros — (BROS model)
camembert — (CamemBERT model)
canine — (CANINE model)
chinese_clip — (Chinese-CLIP model)
clap — (CLAP model)
clip — (CLIP model)
clipseg — (CLIPSeg model)
code_llama — (CodeLlama model)
codegen — (CodeGen model)
conditional_detr — (Conditional DETR model)
convbert — (ConvBERT model)
convnext — (ConvNeXT model)
convnextv2 — (ConvNeXTV2 model)
cpmant — (CPM-Ant model)
ctrl — (CTRL model)
cvt — (CvT model)
data2vec-audio — (Data2VecAudio model)
data2vec-text — (Data2VecText model)
data2vec-vision — (Data2VecVision model)
deberta — (DeBERTa model)
deberta-v2 — (DeBERTa-v2 model)
decision_transformer — (Decision Transformer model)
deformable_detr — (Deformable DETR model)
deit — (DeiT model)
deta — (DETA model)
detr — (DETR model)
dinat — (DiNAT model)
dinov2 — (DINOv2 model)
distilbert — (DistilBERT model)
donut-swin — (DonutSwin model)
dpr — (DPR model)
dpt — (DPT model)
efficientformer — (EfficientFormer model)
efficientnet — (EfficientNet model)
electra — (ELECTRA model)
encodec — (EnCodec model)
ernie — (ERNIE model)
ernie_m — (ErnieM model)
esm — (ESM model)
falcon — (Falcon model)
flaubert — (FlauBERT model)
flava — (FLAVA model)
fnet — (FNet model)
focalnet — (FocalNet model)
fsmt — (FairSeq Machine-Translation model)
funnel — or (Funnel Transformer model)
git — (GIT model)
glpn — (GLPN model)
gpt-sw3 — (GPT-Sw3 model)
gpt2 — (OpenAI GPT-2 model)
gpt_bigcode — (GPTBigCode model)
gpt_neo — (GPT Neo model)
gpt_neox — (GPT NeoX model)
gpt_neox_japanese — (GPT NeoX Japanese model)
gptj — (GPT-J model)
gptsan-japanese — (GPTSAN-japanese model)
graphormer — (Graphormer model)
groupvit — (GroupViT model)
hubert — (Hubert model)
ibert — (I-BERT model)
idefics — (IDEFICS model)
imagegpt — (ImageGPT model)
informer — (Informer model)
jukebox — (Jukebox model)
layoutlm — (LayoutLM model)
layoutlmv2 — (LayoutLMv2 model)
layoutlmv3 — (LayoutLMv3 model)
led — (LED model)
levit — (LeViT model)
lilt — (LiLT model)
llama — (LLaMA model)
longformer — (Longformer model)
longt5 — (LongT5 model)
luke — (LUKE model)
lxmert — (LXMERT model)
m2m_100 — (M2M100 model)
marian — (Marian model)
markuplm — (MarkupLM model)
mask2former — (Mask2Former model)
maskformer — (MaskFormer model)
mbart — (mBART model)
mctct — (M-CTC-T model)
mega — (MEGA model)
megatron-bert — (Megatron-BERT model)
mgp-str — (MGP-STR model)
mistral — (Mistral model)
mobilebert — (MobileBERT model)
mobilenet_v1 — (MobileNetV1 model)
mobilenet_v2 — (MobileNetV2 model)
mobilevit — (MobileViT model)
mobilevitv2 — (MobileViTV2 model)
mpnet — (MPNet model)
mpt — (MPT model)
mra — (MRA model)
mt5 — (MT5 model)
mvp — (MVP model)
nat — (NAT model)
nezha — (Nezha model)
nllb-moe — (NLLB-MOE model)
nystromformer — (Nyströmformer model)
oneformer — (OneFormer model)
open-llama — (OpenLlama model)
openai-gpt — (OpenAI GPT model)
opt — (OPT model)
owlvit — (OWL-ViT model)
pegasus — (Pegasus model)
pegasus_x — (PEGASUS-X model)
perceiver — (Perceiver model)
persimmon — (Persimmon model)
plbart — (PLBart model)
poolformer — (PoolFormer model)
prophetnet — (ProphetNet model)
pvt — (PVT model)
qdqbert — (QDQBert model)
reformer — (Reformer model)
regnet — (RegNet model)
rembert — (RemBERT model)
resnet — (ResNet model)
retribert — (RetriBERT model)
roberta — (RoBERTa model)
roberta-prelayernorm — (RoBERTa-PreLayerNorm model)
roc_bert — (RoCBert model)
roformer — (RoFormer model)
rwkv — (RWKV model)
sam — (SAM model)
segformer — (SegFormer model)
sew — (SEW model)
sew-d — (SEW-D model)
speech_to_text — (Speech2Text model)
speecht5 — (SpeechT5 model)
splinter — (Splinter model)
squeezebert — (SqueezeBERT model)
swiftformer — (SwiftFormer model)
swin — (Swin Transformer model)
swin2sr — (Swin2SR model)
swinv2 — (Swin Transformer V2 model)
switch_transformers — (SwitchTransformers model)
t5 — (T5 model)
table-transformer — (Table Transformer model)
tapas — (TAPAS model)
time_series_transformer — (Time Series Transformer model)
timesformer — (TimeSformer model)
trajectory_transformer — (Trajectory Transformer model)
transfo-xl — (Transformer-XL model)
tvlt — (TVLT model)
umt5 — (UMT5 model)
unispeech — (UniSpeech model)
unispeech-sat — (UniSpeechSat model)
van — (VAN model)
videomae — (VideoMAE model)
vilt — (ViLT model)
vision-text-dual-encoder — (VisionTextDualEncoder model)
visual_bert — (VisualBERT model)
vit — (ViT model)
vit_hybrid — (ViT Hybrid model)
vit_mae — (ViTMAE model)
vit_msn — (ViTMSN model)
vitdet — (VitDet model)
vits — (VITS model)
vivit — (ViViT model)
wav2vec2 — (Wav2Vec2 model)
wav2vec2-conformer — (Wav2Vec2-Conformer model)
wavlm — (WavLM model)
whisper — (Whisper model)
xclip — (X-CLIP model)
xglm — (XGLM model)
xlm — (XLM model)
xlm-prophetnet — (XLM-ProphetNet model)
xlm-roberta — (XLM-RoBERTa model)
xlm-roberta-xl — (XLM-RoBERTa-XL model)
xlnet — (XLNet model)
xmod — (X-MOD model)
yolos — (YOLOS model)
yoso — (YOSO model)