AutoConfig
AutoConfig
class transformers.AutoConfig
( )
This is a generic configuration class that will be instantiated as one of the configuration classes of the library when created with the from_pretrained() class method.
This class cannot be instantiated directly using __init__() (throws an error).
from_pretrained
( pretrained_model_name_or_path**kwargs )
Parameters
- pretrained_model_name_or_path ( - stror- os.PathLike) β Can be either:- A string, the model id of a pretrained model configuration 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 a configuration file saved using the save_pretrained() method, or the save_pretrained() method, e.g., - ./my_model_directory/.
- A path or url to a saved configuration JSON file, e.g., - ./my_model_directory/configuration.json.
 
- cache_dir ( - stror- 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.
- force_download ( - bool, optional, defaults to- False) β Whether or not to force the (re-)download the model weights and configuration files and override 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.
- 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- revisioncan be any identifier allowed by git.
- return_unused_kwargs ( - bool, optional, defaults to- False) β If- False, then this function returns just the final configuration object.- If - True, then this functions returns a- Tuple(config, unused_kwargs)where unused_kwargs is a dictionary consisting of the key/value pairs whose keys are not configuration attributes: i.e., the part of- kwargswhich has not been used to update- configand is otherwise ignored.
- 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- Truefor repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine.
- kwargs(additional keyword arguments, optional) β The values in kwargs of any keys which are configuration attributes will be used to override the loaded values. Behavior concerning key/value pairs whose keys are not configuration attributes is controlled by the - return_unused_kwargskeyword parameter.
Instantiate one of the configuration classes of the library from a pretrained model configuration.
The configuration class to instantiate is selected based on the model_type property of the config object that is loaded, or when itβs missing, by falling back to using pattern matching on pretrained_model_name_or_path:
- albert β AlbertConfig (ALBERT model) 
- align β AlignConfig (ALIGN model) 
- altclip β AltCLIPConfig (AltCLIP model) 
- audio-spectrogram-transformer β ASTConfig (Audio Spectrogram Transformer model) 
- autoformer β AutoformerConfig (Autoformer model) 
- bark β BarkConfig (Bark model) 
- bart β BartConfig (BART model) 
- beit β BeitConfig (BEiT model) 
- bert β BertConfig (BERT model) 
- bert-generation β BertGenerationConfig (Bert Generation model) 
- big_bird β BigBirdConfig (BigBird model) 
- bigbird_pegasus β BigBirdPegasusConfig (BigBird-Pegasus model) 
- biogpt β BioGptConfig (BioGpt model) 
- bit β BitConfig (BiT model) 
- blenderbot β BlenderbotConfig (Blenderbot model) 
- blenderbot-small β BlenderbotSmallConfig (BlenderbotSmall model) 
- blip β BlipConfig (BLIP model) 
- blip-2 β Blip2Config (BLIP-2 model) 
- bloom β BloomConfig (BLOOM model) 
- bridgetower β BridgeTowerConfig (BridgeTower model) 
- bros β BrosConfig (BROS model) 
- camembert β CamembertConfig (CamemBERT model) 
- canine β CanineConfig (CANINE model) 
- chinese_clip β ChineseCLIPConfig (Chinese-CLIP model) 
- clap β ClapConfig (CLAP model) 
- clip β CLIPConfig (CLIP model) 
- clipseg β CLIPSegConfig (CLIPSeg model) 
- code_llama β LlamaConfig (CodeLlama model) 
- codegen β CodeGenConfig (CodeGen model) 
- conditional_detr β ConditionalDetrConfig (Conditional DETR model) 
- convbert β ConvBertConfig (ConvBERT model) 
- convnext β ConvNextConfig (ConvNeXT model) 
- convnextv2 β ConvNextV2Config (ConvNeXTV2 model) 
- cpmant β CpmAntConfig (CPM-Ant model) 
- ctrl β CTRLConfig (CTRL model) 
- cvt β CvtConfig (CvT model) 
- data2vec-audio β Data2VecAudioConfig (Data2VecAudio model) 
- data2vec-text β Data2VecTextConfig (Data2VecText model) 
- data2vec-vision β Data2VecVisionConfig (Data2VecVision model) 
- deberta β DebertaConfig (DeBERTa model) 
- deberta-v2 β DebertaV2Config (DeBERTa-v2 model) 
- decision_transformer β DecisionTransformerConfig (Decision Transformer model) 
- deformable_detr β DeformableDetrConfig (Deformable DETR model) 
- deit β DeiTConfig (DeiT model) 
- deta β DetaConfig (DETA model) 
- detr β DetrConfig (DETR model) 
- dinat β DinatConfig (DiNAT model) 
- dinov2 β Dinov2Config (DINOv2 model) 
- distilbert β DistilBertConfig (DistilBERT model) 
- donut-swin β DonutSwinConfig (DonutSwin model) 
- dpr β DPRConfig (DPR model) 
- dpt β DPTConfig (DPT model) 
- efficientformer β EfficientFormerConfig (EfficientFormer model) 
- efficientnet β EfficientNetConfig (EfficientNet model) 
- electra β ElectraConfig (ELECTRA model) 
- encodec β EncodecConfig (EnCodec model) 
- encoder-decoder β EncoderDecoderConfig (Encoder decoder model) 
- ernie β ErnieConfig (ERNIE model) 
- ernie_m β ErnieMConfig (ErnieM model) 
- esm β EsmConfig (ESM model) 
- falcon β FalconConfig (Falcon model) 
- flaubert β FlaubertConfig (FlauBERT model) 
- flava β FlavaConfig (FLAVA model) 
- fnet β FNetConfig (FNet model) 
- focalnet β FocalNetConfig (FocalNet model) 
- fsmt β FSMTConfig (FairSeq Machine-Translation model) 
- funnel β FunnelConfig (Funnel Transformer model) 
- git β GitConfig (GIT model) 
- glpn β GLPNConfig (GLPN model) 
- gpt-sw3 β GPT2Config (GPT-Sw3 model) 
- gpt2 β GPT2Config (OpenAI GPT-2 model) 
- gpt_bigcode β GPTBigCodeConfig (GPTBigCode model) 
- gpt_neo β GPTNeoConfig (GPT Neo model) 
- gpt_neox β GPTNeoXConfig (GPT NeoX model) 
- gpt_neox_japanese β GPTNeoXJapaneseConfig (GPT NeoX Japanese model) 
- gptj β GPTJConfig (GPT-J model) 
- gptsan-japanese β GPTSanJapaneseConfig (GPTSAN-japanese model) 
- graphormer β GraphormerConfig (Graphormer model) 
- groupvit β GroupViTConfig (GroupViT model) 
- hubert β HubertConfig (Hubert model) 
- ibert β IBertConfig (I-BERT model) 
- idefics β IdeficsConfig (IDEFICS model) 
- imagegpt β ImageGPTConfig (ImageGPT model) 
- informer β InformerConfig (Informer model) 
- instructblip β InstructBlipConfig (InstructBLIP model) 
- jukebox β JukeboxConfig (Jukebox model) 
- layoutlm β LayoutLMConfig (LayoutLM model) 
- layoutlmv2 β LayoutLMv2Config (LayoutLMv2 model) 
- layoutlmv3 β LayoutLMv3Config (LayoutLMv3 model) 
- led β LEDConfig (LED model) 
- levit β LevitConfig (LeViT model) 
- lilt β LiltConfig (LiLT model) 
- llama β LlamaConfig (LLaMA model) 
- longformer β LongformerConfig (Longformer model) 
- longt5 β LongT5Config (LongT5 model) 
- luke β LukeConfig (LUKE model) 
- lxmert β LxmertConfig (LXMERT model) 
- m2m_100 β M2M100Config (M2M100 model) 
- marian β MarianConfig (Marian model) 
- markuplm β MarkupLMConfig (MarkupLM model) 
- mask2former β Mask2FormerConfig (Mask2Former model) 
- maskformer β MaskFormerConfig (MaskFormer model) 
- maskformer-swin β - MaskFormerSwinConfig(MaskFormerSwin model)
- mbart β MBartConfig (mBART model) 
- mctct β MCTCTConfig (M-CTC-T model) 
- mega β MegaConfig (MEGA model) 
- megatron-bert β MegatronBertConfig (Megatron-BERT model) 
- mgp-str β MgpstrConfig (MGP-STR model) 
- mistral β MistralConfig (Mistral model) 
- mobilebert β MobileBertConfig (MobileBERT model) 
- mobilenet_v1 β MobileNetV1Config (MobileNetV1 model) 
- mobilenet_v2 β MobileNetV2Config (MobileNetV2 model) 
- mobilevit β MobileViTConfig (MobileViT model) 
- mobilevitv2 β MobileViTV2Config (MobileViTV2 model) 
- mpnet β MPNetConfig (MPNet model) 
- mpt β MptConfig (MPT model) 
- mra β MraConfig (MRA model) 
- mt5 β MT5Config (MT5 model) 
- musicgen β MusicgenConfig (MusicGen model) 
- mvp β MvpConfig (MVP model) 
- nat β NatConfig (NAT model) 
- nezha β NezhaConfig (Nezha model) 
- nllb-moe β NllbMoeConfig (NLLB-MOE model) 
- nougat β VisionEncoderDecoderConfig (Nougat model) 
- nystromformer β NystromformerConfig (NystrΓΆmformer model) 
- oneformer β OneFormerConfig (OneFormer model) 
- open-llama β OpenLlamaConfig (OpenLlama model) 
- openai-gpt β OpenAIGPTConfig (OpenAI GPT model) 
- opt β OPTConfig (OPT model) 
- owlvit β OwlViTConfig (OWL-ViT model) 
- pegasus β PegasusConfig (Pegasus model) 
- pegasus_x β PegasusXConfig (PEGASUS-X model) 
- perceiver β PerceiverConfig (Perceiver model) 
- persimmon β PersimmonConfig (Persimmon model) 
- pix2struct β Pix2StructConfig (Pix2Struct model) 
- plbart β PLBartConfig (PLBart model) 
- poolformer β PoolFormerConfig (PoolFormer model) 
- pop2piano β Pop2PianoConfig (Pop2Piano model) 
- prophetnet β ProphetNetConfig (ProphetNet model) 
- pvt β PvtConfig (PVT model) 
- qdqbert β QDQBertConfig (QDQBert model) 
- rag β RagConfig (RAG model) 
- realm β RealmConfig (REALM model) 
- reformer β ReformerConfig (Reformer model) 
- regnet β RegNetConfig (RegNet model) 
- rembert β RemBertConfig (RemBERT model) 
- resnet β ResNetConfig (ResNet model) 
- retribert β RetriBertConfig (RetriBERT model) 
- roberta β RobertaConfig (RoBERTa model) 
- roberta-prelayernorm β RobertaPreLayerNormConfig (RoBERTa-PreLayerNorm model) 
- roc_bert β RoCBertConfig (RoCBert model) 
- roformer β RoFormerConfig (RoFormer model) 
- rwkv β RwkvConfig (RWKV model) 
- sam β SamConfig (SAM model) 
- segformer β SegformerConfig (SegFormer model) 
- sew β SEWConfig (SEW model) 
- sew-d β SEWDConfig (SEW-D model) 
- speech-encoder-decoder β SpeechEncoderDecoderConfig (Speech Encoder decoder model) 
- speech_to_text β Speech2TextConfig (Speech2Text model) 
- speech_to_text_2 β Speech2Text2Config (Speech2Text2 model) 
- speecht5 β SpeechT5Config (SpeechT5 model) 
- splinter β SplinterConfig (Splinter model) 
- squeezebert β SqueezeBertConfig (SqueezeBERT model) 
- swiftformer β SwiftFormerConfig (SwiftFormer model) 
- swin β SwinConfig (Swin Transformer model) 
- swin2sr β Swin2SRConfig (Swin2SR model) 
- swinv2 β Swinv2Config (Swin Transformer V2 model) 
- switch_transformers β SwitchTransformersConfig (SwitchTransformers model) 
- t5 β T5Config (T5 model) 
- table-transformer β TableTransformerConfig (Table Transformer model) 
- tapas β TapasConfig (TAPAS model) 
- time_series_transformer β TimeSeriesTransformerConfig (Time Series Transformer model) 
- timesformer β TimesformerConfig (TimeSformer model) 
- timm_backbone β - TimmBackboneConfig(TimmBackbone model)
- trajectory_transformer β TrajectoryTransformerConfig (Trajectory Transformer model) 
- transfo-xl β TransfoXLConfig (Transformer-XL model) 
- trocr β TrOCRConfig (TrOCR model) 
- tvlt β TvltConfig (TVLT model) 
- umt5 β UMT5Config (UMT5 model) 
- unispeech β UniSpeechConfig (UniSpeech model) 
- unispeech-sat β UniSpeechSatConfig (UniSpeechSat model) 
- upernet β UperNetConfig (UPerNet model) 
- van β VanConfig (VAN model) 
- videomae β VideoMAEConfig (VideoMAE model) 
- vilt β ViltConfig (ViLT model) 
- vision-encoder-decoder β VisionEncoderDecoderConfig (Vision Encoder decoder model) 
- vision-text-dual-encoder β VisionTextDualEncoderConfig (VisionTextDualEncoder model) 
- visual_bert β VisualBertConfig (VisualBERT model) 
- vit β ViTConfig (ViT model) 
- vit_hybrid β ViTHybridConfig (ViT Hybrid model) 
- vit_mae β ViTMAEConfig (ViTMAE model) 
- vit_msn β ViTMSNConfig (ViTMSN model) 
- vitdet β VitDetConfig (VitDet model) 
- vitmatte β VitMatteConfig (ViTMatte model) 
- vits β VitsConfig (VITS model) 
- vivit β VivitConfig (ViViT model) 
- wav2vec2 β Wav2Vec2Config (Wav2Vec2 model) 
- wav2vec2-conformer β Wav2Vec2ConformerConfig (Wav2Vec2-Conformer model) 
- wavlm β WavLMConfig (WavLM model) 
- whisper β WhisperConfig (Whisper model) 
- xclip β XCLIPConfig (X-CLIP model) 
- xglm β XGLMConfig (XGLM model) 
- xlm β XLMConfig (XLM model) 
- xlm-prophetnet β XLMProphetNetConfig (XLM-ProphetNet model) 
- xlm-roberta β XLMRobertaConfig (XLM-RoBERTa model) 
- xlm-roberta-xl β XLMRobertaXLConfig (XLM-RoBERTa-XL model) 
- xlnet β XLNetConfig (XLNet model) 
- xmod β XmodConfig (X-MOD model) 
- yolos β YolosConfig (YOLOS model) 
- yoso β YosoConfig (YOSO model) 
Examples:
Copied
>>> from transformers import AutoConfig
>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("bert-base-uncased")
>>> # Download configuration from huggingface.co (user-uploaded) and cache.
>>> config = AutoConfig.from_pretrained("dbmdz/bert-base-german-cased")
>>> # If configuration file is in a directory (e.g., was saved using *save_pretrained('./test/saved_model/')*).
>>> config = AutoConfig.from_pretrained("./test/bert_saved_model/")
>>> # Load a specific configuration file.
>>> config = AutoConfig.from_pretrained("./test/bert_saved_model/my_configuration.json")
>>> # Change some config attributes when loading a pretrained config.
>>> config = AutoConfig.from_pretrained("bert-base-uncased", output_attentions=True, foo=False)
>>> config.output_attentions
True
>>> config, unused_kwargs = AutoConfig.from_pretrained(
...     "bert-base-uncased", output_attentions=True, foo=False, return_unused_kwargs=True
... )
>>> config.output_attentions
True
>>> unused_kwargs
{'foo': False}register
( model_typeconfigexist_ok = False )
Parameters
- model_type ( - str) β The model type like βbertβ or βgptβ.
- config (PretrainedConfig) β The config to register. 
Register a new configuration for this class.
Last updated
