MCPcopy
hub / github.com/InternLM/InternLM / sync_model_param_within_tp

Function sync_model_param_within_tp

internlm/utils/parallel.py:27–44  ·  view source on GitHub ↗

r"""This function is changed from colossalai, which is ``sync_model_param``. We modified this function to make sure it only sync parameters within tensor parallelism but they are not splitted by tensor parallelism. This function is used to make sure parameters that are not splitted by t

(model)

Source from the content-addressed store, hash-verified

25
26
27def sync_model_param_within_tp(model):
28 r"""This function is changed from colossalai, which is ``sync_model_param``.
29
30 We modified this function to make sure it only sync parameters within tensor parallelism
31 but they are not splitted by tensor parallelism.
32 This function is used to make sure parameters that are not splitted by tensor parallelism
33 are the same across each tensor parallelism.
34 For example, parameters like RMSNorm, LayerNorm...
35
36 Args:
37 model (:class:`torch.nn.Module`): A pyTorch model on whose parameters you check the consistency.
38 """
39 parallel_mode = ParallelMode.TENSOR
40 if gpc.is_initialized(parallel_mode) and gpc.get_world_size(parallel_mode) > 1:
41 for param in model.parameters():
42 if not is_model_parallel_parameter(param):
43 ranks = gpc.get_ranks_in_group(parallel_mode)
44 dist.broadcast(param, src=ranks[0], group=gpc.get_group(parallel_mode))
45
46
47def is_no_pp_or_last_stage():

Callers 1

initialize_modelFunction · 0.90

Calls 5

is_initializedMethod · 0.80
get_world_sizeMethod · 0.80
get_ranks_in_groupMethod · 0.80
get_groupMethod · 0.80

Tested by

no test coverage detected