docs/source/en/model_doc/auto.md
In many cases, the architecture you want to use can be guessed from the name or the path of the pretrained model you
are supplying to the from_pretrained() method. AutoClasses are here to do this job for you so that you
automatically retrieve the relevant model given the name/path to the pretrained weights/config/vocabulary.
Instantiating one of [AutoConfig], [AutoModel], and
[AutoTokenizer] will directly create a class of the relevant architecture. For instance
model = AutoModel.from_pretrained("google-bert/bert-base-cased", device_map="auto")
will create a model that is an instance of [BertModel].
There is one class of AutoModel for each task.
Each of the auto classes has a method to be extended with your custom classes. For instance, if you have defined a
custom class of model NewModel, make sure you have a NewModelConfig then you can add those to the auto
classes like this:
from transformers import AutoConfig, AutoModel
AutoConfig.register("new-model", NewModelConfig)
AutoModel.register(NewModelConfig, NewModel)
You will then be able to use the auto classes like you would usually do!
<Tip warning={true}>If your NewModelConfig is a subclass of [~transformers.PreTrainedConfig], make sure its
model_type attribute is set to the same key you use when registering the config (here "new-model").
Likewise, if your NewModel is a subclass of [PreTrainedModel], make sure its
config_class attribute is set to the same class you use when registering the model (here
NewModelConfig).
[[autodoc]] AutoConfig
[[autodoc]] AutoTokenizer
[[autodoc]] AutoFeatureExtractor
[[autodoc]] AutoImageProcessor
[[autodoc]] AutoVideoProcessor
[[autodoc]] AutoProcessor
The following auto classes are available for instantiating a base model class without a specific head.
[[autodoc]] AutoModel
The following auto classes are available for instantiating a model with a pretraining head.
[[autodoc]] AutoModelForPreTraining
The following auto classes are available for the following natural language processing tasks.
[[autodoc]] AutoModelForCausalLM
[[autodoc]] AutoModelForMaskedLM
[[autodoc]] AutoModelForMaskGeneration
[[autodoc]] AutoModelForSeq2SeqLM
[[autodoc]] AutoModelForSequenceClassification
[[autodoc]] AutoModelForMultipleChoice
[[autodoc]] AutoModelForNextSentencePrediction
[[autodoc]] AutoModelForTokenClassification
[[autodoc]] AutoModelForQuestionAnswering
[[autodoc]] AutoModelForTextEncoding
The following auto classes are available for the following computer vision tasks.
[[autodoc]] AutoModelForDepthEstimation
[[autodoc]] AutoModelForTextRecognition
[[autodoc]] AutoModelForTableRecognition
[[autodoc]] AutoModelForImageClassification
[[autodoc]] AutoModelForVideoClassification
[[autodoc]] AutoModelForKeypointDetection
[[autodoc]] AutoModelForKeypointMatching
[[autodoc]] AutoModelForMaskedImageModeling
[[autodoc]] AutoModelForObjectDetection
[[autodoc]] AutoModelForImageSegmentation
[[autodoc]] AutoModelForImageToImage
[[autodoc]] AutoModelForSemanticSegmentation
[[autodoc]] AutoModelForInstanceSegmentation
[[autodoc]] AutoModelForUniversalSegmentation
[[autodoc]] AutoModelForZeroShotImageClassification
[[autodoc]] AutoModelForZeroShotObjectDetection
The following auto classes are available for the following audio tasks.
[[autodoc]] AutoModelForAudioClassification
[[autodoc]] AutoModelForAudioFrameClassification
[[autodoc]] AutoModelForCTC
[[autodoc]] AutoModelForSpeechSeq2Seq
[[autodoc]] AutoModelForAudioXVector
[[autodoc]] AutoModelForTextToSpectrogram
[[autodoc]] AutoModelForTextToWaveform
[[autodoc]] AutoModelForAudioTokenization
The following auto classes are available for the following multimodal tasks.
[[autodoc]] AutoModelForMultimodalLM
[[autodoc]] AutoModelForTableQuestionAnswering
[[autodoc]] AutoModelForDocumentQuestionAnswering
[[autodoc]] AutoModelForVisualQuestionAnswering
[[autodoc]] AutoModelForImageTextToText
[[autodoc]] AutoModelForTimeSeriesPrediction