MCPcopy Create free account
hub / github.com/togethercomputer/OpenChatKit / reinit_dp_communicator

Function reinit_dp_communicator

training/comm/comm_utils.py:159–205  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

157
158
159def reinit_dp_communicator(args):
160
161 print('###### reinit start #######')
162
163 default_init(args)
164 assert args.world_size == args.data_group_size * args.pipeline_group_size
165 if args.world_size == args.data_group_size * args.pipeline_group_size:
166 # We do the following hard code alignment of communication groups:
167 # Suppose there are 8 instances (world_size), and 4 data parallel groups (data_group_size is 2),
168 # Then there would be 2 pipeline parallel groups (pipeline_group_size is 4), then the groups will look like:
169 # pipeline parallel: <group 0: [0,1,2,3]>, <group 1: [4,5,6,7]>
170 # data parallel: <group 0: [0,4]>, <group 1: [1,5]>, <group 2: [2,6]>, <group 3: [3,7]>
171 # assert args.world_size == args.data_group_size * args.pipeline_group_size
172 global _DATA_PARALLEL_COMM
173 global _PIPELINE_PARALLEL_COMM
174 global _DATA_PARALLEL_RANK
175 global _PIPELINE_PARALLEL_RANK
176 global _DATA_PARALLEL_WORLD_SIZE
177 global _PIPELINE_PARALLEL_WORLD_SIZE
178
179 if args.data_group_size != 1:
180
181 dp_backend = getattr(args, 'dp_backend', 'gloo')
182 if dp_backend == 'nccl':
183
184 raise Exception('NCCL cannot reinit.')
185
186 elif dp_backend == 'gloo':
187
188 for i in range(args.pipeline_group_size):
189 ranks = [rank for rank in range(i, args.world_size, args.pipeline_group_size)]
190 print(args.rank, ranks)
191 data_group = torch.distributed.new_group(ranks, backend='gloo')
192 if args.rank in ranks:
193 def to_global_rank(dp_rank):
194 rank = _PIPELINE_PARALLEL_RANK + dp_rank * args.pipeline_group_size
195 # print(f"{dp_rank} --> {rank}")
196 return rank
197 _DATA_PARALLEL_COMM = TorchCommunicator(
198 data_group, to_global_rank=to_global_rank,
199 dp_rank=_DATA_PARALLEL_RANK,
200 comm_group_size=args.data_group_size,)
201
202 else:
203 assert False
204
205 print('######## dp comm reinit done!! ########')

Callers

nothing calls this directly

Calls 2

default_initFunction · 0.85
TorchCommunicatorClass · 0.85

Tested by

no test coverage detected