mindformers.models.BaseConfig

class mindformers.models.BaseConfig(**kwargs)[源代码]

Base Config for all models’ config

实际案例

>>> from mindformers.mindformer_book import MindFormerBook
>>> from mindformers.models.base_config import BaseConfig
>>> class MyConfig(BaseConfig):
...     _support_list = MindFormerBook.get_config_support_list()['my_model']
...
...     def __init__(self,
...                  data_size: int = 32,
...                  net_size: list = [1, 2, 3],
...                  loss_type: str = "MyLoss",
...                  checkpoint_name_or_path: str = '',
...                  **kwargs):
...         self.data_size = data_size
...         self.net_size = net_size
...         loss_type = loss_type
...         self.checkpoint_name_or_path = checkpoint_name_or_path
...         super(MyConfig, self).__init__(**kwargs)
...
>>> mynet = MyModel(MyConfig)
>>> output = mynet(input)
classmethod from_pretrained(yaml_name_or_path, **kwargs)[源代码]

From pretrain method, which instantiates a config by yaml name or path.

参数
  • yaml_name_or_path (str) – A supported model name or a path to model config (.yaml), the supported model name could be selected from AutoConfig.show_support_list(). If yaml_name_or_path is model name, it supports model names beginning with mindspore or the model name itself, such as “mindspore/vit_base_p16” or “vit_base_p16”.

  • pretrained_model_name_or_path (Optional[str]) – Equal to “yaml_name_or_path”, if “pretrained_model_name_or_path” is set, “yaml_name_or_path” is useless.

返回

A model config, which inherited from BaseConfig.

classmethod get_support_list()[源代码]

get support list method

inverse_parse_config()[源代码]
remove_type()[源代码]

remove type caused by save’

save_pretrained(save_directory=None, save_name='mindspore_model')[源代码]

Save_pretrained.

参数
  • save_directory (str) – a directory to save config yaml

  • save_name (str) – the name of save files.

classmethod show_support_list()[源代码]

show support list method

to_dict()[源代码]

for yaml dump, transform from Config to a strict dict class