File size: 1,136 Bytes
57bdca5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
This is different from pushing the code to the Hub in the sense that users will need to import your library to
get the custom models (contrarily to automatically downloading the model code from the Hub).
As long as your config has a model_type attribute that is different from existing model types, and that your model
classes have the right config_class attributes, you can just add them to the auto classes like this:

from transformers import AutoConfig, AutoModel, AutoModelForImageClassification
AutoConfig.register("resnet", ResnetConfig)
AutoModel.register(ResnetConfig, ResnetModel)
AutoModelForImageClassification.register(ResnetConfig, ResnetModelForImageClassification)

Note that the first argument used when registering your custom config to [AutoConfig] needs to match the model_type
of your custom config, and the first argument used when registering your custom models to any auto model class needs
to match the config_class of those models.
Sending the code to the Hub

This API is experimental and may have some slight breaking changes in the next releases.

First, make sure your model is fully defined in a .py file.