mindformers.tools.MindFormerConfig

View Source On Gitee
class mindformers.tools.MindFormerConfig(*args, **kwargs)[source]

A class for configuration that inherits from Python's dict class. Can parse configuration parameters from yaml files or dict instances.

Parameters
  • args (Any) – Extensible parameter list, either a yaml configuration file path or a configuration dictionary.

  • kwargs (Any) – Extensible parameter dictionary, either a yaml configuration file path or a configuration dictionary.

Returns

An instance of the class.

Examples

>>> from mindformers.tools import MindFormerConfig
>>>
>>> # test.yaml:
>>> #     a:1
>>> cfg = MindFormerConfig('./test.yaml')
>>> cfg.a
1
>>> cfg = MindFormerConfig(**dict(a=1, b=dict(c=[0,1])))
>>> cfg.b
{'c': [0, 1]}
merge_from_dict(options)[source]

Merge options into config.

Parameters

options (dict) – Configuration options that need to be merged.

Examples

>>> from mindformers.tools import MindFormerConfig
>>>
>>> options = {'model.arch': 'LlamaForCausalLM'}
>>> cfg = MindFormerConfig(**dict(model=dict(model_config=dict(type='LlamaConfig'))))
>>> cfg.merge_from_dict(options)
>>> print(cfg)
{'model': {'model_config': {'type': 'LlamaConfig'}, 'arch': 'LlamaForCausalLM'}}