Exemple #1
0
 def decompress(self,
                data: bytearray,
                offset: Offset = None) -> torch.Tensor:
     offset = offset or Offset()
     torch.manual_seed(self.seed)
     shape = unpack_tensor_shape(data, offset)
     if len(shape) <= 1:
         return unpack_tensor(data, offset)
     else:
         p = unpack_tensor(data, offset)
         q = unpack_tensor(data, offset)
         return torch.matmul(p, q.t()).view(shape)
Exemple #2
0
    def decompress(self, data: bytearray,
                   offset: Offset = None) -> torch.Tensor:
        offset = offset or Offset()

        # unpack tensor shape
        shape = unpack_tensor_shape(data, offset)
        # unpack sparse indices and value
        tensor_indices = unpack_tensor(data, offset)
        tensor_data = unpack_tensor(data, offset)

        tensor = torch.zeros(int(np.prod(shape)))
        tensor.index_copy_(0, tensor_indices, tensor_data)
        tensor = tensor.reshape(list(shape))

        return tensor
Exemple #3
0
    def decompress(self,
                   data: bytearray,
                   offset: Offset = None) -> torch.Tensor:
        offset = offset or Offset()

        shape = unpack_tensor_shape(data, offset)
        if len(shape) <= 1:
            return unpack_tensor(data, offset)
        else:
            mean = unpack_float32(data, offset)
            S = unpack_tensor(data, offset)
            U = unpack_tensor(data, offset)
            V = unpack_tensor(data, offset)
            return (torch.mm(torch.mm(U, torch.diag(S)), V.t()) +
                    mean).view(shape)
Exemple #4
0
    def decompress(self,
                   data: bytearray,
                   offset: Offset = None) -> torch.Tensor:
        offset = offset or Offset()

        # unpack original tensor shape
        shape = unpack_tensor_shape(data, offset)

        # unpack indices and data
        indices = unpack_tensor(data, offset)
        values = unpack_tensor(data, offset)

        # re-construct tensor
        tensor = torch.zeros(shape)
        tensor.index_copy_(0, indices, values)

        return tensor
Exemple #5
0
    def decompress(self,
                   data: bytearray,
                   offset: Offset = None) -> torch.Tensor:
        offset = offset or Offset()

        # unpack original tensor shape
        shape = unpack_tensor_shape(data, offset)
        # unpack compressed tensor
        tensor_data = unpack_tensor(data, offset)

        # restore random mask
        k = math.ceil(self.ratio * np.prod(shape))
        torch.manual_seed(self.seed)
        mask = torch.randperm(int(np.prod(shape))).cuda() < k
        idx = mask.int().sort(descending=True).indices

        # restore tensor
        tensor = torch.zeros(int(np.prod(shape)))
        tensor.index_copy_(0, idx[:k].cpu(), tensor_data)
        tensor = tensor.reshape(shape)

        return tensor
Exemple #6
0
 def decompress(self,
                data: bytearray,
                offset: Offset = None) -> torch.Tensor:
     offset = offset or Offset()
     return unpack_tensor(data, offset)