"docs/source/en/perf_train_gpu_many.mdx" did not exist on "f2ab21833f3c1fcc8dea76988bdacd368fca779e"
auto.md 7.99 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
<!--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.
11
12
13
14

鈿狅笍 Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.

15
16
17
18
19
20
21
22
23
24
25
26
27
-->

# 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
28
model = AutoModel.from_pretrained("bert-base-cased")
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
69
70
71
72
```

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
73
74
75
76
## AutoImageProcessor

[[autodoc]] AutoImageProcessor

77
78
79
80
## AutoProcessor

[[autodoc]] AutoProcessor

81
82
83
84
85
## Generic model classes

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

### AutoModel
86
87
88

[[autodoc]] AutoModel

89
90
91
92
93
94
95
96
97
98
99
100
101
### TFAutoModel

[[autodoc]] TFAutoModel

### FlaxAutoModel

[[autodoc]] FlaxAutoModel

## Generic pretraining classes

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

### AutoModelForPreTraining
102
103
104

[[autodoc]] AutoModelForPreTraining

105
### TFAutoModelForPreTraining
106

107
[[autodoc]] TFAutoModelForPreTraining
108

109
### FlaxAutoModelForPreTraining
110

111
[[autodoc]] FlaxAutoModelForPreTraining
112

113
## Natural Language Processing
114

115
The following auto classes are available for the following natural language processing tasks.
116

117
### AutoModelForCausalLM
118

119
[[autodoc]] AutoModelForCausalLM
120

121
### TFAutoModelForCausalLM
122

123
[[autodoc]] TFAutoModelForCausalLM
124

125
### FlaxAutoModelForCausalLM
126

127
[[autodoc]] FlaxAutoModelForCausalLM
128

129
### AutoModelForMaskedLM
130

131
[[autodoc]] AutoModelForMaskedLM
132

133
### TFAutoModelForMaskedLM
134

135
[[autodoc]] TFAutoModelForMaskedLM
136

137
### FlaxAutoModelForMaskedLM
138

139
[[autodoc]] FlaxAutoModelForMaskedLM
140

141
142
143
144
### AutoModelForMaskGeneration

[[autodoc]] AutoModelForMaskGeneration

145
### AutoModelForSeq2SeqLM
146

147
[[autodoc]] AutoModelForSeq2SeqLM
148

149
### TFAutoModelForSeq2SeqLM
150

151
[[autodoc]] TFAutoModelForSeq2SeqLM
152

153
### FlaxAutoModelForSeq2SeqLM
154

155
[[autodoc]] FlaxAutoModelForSeq2SeqLM
156

157
### AutoModelForSequenceClassification
NielsRogge's avatar
NielsRogge committed
158

159
[[autodoc]] AutoModelForSequenceClassification
NielsRogge's avatar
NielsRogge committed
160

161
### TFAutoModelForSequenceClassification
162

163
[[autodoc]] TFAutoModelForSequenceClassification
164

165
### FlaxAutoModelForSequenceClassification
166

167
[[autodoc]] FlaxAutoModelForSequenceClassification
168

169
### AutoModelForMultipleChoice
170

171
[[autodoc]] AutoModelForMultipleChoice
172

173
### TFAutoModelForMultipleChoice
174

175
[[autodoc]] TFAutoModelForMultipleChoice
176

177
### FlaxAutoModelForMultipleChoice
178

179
[[autodoc]] FlaxAutoModelForMultipleChoice
180

181
### AutoModelForNextSentencePrediction
182

183
[[autodoc]] AutoModelForNextSentencePrediction
184

185
### TFAutoModelForNextSentencePrediction
186

187
[[autodoc]] TFAutoModelForNextSentencePrediction
188

189
### FlaxAutoModelForNextSentencePrediction
NielsRogge's avatar
NielsRogge committed
190

191
[[autodoc]] FlaxAutoModelForNextSentencePrediction
NielsRogge's avatar
NielsRogge committed
192

193
### AutoModelForTokenClassification
194

195
[[autodoc]] AutoModelForTokenClassification
196

197
### TFAutoModelForTokenClassification
198

199
[[autodoc]] TFAutoModelForTokenClassification
200

201
### FlaxAutoModelForTokenClassification
202

203
[[autodoc]] FlaxAutoModelForTokenClassification
204

205
### AutoModelForQuestionAnswering
206

207
[[autodoc]] AutoModelForQuestionAnswering
208

209
### TFAutoModelForQuestionAnswering
210

211
[[autodoc]] TFAutoModelForQuestionAnswering
212

213
### FlaxAutoModelForQuestionAnswering
214

215
[[autodoc]] FlaxAutoModelForQuestionAnswering
216

217
218
219
220
221
222
223
224
### AutoModelForTextEncoding

[[autodoc]] AutoModelForTextEncoding

### TFAutoModelForTextEncoding

[[autodoc]] TFAutoModelForTextEncoding

225
## Computer vision
226

227
The following auto classes are available for the following computer vision tasks.
228

229
### AutoModelForDepthEstimation
230

231
[[autodoc]] AutoModelForDepthEstimation
232

233
234
235
236
237
### AutoModelForImageClassification

[[autodoc]] AutoModelForImageClassification

### TFAutoModelForImageClassification
238
239
240

[[autodoc]] TFAutoModelForImageClassification

241
### FlaxAutoModelForImageClassification
242

243
[[autodoc]] FlaxAutoModelForImageClassification
244

245
### AutoModelForVideoClassification
246

247
[[autodoc]] AutoModelForVideoClassification
248

249
### AutoModelForMaskedImageModeling
250

251
[[autodoc]] AutoModelForMaskedImageModeling
252

253
### AutoModelForObjectDetection
254

255
[[autodoc]] AutoModelForObjectDetection
256

257
### AutoModelForImageSegmentation
258

259
[[autodoc]] AutoModelForImageSegmentation
260

261
### AutoModelForSemanticSegmentation
262

263
[[autodoc]] AutoModelForSemanticSegmentation
264

265
### TFAutoModelForSemanticSegmentation
266

267
[[autodoc]] TFAutoModelForSemanticSegmentation
268

269
### AutoModelForInstanceSegmentation
270

271
[[autodoc]] AutoModelForInstanceSegmentation
272

273
274
275
276
### AutoModelForUniversalSegmentation

[[autodoc]] AutoModelForUniversalSegmentation

277
278
279
280
281
282
283
284
### AutoModelForZeroShotImageClassification

[[autodoc]] AutoModelForZeroShotImageClassification

### TFAutoModelForZeroShotImageClassification

[[autodoc]] TFAutoModelForZeroShotImageClassification

285
### AutoModelForZeroShotObjectDetection
286

287
[[autodoc]] AutoModelForZeroShotObjectDetection
288

289
## Audio
290

291
The following auto classes are available for the following audio tasks.
292

293
### AutoModelForAudioClassification
294

295
[[autodoc]] AutoModelForAudioClassification
296

297
### AutoModelForAudioFrameClassification
Joao Gante's avatar
Joao Gante committed
298

299
[[autodoc]] AutoModelForAudioFrameClassification
Joao Gante's avatar
Joao Gante committed
300

301
### AutoModelForCTC
302

303
[[autodoc]] AutoModelForCTC
304

305
### AutoModelForSpeechSeq2Seq
306

307
[[autodoc]] AutoModelForSpeechSeq2Seq
308

309
### TFAutoModelForSpeechSeq2Seq
310

311
[[autodoc]] TFAutoModelForSpeechSeq2Seq
312

313
314
315
316
### FlaxAutoModelForSpeechSeq2Seq

[[autodoc]] FlaxAutoModelForSpeechSeq2Seq

317
### AutoModelForAudioXVector
318

319
[[autodoc]] AutoModelForAudioXVector
320

321
## Multimodal
322

323
The following auto classes are available for the following multimodal tasks.
324

325
### AutoModelForTableQuestionAnswering
326

327
[[autodoc]] AutoModelForTableQuestionAnswering
328

329
### TFAutoModelForTableQuestionAnswering
330

331
[[autodoc]] TFAutoModelForTableQuestionAnswering
332

333
### AutoModelForDocumentQuestionAnswering
334

335
[[autodoc]] AutoModelForDocumentQuestionAnswering
336

337
### TFAutoModelForDocumentQuestionAnswering
338

339
[[autodoc]] TFAutoModelForDocumentQuestionAnswering
340

341
### AutoModelForVisualQuestionAnswering
342

343
[[autodoc]] AutoModelForVisualQuestionAnswering
344

345
### AutoModelForVision2Seq
346

347
348
349
350
351
[[autodoc]] AutoModelForVision2Seq

### TFAutoModelForVision2Seq

[[autodoc]] TFAutoModelForVision2Seq
352

353
### FlaxAutoModelForVision2Seq
354
355

[[autodoc]] FlaxAutoModelForVision2Seq