Custom config error when model.save_pretrained

I created a model with a custom head. To save the model I created a custom config. But I get the following error: __init__() missing 2 required positional arguments: 'model_type' and 'hidden_size' when I save the model with model.save_pretrained(path)

That’s my config class:

class ReaderConfig(PretrainedConfig):
    
    def __init__(self,model_type:str,hidden_size:int,**kwargs,):

        self.model_type = model_type
        self.hidden_size = hidden_size
        super().__init__(**kwargs)

That’s the error message:

--> 756 class_config_dict = self.__class__().to_dict() if not self.is_composition else {}
    758 serializable_config_dict = {}
    760 # only serialize values that differ from the default config

TypeError: __init__() missing 2 required positional arguments: 'model_type' and 'hidden_size'

Does any one know what could be wrong?

1 Like

I found out what was wrong.

The init function in the config class needs to provide default values.

class ReaderConfig(PretrainedConfig):
    
    def __init__(self,model_type:str='bert-base-uncased',hidden_size:int=1024,**kwargs,):

        self.model_type = model_type
        self.hidden_size = hidden_size
        super().__init__(**kwargs)
5 Likes

thanks you very helpful

Thank you this fix with providing default values unblocked me