MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / sparse_allreduce

Method sparse_allreduce

deepspeed/runtime/engine.py:4032–4057  ·  view source on GitHub ↗
(self, sparse, dp_group, dp_world_size=None)

Source from the content-addressed store, hash-verified

4030 return sparse_list
4031
4032 def sparse_allreduce(self, sparse, dp_group, dp_world_size=None):
4033 original_data_type = sparse.values.dtype
4034 if self.communication_data_type != sparse.values.dtype:
4035 if self.communication_data_type in (torch.float16, torch.bfloat16):
4036 indices = sparse.indices.to(torch.int32)
4037 else:
4038 indices = sparse.indices
4039 values = sparse.values.to(self.communication_data_type)
4040 else:
4041 indices = sparse.indices
4042 values = sparse.values
4043
4044 if dp_world_size is None:
4045 dp_world_size = dist.get_world_size(group=dp_group)
4046 if self.gradient_average:
4047 if self.postscale_gradients():
4048 values.mul_(self.gradient_predivide_factor() / (dp_world_size))
4049 else:
4050 values.mul_(1. / (dp_world_size))
4051
4052 indices_device_list = self.sparse_all_gather(indices, dp_group)
4053 values_device_list = self.sparse_all_gather(values, dp_group)
4054
4055 sparse.indices = torch.cat(indices_device_list).to(torch.long)
4056 sparse.values = torch.cat(values_device_list).to(original_data_type)
4057 return sparse
4058
4059 def sparse_all_gather(self, value, dp_group):
4060 my_size = torch.LongTensor([value.size()[0]]).to(self.device)

Callers 1

Calls 5

postscale_gradientsMethod · 0.95
sparse_all_gatherMethod · 0.95
get_world_sizeMethod · 0.80
toMethod · 0.45

Tested by

no test coverage detected