mindformers.core.set_context

View Source On Gitee
mindformers.core.set_context(run_mode=None, **kwargs)[source]

Set context for running environment.

Context should be configured before running your program. If there is no configuration, it will be automatically set according to the device target by default.

Note

Attribute name is required for setting attributes. Currently only run_mode belongs to MindFormers context. The kwargs will be passed to MindSpore set_context.

Parameters
  • run_mode (str) – The mode of the model behaviour. Must be in ['train', 'finetune', 'eval', 'predict'].

  • **kwargs – MindSpore context arguments.

Examples

>>> from mindformers import build_context, set_context
>>> config = {'context': {'mode': 'GRAPH_MODE'}, 'parallel':{}}
>>> build_context(config=config)
>>> set_context(max_device_memory='59GB')