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

Method sparse_allreduce

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

Source from the content-addressed store, hash-verified

4112 return sparse_list
4113
4114 def sparse_allreduce(self, sparse, dp_group, dp_world_size=None):
4115 original_data_type = sparse.values.dtype
4116 if self.communication_data_type != sparse.values.dtype:
4117 if self.communication_data_type in (torch.float16, torch.bfloat16):
4118 indices = sparse.indices.to(torch.int32)
4119 else:
4120 indices = sparse.indices
4121 values = sparse.values.to(self.communication_data_type)
4122 else:
4123 indices = sparse.indices
4124 values = sparse.values
4125
4126 if dp_world_size is None:
4127 dp_world_size = dist.get_world_size(group=dp_group)
4128 if self.gradient_average:
4129 if self.postscale_gradients():
4130 values.mul_(self.gradient_predivide_factor() / (dp_world_size))
4131 else:
4132 values.mul_(1. / (dp_world_size))
4133
4134 indices_device_list = self.sparse_all_gather(indices, dp_group)
4135 values_device_list = self.sparse_all_gather(values, dp_group)
4136
4137 sparse.indices = torch.cat(indices_device_list).to(torch.long)
4138 sparse.values = torch.cat(values_device_list).to(original_data_type)
4139 return sparse
4140
4141 def sparse_all_gather(self, value, dp_group):
4142 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