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

Method full

deepspeed/runtime/utils.py:790–807  ·  view source on GitHub ↗
(self, device=None)

Source from the content-addressed store, hash-verified

788 return tensor_part, partition
789
790 def full(self, device=None):
791 if device is None:
792 device = self.orig_device
793
794 # Allocate the full tensor as a flat buffer.
795 full_numel = prod(self.full_size())
796 flat_tensor = torch.zeros([full_numel], dtype=self.local_data.dtype, device=device)
797 if self.even_split:
798 # Collect the full tensor
799 dist.all_gather_into_tensor(flat_tensor, self.local_data, group=self.group)
800 else:
801 for part_id in range(self.num_parts):
802 part_size = self.partition[part_id + 1] - self.partition[part_id]
803 buf = flat_tensor.narrow(0, start=self.partition[part_id], length=part_size)
804 if part_id == self.rank:
805 buf.copy_(self.local_data)
806 dist.broadcast(buf, part_id, self.group)
807 return flat_tensor.view(self.full_size()).clone().detach()
808
809 def to_meta(self):
810 """Returns a torch.LongTensor that encodes partitioning information.

Calls 4

full_sizeMethod · 0.95
copy_Method · 0.45
broadcastMethod · 0.45