mindformers.AutoModel

class mindformers.AutoModel[源代码]

AutoModel class helps instantiates a model by yaml model name, path or config. If using a model name, the config yaml and checkpoint file will be downloaded from obs to ./checkpoint_download dir

实际案例

>>> from mindformers.auto_class import AutoModel
>>>
>>> # 1)  input model name, load model and weights
>>> model_a = AutoModel.from_pretrained('clip_vit_b_32')
>>> # 2)  input model directory, load model and weights
>>> from mindformers.mindformer_book import MindFormerBook
>>> checkpoint_dir = os.path.join(MindFormerBook.get_default_checkpoint_download_folder(), 'clip')
>>> model_b = AutoModel.from_pretrained(checkpoint_dir)
>>> # 3)  input yaml path, load model without weights
>>> config_path = os.path.join(MindFormerBook.get_project_path(),
...                            'configs', 'clip', 'run_clip_vit_b_32_pretrain_flickr8k.yaml')
>>> model_c = AutoModel.from_config(config_path)
>>> # 4)  input config, load model without weights
>>> config = AutoConfig.from_pretrained('clip_vit_b_32')
>>> model_d = AutoModel.from_config(config)
classmethod from_config(config, **kwargs)[源代码]

From config method, which instantiates a Model by config.

参数
  • config (str, BaseConfig) – A model config inherited from BaseConfig,

  • a path to .yaml file for model config. (or) –

返回

A model, which inherited from BaseModel.

classmethod from_pretrained(pretrained_model_name_or_dir, **kwargs)[源代码]

From pretrain method, which instantiates a Model by pretrained model name or path.

参数
  • pretrained_model_name_or_dir (str) – A supported model name or a directory to model checkpoint (including .yaml file for config and .ckpt file for weights), the supported model name could be selected from AutoModel.show_support_list(). If pretrained_model_name_or_dir 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 “pretrained_model_name_or_dir”, if “pretrained_model_name_or_path” is set, “pretrained_model_name_or_dir” is useless.

返回

A model, which inherited from BaseModel.

classmethod get_support_list()[源代码]

get support list method

classmethod invalid_model_name(pretrained_model_name_or_dir)[源代码]

Check whether it is a valid model name

classmethod show_support_list()[源代码]

show support list method