MCPcopy Index your code
hub / github.com/modelscope/modelscope / init_megatron_util

Function init_megatron_util

modelscope/utils/megatron_utils.py:36–66  ·  view source on GitHub ↗

Initialize megatron_util environment for megatron_based model. If argument `megatron_cfg` is not specified, then the megatorn_cfg will be load from configuration.json file in the model_dir. Args: megatron_cfg (Dict, optional): Megatron Config will be send to megatron_util.

(megatron_cfg=None, model_dir=None, **kwargs)

Source from the content-addressed store, hash-verified

34
35
36def init_megatron_util(megatron_cfg=None, model_dir=None, **kwargs):
37 """Initialize megatron_util environment for megatron_based model.
38
39 If argument `megatron_cfg` is not specified, then the megatorn_cfg will be load
40 from configuration.json file in the model_dir.
41
42 Args:
43 megatron_cfg (Dict, optional): Megatron Config will be send to megatron_util.
44 model_dir (str, optional): The model path for configuration. Defaults to None.
45 """
46 from modelscope.utils.hub import read_config
47 from megatron_util import initialize_megatron
48
49 assert not (megatron_cfg is None and model_dir is None), \
50 'cfg and model_dir cannot both be None when initializing megatron_util'
51 if megatron_cfg is None:
52 cfg = read_config(model_dir)
53 try:
54 megatron_cfg = cfg.megatron
55 except AttributeError:
56 try:
57 model_type = cfg.model.type
58 except AttributeError:
59 # Fit models without model type, such as mglm
60 model_type = cfg.pipeline.type
61 megatron_cfg = _DEFAULT_CFG_WITH_MODEL_TYPE[model_type] \
62 if model_type in _DEFAULT_CFG_WITH_MODEL_TYPE else {}
63 megatron_cfg.update(kwargs)
64 initialize_megatron(megatron_cfg)
65 global _IS_MEGATRON_INITIALIZED
66 _IS_MEGATRON_INITIALIZED = True
67
68
69def is_megatron_initialized() -> bool:

Callers 7

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
convert_gpt3_checkpointFunction · 0.90

Calls 2

read_configFunction · 0.90
updateMethod · 0.45

Tested by 2

convert_gpt3_checkpointFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…