> For the complete documentation index, see [llms.txt](https://boinc-ai.gitbook.io/transformers/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boinc-ai.gitbook.io/transformers/api/main-classes/auto-classes/generic-pretraining-classes/automodelforpretraining.md).

# AutoModelForPreTraining

#### AutoModelForPreTraining

#### class transformers.AutoModelForPreTraining

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/auto/modeling_auto.py#L1231)

( \*args\*\*kwargs )

This is a generic model class that will be instantiated as one of the model classes of the library (with a pretraining head) when created with the [from\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained) class method or the [from\_config()](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_config) class method.

This class cannot be instantiated directly using `__init__()` (throws an error).

**from\_config**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/auto/auto_factory.py#L417)

( \*\*kwargs )

Parameters

* **config** ([PretrainedConfig](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/configuration#transformers.PretrainedConfig)) — The model class to instantiate is selected based on the configuration class:
  * [AlbertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/albert#transformers.AlbertConfig) configuration class: [AlbertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/albert#transformers.AlbertForPreTraining) (ALBERT model)
  * [BartConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/bart#transformers.BartConfig) configuration class: [BartForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/bart#transformers.BartForConditionalGeneration) (BART model)
  * [BertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/bert#transformers.BertConfig) configuration class: [BertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/bert#transformers.BertForPreTraining) (BERT model)
  * [BigBirdConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/big_bird#transformers.BigBirdConfig) configuration class: [BigBirdForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/big_bird#transformers.BigBirdForPreTraining) (BigBird model)
  * [BloomConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/bloom#transformers.BloomConfig) configuration class: [BloomForCausalLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/bloom#transformers.BloomForCausalLM) (BLOOM model)
  * [CTRLConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/ctrl#transformers.CTRLConfig) configuration class: [CTRLLMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/ctrl#transformers.CTRLLMHeadModel) (CTRL model)
  * [CamembertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/camembert#transformers.CamembertConfig) configuration class: [CamembertForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/camembert#transformers.CamembertForMaskedLM) (CamemBERT model)
  * [Data2VecTextConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/data2vec#transformers.Data2VecTextConfig) configuration class: [Data2VecTextForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/data2vec#transformers.Data2VecTextForMaskedLM) (Data2VecText model)
  * [DebertaConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/deberta#transformers.DebertaConfig) configuration class: [DebertaForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/deberta#transformers.DebertaForMaskedLM) (DeBERTa model)
  * [DebertaV2Config](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/deberta-v2#transformers.DebertaV2Config) configuration class: [DebertaV2ForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/deberta-v2#transformers.DebertaV2ForMaskedLM) (DeBERTa-v2 model)
  * [DistilBertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/distilbert#transformers.DistilBertConfig) configuration class: [DistilBertForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/distilbert#transformers.DistilBertForMaskedLM) (DistilBERT model)
  * [ElectraConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/electra#transformers.ElectraConfig) configuration class: [ElectraForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/electra#transformers.ElectraForPreTraining) (ELECTRA model)
  * [ErnieConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/ernie#transformers.ErnieConfig) configuration class: [ErnieForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/ernie#transformers.ErnieForPreTraining) (ERNIE model)
  * [FNetConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/fnet#transformers.FNetConfig) configuration class: [FNetForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/fnet#transformers.FNetForPreTraining) (FNet model)
  * [FSMTConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/fsmt#transformers.FSMTConfig) configuration class: [FSMTForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/fsmt#transformers.FSMTForConditionalGeneration) (FairSeq Machine-Translation model)
  * [FlaubertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/flaubert#transformers.FlaubertConfig) configuration class: [FlaubertWithLMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/flaubert#transformers.FlaubertWithLMHeadModel) (FlauBERT model)
  * [FlavaConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/flava#transformers.FlavaConfig) configuration class: [FlavaForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/flava#transformers.FlavaForPreTraining) (FLAVA model)
  * [FunnelConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/funnel#transformers.FunnelConfig) configuration class: [FunnelForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/funnel#transformers.FunnelForPreTraining) (Funnel Transformer model)
  * [GPT2Config](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/gpt2#transformers.GPT2Config) configuration class: [GPT2LMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/gpt2#transformers.GPT2LMHeadModel) (OpenAI GPT-2 model)
  * [GPTBigCodeConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/gpt_bigcode#transformers.GPTBigCodeConfig) configuration class: [GPTBigCodeForCausalLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/gpt_bigcode#transformers.GPTBigCodeForCausalLM) (GPTBigCode model)
  * [GPTSanJapaneseConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/gptsan-japanese#transformers.GPTSanJapaneseConfig) configuration class: [GPTSanJapaneseForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/gptsan-japanese#transformers.GPTSanJapaneseForConditionalGeneration) (GPTSAN-japanese model)
  * [IBertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/ibert#transformers.IBertConfig) configuration class: [IBertForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/ibert#transformers.IBertForMaskedLM) (I-BERT model)
  * [IdeficsConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/idefics#transformers.IdeficsConfig) configuration class: [IdeficsForVisionText2Text](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/idefics#transformers.IdeficsForVisionText2Text) (IDEFICS model)
  * [LayoutLMConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/layoutlm#transformers.LayoutLMConfig) configuration class: [LayoutLMForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/layoutlm#transformers.LayoutLMForMaskedLM) (LayoutLM model)
  * [LongformerConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/longformer#transformers.LongformerConfig) configuration class: [LongformerForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/longformer#transformers.LongformerForMaskedLM) (Longformer model)
  * [LukeConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/luke#transformers.LukeConfig) configuration class: [LukeForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/luke#transformers.LukeForMaskedLM) (LUKE model)
  * [LxmertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/lxmert#transformers.LxmertConfig) configuration class: [LxmertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/lxmert#transformers.LxmertForPreTraining) (LXMERT model)
  * [MPNetConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mpnet#transformers.MPNetConfig) configuration class: [MPNetForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mpnet#transformers.MPNetForMaskedLM) (MPNet model)
  * [MegaConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mega#transformers.MegaConfig) configuration class: [MegaForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mega#transformers.MegaForMaskedLM) (MEGA model)
  * [MegatronBertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/megatron-bert#transformers.MegatronBertConfig) configuration class: [MegatronBertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/megatron-bert#transformers.MegatronBertForPreTraining) (Megatron-BERT model)
  * [MobileBertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mobilebert#transformers.MobileBertConfig) configuration class: [MobileBertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mobilebert#transformers.MobileBertForPreTraining) (MobileBERT model)
  * [MptConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mpt#transformers.MptConfig) configuration class: [MptForCausalLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mpt#transformers.MptForCausalLM) (MPT model)
  * [MraConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mra#transformers.MraConfig) configuration class: [MraForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mra#transformers.MraForMaskedLM) (MRA model)
  * [MvpConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mvp#transformers.MvpConfig) configuration class: [MvpForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mvp#transformers.MvpForConditionalGeneration) (MVP model)
  * [NezhaConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nezha#transformers.NezhaConfig) configuration class: [NezhaForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nezha#transformers.NezhaForPreTraining) (Nezha model)
  * [NllbMoeConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nllb-moe#transformers.NllbMoeConfig) configuration class: [NllbMoeForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nllb-moe#transformers.NllbMoeForConditionalGeneration) (NLLB-MOE model)
  * [OpenAIGPTConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/openai-gpt#transformers.OpenAIGPTConfig) configuration class: [OpenAIGPTLMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/openai-gpt#transformers.OpenAIGPTLMHeadModel) (OpenAI GPT model)
  * [RetriBertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/retribert#transformers.RetriBertConfig) configuration class: [RetriBertModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/retribert#transformers.RetriBertModel) (RetriBERT model)
  * [RoCBertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/roc_bert#transformers.RoCBertConfig) configuration class: [RoCBertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/roc_bert#transformers.RoCBertForPreTraining) (RoCBert model)
  * [RobertaConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/roberta#transformers.RobertaConfig) configuration class: [RobertaForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/roberta#transformers.RobertaForMaskedLM) (RoBERTa model)
  * [RobertaPreLayerNormConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/roberta-prelayernorm#transformers.RobertaPreLayerNormConfig) configuration class: [RobertaPreLayerNormForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/roberta-prelayernorm#transformers.RobertaPreLayerNormForMaskedLM) (RoBERTa-PreLayerNorm model)
  * [RwkvConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/rwkv#transformers.RwkvConfig) configuration class: [RwkvForCausalLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/rwkv#transformers.RwkvForCausalLM) (RWKV model)
  * [SplinterConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/splinter#transformers.SplinterConfig) configuration class: [SplinterForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/splinter#transformers.SplinterForPreTraining) (Splinter model)
  * [SqueezeBertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/squeezebert#transformers.SqueezeBertConfig) configuration class: [SqueezeBertForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/squeezebert#transformers.SqueezeBertForMaskedLM) (SqueezeBERT model)
  * [SwitchTransformersConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/switch_transformers#transformers.SwitchTransformersConfig) configuration class: [SwitchTransformersForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/switch_transformers#transformers.SwitchTransformersForConditionalGeneration) (SwitchTransformers model)
  * [T5Config](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/t5#transformers.T5Config) configuration class: [T5ForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/t5#transformers.T5ForConditionalGeneration) (T5 model)
  * [TapasConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/tapas#transformers.TapasConfig) configuration class: [TapasForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/tapas#transformers.TapasForMaskedLM) (TAPAS model)
  * [TransfoXLConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/transfo-xl#transformers.TransfoXLConfig) configuration class: [TransfoXLLMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/transfo-xl#transformers.TransfoXLLMHeadModel) (Transformer-XL model)
  * [TvltConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/tvlt#transformers.TvltConfig) configuration class: [TvltForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/tvlt#transformers.TvltForPreTraining) (TVLT model)
  * [UniSpeechConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/unispeech#transformers.UniSpeechConfig) configuration class: [UniSpeechForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/unispeech#transformers.UniSpeechForPreTraining) (UniSpeech model)
  * [UniSpeechSatConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/unispeech-sat#transformers.UniSpeechSatConfig) configuration class: [UniSpeechSatForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/unispeech-sat#transformers.UniSpeechSatForPreTraining) (UniSpeechSat model)
  * [ViTMAEConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/vit_mae#transformers.ViTMAEConfig) configuration class: [ViTMAEForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/vit_mae#transformers.ViTMAEForPreTraining) (ViTMAE model)
  * [VideoMAEConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/videomae#transformers.VideoMAEConfig) configuration class: [VideoMAEForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/videomae#transformers.VideoMAEForPreTraining) (VideoMAE model)
  * [VisualBertConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/visual_bert#transformers.VisualBertConfig) configuration class: [VisualBertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/visual_bert#transformers.VisualBertForPreTraining) (VisualBERT model)
  * [Wav2Vec2Config](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/wav2vec2#transformers.Wav2Vec2Config) configuration class: [Wav2Vec2ForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/wav2vec2#transformers.Wav2Vec2ForPreTraining) (Wav2Vec2 model)
  * [Wav2Vec2ConformerConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/wav2vec2-conformer#transformers.Wav2Vec2ConformerConfig) configuration class: [Wav2Vec2ConformerForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/wav2vec2-conformer#transformers.Wav2Vec2ConformerForPreTraining) (Wav2Vec2-Conformer model)
  * [XLMConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xlm#transformers.XLMConfig) configuration class: [XLMWithLMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xlm#transformers.XLMWithLMHeadModel) (XLM model)
  * [XLMRobertaConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xlm-roberta#transformers.XLMRobertaConfig) configuration class: [XLMRobertaForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xlm-roberta#transformers.XLMRobertaForMaskedLM) (XLM-RoBERTa model)
  * [XLMRobertaXLConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xlm-roberta-xl#transformers.XLMRobertaXLConfig) configuration class: [XLMRobertaXLForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xlm-roberta-xl#transformers.XLMRobertaXLForMaskedLM) (XLM-RoBERTa-XL model)
  * [XLNetConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xlnet#transformers.XLNetConfig) configuration class: [XLNetLMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xlnet#transformers.XLNetLMHeadModel) (XLNet model)
  * [XmodConfig](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xmod#transformers.XmodConfig) configuration class: [XmodForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xmod#transformers.XmodForMaskedLM) (X-MOD model)

Instantiates one of the model classes of the library (with a pretraining head) from a configuration.

Note: Loading a model from its configuration file does **not** load the model weights. It only affects the model’s configuration. Use [from\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained) to load the model weights.

Examples:

Copied

```
>>> from transformers import AutoConfig, AutoModelForPreTraining

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("bert-base-cased")
>>> model = AutoModelForPreTraining.from_config(config)
```

**from\_pretrained**

[\<source>](https://github.com/huggingface/transformers/blob/v4.34.1/src/transformers/models/auto/auto_factory.py#L448)

( \*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 to a *directory* containing model weights saved using [save\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/model#transformers.PreTrainedModel.save_pretrained), e.g., `./my_model_directory/`.
  * 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.
* **config** ([PretrainedConfig](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/configuration#transformers.PretrainedConfig), *optional*) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
  * The model is a model provided by the library (loaded with the *model id* string of a pretrained model).
  * The model was saved using [save\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/model#transformers.PreTrainedModel.save_pretrained) and is reloaded by supplying the save directory.
  * 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.

  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 [save\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/model#transformers.PreTrainedModel.save_pretrained) and [from\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) is not a simpler option.
* **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)
  * If a configuration is not provided, `kwargs` will be first passed to the configuration class initialization function ([from\_pretrained()](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/configuration#transformers.PretrainedConfig.from_pretrained)). 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.

Instantiate one of the model classes of the library (with a pretraining head) 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`:

* **albert** — [AlbertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/albert#transformers.AlbertForPreTraining) (ALBERT model)
* **bart** — [BartForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/bart#transformers.BartForConditionalGeneration) (BART model)
* **bert** — [BertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/bert#transformers.BertForPreTraining) (BERT model)
* **big\_bird** — [BigBirdForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/big_bird#transformers.BigBirdForPreTraining) (BigBird model)
* **bloom** — [BloomForCausalLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/bloom#transformers.BloomForCausalLM) (BLOOM model)
* **camembert** — [CamembertForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/camembert#transformers.CamembertForMaskedLM) (CamemBERT model)
* **ctrl** — [CTRLLMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/ctrl#transformers.CTRLLMHeadModel) (CTRL model)
* **data2vec-text** — [Data2VecTextForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/data2vec#transformers.Data2VecTextForMaskedLM) (Data2VecText model)
* **deberta** — [DebertaForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/deberta#transformers.DebertaForMaskedLM) (DeBERTa model)
* **deberta-v2** — [DebertaV2ForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/deberta-v2#transformers.DebertaV2ForMaskedLM) (DeBERTa-v2 model)
* **distilbert** — [DistilBertForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/distilbert#transformers.DistilBertForMaskedLM) (DistilBERT model)
* **electra** — [ElectraForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/electra#transformers.ElectraForPreTraining) (ELECTRA model)
* **ernie** — [ErnieForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/ernie#transformers.ErnieForPreTraining) (ERNIE model)
* **flaubert** — [FlaubertWithLMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/flaubert#transformers.FlaubertWithLMHeadModel) (FlauBERT model)
* **flava** — [FlavaForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/flava#transformers.FlavaForPreTraining) (FLAVA model)
* **fnet** — [FNetForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/fnet#transformers.FNetForPreTraining) (FNet model)
* **fsmt** — [FSMTForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/fsmt#transformers.FSMTForConditionalGeneration) (FairSeq Machine-Translation model)
* **funnel** — [FunnelForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/funnel#transformers.FunnelForPreTraining) (Funnel Transformer model)
* **gpt-sw3** — [GPT2LMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/gpt2#transformers.GPT2LMHeadModel) (GPT-Sw3 model)
* **gpt2** — [GPT2LMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/gpt2#transformers.GPT2LMHeadModel) (OpenAI GPT-2 model)
* **gpt\_bigcode** — [GPTBigCodeForCausalLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/gpt_bigcode#transformers.GPTBigCodeForCausalLM) (GPTBigCode model)
* **gptsan-japanese** — [GPTSanJapaneseForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/gptsan-japanese#transformers.GPTSanJapaneseForConditionalGeneration) (GPTSAN-japanese model)
* **ibert** — [IBertForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/ibert#transformers.IBertForMaskedLM) (I-BERT model)
* **idefics** — [IdeficsForVisionText2Text](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/idefics#transformers.IdeficsForVisionText2Text) (IDEFICS model)
* **layoutlm** — [LayoutLMForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/layoutlm#transformers.LayoutLMForMaskedLM) (LayoutLM model)
* **longformer** — [LongformerForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/longformer#transformers.LongformerForMaskedLM) (Longformer model)
* **luke** — [LukeForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/luke#transformers.LukeForMaskedLM) (LUKE model)
* **lxmert** — [LxmertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/lxmert#transformers.LxmertForPreTraining) (LXMERT model)
* **mega** — [MegaForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mega#transformers.MegaForMaskedLM) (MEGA model)
* **megatron-bert** — [MegatronBertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/megatron-bert#transformers.MegatronBertForPreTraining) (Megatron-BERT model)
* **mobilebert** — [MobileBertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mobilebert#transformers.MobileBertForPreTraining) (MobileBERT model)
* **mpnet** — [MPNetForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mpnet#transformers.MPNetForMaskedLM) (MPNet model)
* **mpt** — [MptForCausalLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mpt#transformers.MptForCausalLM) (MPT model)
* **mra** — [MraForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mra#transformers.MraForMaskedLM) (MRA model)
* **mvp** — [MvpForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/mvp#transformers.MvpForConditionalGeneration) (MVP model)
* **nezha** — [NezhaForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nezha#transformers.NezhaForPreTraining) (Nezha model)
* **nllb-moe** — [NllbMoeForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/nllb-moe#transformers.NllbMoeForConditionalGeneration) (NLLB-MOE model)
* **openai-gpt** — [OpenAIGPTLMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/openai-gpt#transformers.OpenAIGPTLMHeadModel) (OpenAI GPT model)
* **retribert** — [RetriBertModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/retribert#transformers.RetriBertModel) (RetriBERT model)
* **roberta** — [RobertaForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/roberta#transformers.RobertaForMaskedLM) (RoBERTa model)
* **roberta-prelayernorm** — [RobertaPreLayerNormForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/roberta-prelayernorm#transformers.RobertaPreLayerNormForMaskedLM) (RoBERTa-PreLayerNorm model)
* **roc\_bert** — [RoCBertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/roc_bert#transformers.RoCBertForPreTraining) (RoCBert model)
* **rwkv** — [RwkvForCausalLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/rwkv#transformers.RwkvForCausalLM) (RWKV model)
* **splinter** — [SplinterForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/splinter#transformers.SplinterForPreTraining) (Splinter model)
* **squeezebert** — [SqueezeBertForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/squeezebert#transformers.SqueezeBertForMaskedLM) (SqueezeBERT model)
* **switch\_transformers** — [SwitchTransformersForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/switch_transformers#transformers.SwitchTransformersForConditionalGeneration) (SwitchTransformers model)
* **t5** — [T5ForConditionalGeneration](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/t5#transformers.T5ForConditionalGeneration) (T5 model)
* **tapas** — [TapasForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/tapas#transformers.TapasForMaskedLM) (TAPAS model)
* **transfo-xl** — [TransfoXLLMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/transfo-xl#transformers.TransfoXLLMHeadModel) (Transformer-XL model)
* **tvlt** — [TvltForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/tvlt#transformers.TvltForPreTraining) (TVLT model)
* **unispeech** — [UniSpeechForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/unispeech#transformers.UniSpeechForPreTraining) (UniSpeech model)
* **unispeech-sat** — [UniSpeechSatForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/unispeech-sat#transformers.UniSpeechSatForPreTraining) (UniSpeechSat model)
* **videomae** — [VideoMAEForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/videomae#transformers.VideoMAEForPreTraining) (VideoMAE model)
* **visual\_bert** — [VisualBertForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/visual_bert#transformers.VisualBertForPreTraining) (VisualBERT model)
* **vit\_mae** — [ViTMAEForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/vit_mae#transformers.ViTMAEForPreTraining) (ViTMAE model)
* **wav2vec2** — [Wav2Vec2ForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/wav2vec2#transformers.Wav2Vec2ForPreTraining) (Wav2Vec2 model)
* **wav2vec2-conformer** — [Wav2Vec2ConformerForPreTraining](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/wav2vec2-conformer#transformers.Wav2Vec2ConformerForPreTraining) (Wav2Vec2-Conformer model)
* **xlm** — [XLMWithLMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xlm#transformers.XLMWithLMHeadModel) (XLM model)
* **xlm-roberta** — [XLMRobertaForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xlm-roberta#transformers.XLMRobertaForMaskedLM) (XLM-RoBERTa model)
* **xlm-roberta-xl** — [XLMRobertaXLForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xlm-roberta-xl#transformers.XLMRobertaXLForMaskedLM) (XLM-RoBERTa-XL model)
* **xlnet** — [XLNetLMHeadModel](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xlnet#transformers.XLNetLMHeadModel) (XLNet model)
* **xmod** — [XmodForMaskedLM](https://huggingface.co/docs/transformers/v4.34.1/en/model_doc/xmod#transformers.XmodForMaskedLM) (X-MOD 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

```
>>> from transformers import AutoConfig, AutoModelForPreTraining

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForPreTraining.from_pretrained("bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForPreTraining.from_pretrained("bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForPreTraining.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )
```
