auto.mdx 7.34 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!--Copyright 2020 The HuggingFace Team. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->

# 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


```python
Sylvain Gugger's avatar
Style  
Sylvain Gugger committed
24
model = AutoModel.from_pretrained("bert-base-cased")
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
```

will create a model that is an instance of [`BertModel`].

There is one class of `AutoModel` for each task, and for each backend (PyTorch, TensorFlow, or Flax).

## 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:

```python
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 [`~transformer.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`).

</Tip>

## AutoConfig

[[autodoc]] AutoConfig

## AutoTokenizer

[[autodoc]] AutoTokenizer

## AutoFeatureExtractor

[[autodoc]] AutoFeatureExtractor

amyeroberts's avatar
amyeroberts committed
69
70
71
72
## AutoImageProcessor

[[autodoc]] AutoImageProcessor

73
74
75
76
## AutoProcessor

[[autodoc]] AutoProcessor

77
78
79
80
81
## Generic model classes

The following auto classes are available for instantiating a base model class without a specific head.

### AutoModel
82
83
84

[[autodoc]] AutoModel

85
86
87
88
89
90
91
92
93
94
95
96
97
### TFAutoModel

[[autodoc]] TFAutoModel

### FlaxAutoModel

[[autodoc]] FlaxAutoModel

## Generic pretraining classes

The following auto classes are available for instantiating a model with a pretraining head.

### AutoModelForPreTraining
98
99
100

[[autodoc]] AutoModelForPreTraining

101
### TFAutoModelForPreTraining
102

103
[[autodoc]] TFAutoModelForPreTraining
104

105
### FlaxAutoModelForPreTraining
106

107
[[autodoc]] FlaxAutoModelForPreTraining
108

109
## Natural Language Processing
110

111
The following auto classes are available for the following natural language processing tasks.
112

113
### AutoModelForCausalLM
114

115
[[autodoc]] AutoModelForCausalLM
116

117
### TFAutoModelForCausalLM
118

119
[[autodoc]] TFAutoModelForCausalLM
120

121
### FlaxAutoModelForCausalLM
122

123
[[autodoc]] FlaxAutoModelForCausalLM
124

125
### AutoModelForMaskedLM
126

127
[[autodoc]] AutoModelForMaskedLM
128

129
### TFAutoModelForMaskedLM
130

131
[[autodoc]] TFAutoModelForMaskedLM
132

133
### FlaxAutoModelForMaskedLM
134

135
[[autodoc]] FlaxAutoModelForMaskedLM
136

137
### AutoModelForSeq2SeqLM
138

139
[[autodoc]] AutoModelForSeq2SeqLM
140

141
### TFAutoModelForSeq2SeqLM
142

143
[[autodoc]] TFAutoModelForSeq2SeqLM
144

145
### FlaxAutoModelForSeq2SeqLM
146

147
[[autodoc]] FlaxAutoModelForSeq2SeqLM
148

149
### AutoModelForSequenceClassification
NielsRogge's avatar
NielsRogge committed
150

151
[[autodoc]] AutoModelForSequenceClassification
NielsRogge's avatar
NielsRogge committed
152

153
### TFAutoModelForSequenceClassification
154

155
[[autodoc]] TFAutoModelForSequenceClassification
156

157
### FlaxAutoModelForSequenceClassification
158

159
[[autodoc]] FlaxAutoModelForSequenceClassification
160

161
### AutoModelForMultipleChoice
162

163
[[autodoc]] AutoModelForMultipleChoice
164

165
### TFAutoModelForMultipleChoice
166

167
[[autodoc]] TFAutoModelForMultipleChoice
168

169
### FlaxAutoModelForMultipleChoice
170

171
[[autodoc]] FlaxAutoModelForMultipleChoice
172

173
### AutoModelForNextSentencePrediction
174

175
[[autodoc]] AutoModelForNextSentencePrediction
176

177
### TFAutoModelForNextSentencePrediction
178

179
[[autodoc]] TFAutoModelForNextSentencePrediction
180

181
### FlaxAutoModelForNextSentencePrediction
NielsRogge's avatar
NielsRogge committed
182

183
[[autodoc]] FlaxAutoModelForNextSentencePrediction
NielsRogge's avatar
NielsRogge committed
184

185
### AutoModelForTokenClassification
186

187
[[autodoc]] AutoModelForTokenClassification
188

189
### TFAutoModelForTokenClassification
190

191
[[autodoc]] TFAutoModelForTokenClassification
192

193
### FlaxAutoModelForTokenClassification
194

195
[[autodoc]] FlaxAutoModelForTokenClassification
196

197
### AutoModelForQuestionAnswering
198

199
[[autodoc]] AutoModelForQuestionAnswering
200

201
### TFAutoModelForQuestionAnswering
202

203
[[autodoc]] TFAutoModelForQuestionAnswering
204

205
### FlaxAutoModelForQuestionAnswering
206

207
[[autodoc]] FlaxAutoModelForQuestionAnswering
208

209
## Computer vision
210

211
The following auto classes are available for the following computer vision tasks.
212

213
### AutoModelForDepthEstimation
214

215
[[autodoc]] AutoModelForDepthEstimation
216

217
218
219
220
221
### AutoModelForImageClassification

[[autodoc]] AutoModelForImageClassification

### TFAutoModelForImageClassification
222
223
224

[[autodoc]] TFAutoModelForImageClassification

225
### FlaxAutoModelForImageClassification
226

227
[[autodoc]] FlaxAutoModelForImageClassification
228

229
### AutoModelForVideoClassification
230

231
[[autodoc]] AutoModelForVideoClassification
232

233
### AutoModelForMaskedImageModeling
234

235
[[autodoc]] AutoModelForMaskedImageModeling
236

237
### AutoModelForObjectDetection
238

239
[[autodoc]] AutoModelForObjectDetection
240

241
### AutoModelForImageSegmentation
242

243
[[autodoc]] AutoModelForImageSegmentation
244

245
### AutoModelForSemanticSegmentation
246

247
[[autodoc]] AutoModelForSemanticSegmentation
248

249
### TFAutoModelForSemanticSegmentation
250

251
[[autodoc]] TFAutoModelForSemanticSegmentation
252

253
### AutoModelForInstanceSegmentation
254

255
[[autodoc]] AutoModelForInstanceSegmentation
256

257
258
259
260
### AutoModelForUniversalSegmentation

[[autodoc]] AutoModelForUniversalSegmentation

261
### AutoModelForZeroShotObjectDetection
262

263
[[autodoc]] AutoModelForZeroShotObjectDetection
264

265
## Audio
266

267
The following auto classes are available for the following audio tasks.
268

269
### AutoModelForAudioClassification
270

271
[[autodoc]] AutoModelForAudioClassification
272

273
### AutoModelForAudioFrameClassification
Joao Gante's avatar
Joao Gante committed
274

275
[[autodoc]] AutoModelForAudioFrameClassification
Joao Gante's avatar
Joao Gante committed
276

277
### AutoModelForCTC
278

279
[[autodoc]] AutoModelForCTC
280

281
### AutoModelForSpeechSeq2Seq
282

283
[[autodoc]] AutoModelForSpeechSeq2Seq
284

285
### TFAutoModelForSpeechSeq2Seq
286

287
[[autodoc]] TFAutoModelForSpeechSeq2Seq
288

289
### AutoModelForAudioXVector
290

291
[[autodoc]] AutoModelForAudioXVector
292

293
## Multimodal
294

295
The following auto classes are available for the following multimodal tasks.
296

297
### AutoModelForTableQuestionAnswering
298

299
[[autodoc]] AutoModelForTableQuestionAnswering
300

301
### TFAutoModelForTableQuestionAnswering
302

303
[[autodoc]] TFAutoModelForTableQuestionAnswering
304

305
### AutoModelForDocumentQuestionAnswering
306

307
[[autodoc]] AutoModelForDocumentQuestionAnswering
308

309
### TFAutoModelForDocumentQuestionAnswering
310

311
[[autodoc]] TFAutoModelForDocumentQuestionAnswering
312

313
### AutoModelForVisualQuestionAnswering
314

315
[[autodoc]] AutoModelForVisualQuestionAnswering
316

317
### AutoModelForVision2Seq
318

319
320
321
322
323
[[autodoc]] AutoModelForVision2Seq

### TFAutoModelForVision2Seq

[[autodoc]] TFAutoModelForVision2Seq
324

325
### FlaxAutoModelForVision2Seq
326
327

[[autodoc]] FlaxAutoModelForVision2Seq