Auto Classes
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")will create a model that is an instance of BertModel.
There is one class of AutoModel for each task.
Extending the Auto Classes
Section titled “Extending the Auto Classes”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!
If your NewModelConfig is a subclass of 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).
AutoConfig
Section titled “AutoConfig”[[autodoc]] AutoConfig
AutoTokenizer
Section titled “AutoTokenizer”[[autodoc]] AutoTokenizer
AutoFeatureExtractor
Section titled “AutoFeatureExtractor”[[autodoc]] AutoFeatureExtractor
AutoImageProcessor
Section titled “AutoImageProcessor”[[autodoc]] AutoImageProcessor
AutoVideoProcessor
Section titled “AutoVideoProcessor”[[autodoc]] AutoVideoProcessor
AutoProcessor
Section titled “AutoProcessor”[[autodoc]] AutoProcessor
Generic model classes
Section titled “Generic model classes”The following auto classes are available for instantiating a base model class without a specific head.
AutoModel
Section titled “AutoModel”[[autodoc]] AutoModel
Generic pretraining classes
Section titled “Generic pretraining classes”The following auto classes are available for instantiating a model with a pretraining head.
AutoModelForPreTraining
Section titled “AutoModelForPreTraining”[[autodoc]] AutoModelForPreTraining
Natural Language Processing
Section titled “Natural Language Processing”The following auto classes are available for the following natural language processing tasks.
AutoModelForCausalLM
Section titled “AutoModelForCausalLM”[[autodoc]] AutoModelForCausalLM
AutoModelForMaskedLM
Section titled “AutoModelForMaskedLM”[[autodoc]] AutoModelForMaskedLM
AutoModelForMaskGeneration
Section titled “AutoModelForMaskGeneration”[[autodoc]] AutoModelForMaskGeneration
AutoModelForSeq2SeqLM
Section titled “AutoModelForSeq2SeqLM”[[autodoc]] AutoModelForSeq2SeqLM
AutoModelForSequenceClassification
Section titled “AutoModelForSequenceClassification”[[autodoc]] AutoModelForSequenceClassification
AutoModelForMultipleChoice
Section titled “AutoModelForMultipleChoice”[[autodoc]] AutoModelForMultipleChoice
AutoModelForNextSentencePrediction
Section titled “AutoModelForNextSentencePrediction”[[autodoc]] AutoModelForNextSentencePrediction
AutoModelForTokenClassification
Section titled “AutoModelForTokenClassification”[[autodoc]] AutoModelForTokenClassification
AutoModelForQuestionAnswering
Section titled “AutoModelForQuestionAnswering”[[autodoc]] AutoModelForQuestionAnswering
AutoModelForTextEncoding
Section titled “AutoModelForTextEncoding”[[autodoc]] AutoModelForTextEncoding
Computer vision
Section titled “Computer vision”The following auto classes are available for the following computer vision tasks.
AutoModelForDepthEstimation
Section titled “AutoModelForDepthEstimation”[[autodoc]] AutoModelForDepthEstimation
AutoModelForImageClassification
Section titled “AutoModelForImageClassification”[[autodoc]] AutoModelForImageClassification
AutoModelForVideoClassification
Section titled “AutoModelForVideoClassification”[[autodoc]] AutoModelForVideoClassification
AutoModelForKeypointDetection
Section titled “AutoModelForKeypointDetection”[[autodoc]] AutoModelForKeypointDetection
AutoModelForKeypointMatching
Section titled “AutoModelForKeypointMatching”[[autodoc]] AutoModelForKeypointMatching
AutoModelForMaskedImageModeling
Section titled “AutoModelForMaskedImageModeling”[[autodoc]] AutoModelForMaskedImageModeling
AutoModelForObjectDetection
Section titled “AutoModelForObjectDetection”[[autodoc]] AutoModelForObjectDetection
AutoModelForImageSegmentation
Section titled “AutoModelForImageSegmentation”[[autodoc]] AutoModelForImageSegmentation
AutoModelForImageToImage
Section titled “AutoModelForImageToImage”[[autodoc]] AutoModelForImageToImage
AutoModelForSemanticSegmentation
Section titled “AutoModelForSemanticSegmentation”[[autodoc]] AutoModelForSemanticSegmentation
AutoModelForInstanceSegmentation
Section titled “AutoModelForInstanceSegmentation”[[autodoc]] AutoModelForInstanceSegmentation
AutoModelForUniversalSegmentation
Section titled “AutoModelForUniversalSegmentation”[[autodoc]] AutoModelForUniversalSegmentation
AutoModelForZeroShotImageClassification
Section titled “AutoModelForZeroShotImageClassification”[[autodoc]] AutoModelForZeroShotImageClassification
AutoModelForZeroShotObjectDetection
Section titled “AutoModelForZeroShotObjectDetection”[[autodoc]] AutoModelForZeroShotObjectDetection
The following auto classes are available for the following audio tasks.
AutoModelForAudioClassification
Section titled “AutoModelForAudioClassification”[[autodoc]] AutoModelForAudioClassification
AutoModelForAudioFrameClassification
Section titled “AutoModelForAudioFrameClassification”[[autodoc]] AutoModelForAudioFrameClassification
AutoModelForCTC
Section titled “AutoModelForCTC”[[autodoc]] AutoModelForCTC
AutoModelForSpeechSeq2Seq
Section titled “AutoModelForSpeechSeq2Seq”[[autodoc]] AutoModelForSpeechSeq2Seq
AutoModelForAudioXVector
Section titled “AutoModelForAudioXVector”[[autodoc]] AutoModelForAudioXVector
AutoModelForTextToSpectrogram
Section titled “AutoModelForTextToSpectrogram”[[autodoc]] AutoModelForTextToSpectrogram
AutoModelForTextToWaveform
Section titled “AutoModelForTextToWaveform”[[autodoc]] AutoModelForTextToWaveform
AutoModelForAudioTokenization
Section titled “AutoModelForAudioTokenization”[[autodoc]] AutoModelForAudioTokenization
Multimodal
Section titled “Multimodal”The following auto classes are available for the following multimodal tasks.
AutoModelForMultimodalLM
Section titled “AutoModelForMultimodalLM”[[autodoc]] AutoModelForMultimodalLM
AutoModelForTableQuestionAnswering
Section titled “AutoModelForTableQuestionAnswering”[[autodoc]] AutoModelForTableQuestionAnswering
AutoModelForDocumentQuestionAnswering
Section titled “AutoModelForDocumentQuestionAnswering”[[autodoc]] AutoModelForDocumentQuestionAnswering
AutoModelForVisualQuestionAnswering
Section titled “AutoModelForVisualQuestionAnswering”[[autodoc]] AutoModelForVisualQuestionAnswering
AutoModelForVision2Seq
Section titled “AutoModelForVision2Seq”[[autodoc]] AutoModelForVision2Seq
AutoModelForImageTextToText
Section titled “AutoModelForImageTextToText”[[autodoc]] AutoModelForImageTextToText
Time Series
Section titled “Time Series”AutoModelForTimeSeriesPrediction
Section titled “AutoModelForTimeSeriesPrediction”[[autodoc]] AutoModelForTimeSeriesPrediction