mindformers.AutoConfig

View Source On Gitee
class mindformers.AutoConfig[source]

This is a generic configuration class that will be instantiated as one of the configuration classes of the library when created with the from_pretrained() class method. This class cannot be instantiated directly using __init__() (throws an error).

Examples

>>> from mindformers import AutoConfig
>>> # 1)  instantiates a config by yaml model name
>>> config_a = AutoConfig.from_pretrained('configs/llama2/predict_llama2_7b.yaml')
>>> # 2)  instantiates a config by json file
>>> config_b = AutoConfig.from_pretrained('./config.json')
>>> # 3)  instantiates a config by directory containing a configuration json file
>>> config_c = AutoConfig.from_pretrained('./dir/')
>>> # 4)  instantiates a config by model_id from modelers.cn
>>> config_d = AutoConfig.from_pretrained('MindSpore-Lab/glm2_6b')
classmethod from_pretrained(yaml_name_or_path, **kwargs)[source]

From pretrain method, which instantiates a config by YAML, JSON, directory or model_id from modelers.cn.

Warning

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

Parameters
  • yaml_name_or_path (str) – YAML file path, JSON file path, a folder containing a config.json file, or a model_id from modelers.cn. The last three are experimental features.

  • kwargs (Dict[str, Any], optional) – The values in kwargs of any keys which are configuration attributes will be used to override the loaded values.

Returns

A model config, which inherited from PretrainedConfig.

static register(model_type, config, exist_ok=False)[source]

Register a new configuration for this class.

Warning

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

Parameters
  • model_type (str) – The model type like "bert" or "gpt".

  • config (PretrainedConfig) – The config to register.

  • exist_ok (bool, optional) – If set to True, no error will be raised even if model_type already exists. Default: False .

classmethod show_support_list()[source]

show support list method