In many cases, the architecture to use can be inferred from the name or path of the pretrained model provided to the frompretrained() method.
Auto classes
In many cases, the architecture to use can be inferred from the name or path of the pretrained model provided to the from_pretrained() method.
Instantiating AutoConfig, AutoModel, or AutoTokenizer automatically creates the appropriate architecture class. For example:
model = AutoModel.from_pretrained("google-bert/bert-base-cased", device_map="auto")
This creates a model instance of BertModel.
Each task has a corresponding AutoModel class.
Extending the Auto Classes
Each auto class provides a method that allows it to be extended with custom classes. For example, if you define a custom model class NewModel, ensure that you also define a corresponding NewModelConfig. You can then register them with the auto classes as shown below:
from transformers import AutoConfig, AutoModel
AutoConfig.register("new-model", NewModelConfig)
AutoModel.register(NewModelConfig, NewModel)
You can then use the auto classes as you normally would.
If your
NewModelConfigis a subclass oftransformers.PreTrainedConfig, make sure itsmodel_typeattribute is set to the same key you use when registering the config (here"new-model").Likewise, if your
NewModelis a subclass ofPreTrainedModel, make sure itsconfig_classattribute is set to the same class you use when registering the model (hereNewModelConfig).
AutoConfig
[[autodoc]] AutoConfig
AutoTokenizer
[[autodoc]] AutoTokenizer
AutoFeatureExtractor
[[autodoc]] AutoFeatureExtractor
AutoImageProcessor
[[autodoc]] AutoImageProcessor
AutoVideoProcessor
See Video processor backends for backend selection, custom registration, and saving and reloading.
[[autodoc]] AutoVideoProcessor
AutoProcessor
[[autodoc]] AutoProcessor
Generic model classes
The following auto classes are available for instantiating a base model class without a specific head.
AutoModel
[[autodoc]] AutoModel
Generic pretraining classes
The following auto classes are available for instantiating a model with a pretraining head.
AutoModelForPreTraining
[[autodoc]] AutoModelForPreTraining
Natural Language Processing
The following auto classes are available for the following natural language processing tasks.
AutoModelForCausalLM
[[autodoc]] AutoModelForCausalLM
AutoModelForMaskedLM
[[autodoc]] AutoModelForMaskedLM
AutoModelForMaskGeneration
[[autodoc]] AutoModelForMaskGeneration
AutoModelForSeq2SeqLM
[[autodoc]] AutoModelForSeq2SeqLM
AutoModelForSequenceClassification
[[autodoc]] AutoModelForSequenceClassification
AutoModelForMultipleChoice
[[autodoc]] AutoModelForMultipleChoice
AutoModelForNextSentencePrediction
[[autodoc]] AutoModelForNextSentencePrediction
AutoModelForTokenClassification
[[autodoc]] AutoModelForTokenClassification
AutoModelForQuestionAnswering
[[autodoc]] AutoModelForQuestionAnswering
AutoModelForTextEncoding
[[autodoc]] AutoModelForTextEncoding
Computer vision
The following auto classes are available for the following computer vision tasks.
AutoModelForDepthEstimation
[[autodoc]] AutoModelForDepthEstimation
AutoModelForNormalEstimation
[[autodoc]] AutoModelForNormalEstimation
AutoModelForPointmapEstimation
[[autodoc]] AutoModelForPointmapEstimation
AutoModelForImageMatting
[[autodoc]] AutoModelForImageMatting
AutoModelForTextRecognition
[[autodoc]] AutoModelForTextRecognition
AutoModelForTableRecognition
[[autodoc]] AutoModelForTableRecognition
AutoModelForImageClassification
[[autodoc]] AutoModelForImageClassification
AutoModelForVideoClassification
[[autodoc]] AutoModelForVideoClassification
AutoModelForPoseEstimation
[[autodoc]] AutoModelForPoseEstimation
AutoModelForKeypointDetection
[[autodoc]] AutoModelForKeypointDetection
AutoModelForKeypointMatching
[[autodoc]] AutoModelForKeypointMatching
AutoModelForMaskedImageModeling
[[autodoc]] AutoModelForMaskedImageModeling
AutoModelForObjectDetection
[[autodoc]] AutoModelForObjectDetection
AutoModelForImageSegmentation
[[autodoc]] AutoModelForImageSegmentation
AutoModelForImageToImage
[[autodoc]] AutoModelForImageToImage
AutoModelForSemanticSegmentation
[[autodoc]] AutoModelForSemanticSegmentation
AutoModelForInstanceSegmentation
[[autodoc]] AutoModelForInstanceSegmentation
AutoModelForUniversalSegmentation
[[autodoc]] AutoModelForUniversalSegmentation
AutoModelForZeroShotImageClassification
[[autodoc]] AutoModelForZeroShotImageClassification
AutoModelForZeroShotObjectDetection
[[autodoc]] AutoModelForZeroShotObjectDetection
Audio
The following auto classes are available for the following audio tasks.
AutoModelForAudioClassification
[[autodoc]] AutoModelForAudioClassification
AutoModelForAudioFrameClassification
[[autodoc]] AutoModelForAudioFrameClassification
AutoModelForCTC
[[autodoc]] AutoModelForCTC
AutoModelForTDT
[[autodoc]] AutoModelForTDT
AutoModelForRNNT
[[autodoc]] AutoModelForRNNT
AutoModelForSpeechSeq2Seq
[[autodoc]] AutoModelForSpeechSeq2Seq
AutoModelForAudioXVector
[[autodoc]] AutoModelForAudioXVector
AutoModelForTextToSpectrogram
[[autodoc]] AutoModelForTextToSpectrogram
AutoModelForTextToWaveform
[[autodoc]] AutoModelForTextToWaveform
AutoModelForAudioTokenization
[[autodoc]] AutoModelForAudioTokenization
Multimodal
The following auto classes are available for the following multimodal tasks.
AutoModelForMultimodalLM
[[autodoc]] AutoModelForMultimodalLM
AutoModelForTableQuestionAnswering
[[autodoc]] AutoModelForTableQuestionAnswering
AutoModelForDocumentQuestionAnswering
[[autodoc]] AutoModelForDocumentQuestionAnswering
AutoModelForVisualQuestionAnswering
[[autodoc]] AutoModelForVisualQuestionAnswering
AutoModelForImageTextToText
[[autodoc]] AutoModelForImageTextToText
Time Series
AutoModelForTimeSeriesPrediction
[[autodoc]] AutoModelForTimeSeriesPrediction
Source and license
Source: Transformers documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.