| 713 | return tensor_part, partition |
| 714 | |
| 715 | def full(self, device=None): |
| 716 | if device is None: |
| 717 | device = self.orig_device |
| 718 | |
| 719 | # Allocate the full tensor as a flat buffer. |
| 720 | full_numel = prod(self.full_size()) |
| 721 | flat_tensor = torch.zeros([full_numel], dtype=self.local_data.dtype, device=device) |
| 722 | if self.even_split: |
| 723 | # Collect the full tensor |
| 724 | dist.all_gather_into_tensor(flat_tensor, self.local_data, group=self.group) |
| 725 | else: |
| 726 | for part_id in range(self.num_parts): |
| 727 | part_size = self.partition[part_id + 1] - self.partition[part_id] |
| 728 | buf = flat_tensor.narrow(0, start=self.partition[part_id], length=part_size) |
| 729 | if part_id == self.rank: |
| 730 | buf.copy_(self.local_data) |
| 731 | dist.broadcast(buf, part_id, self.group) |
| 732 | return flat_tensor.view(self.full_size()).clone().detach() |
| 733 | |
| 734 | def to_meta(self): |
| 735 | """Returns a torch.LongTensor that encodes partitioning information. |