|
|
@ -58,6 +58,10 @@ class ColoTensor(object):
|
|
|
|
def shape(self):
|
|
|
|
def shape(self):
|
|
|
|
return torch.Size(self._size)
|
|
|
|
return torch.Size(self._size)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def device(self):
|
|
|
|
|
|
|
|
return self._torch_tensor.device
|
|
|
|
|
|
|
|
|
|
|
|
def size(self, dim=None):
|
|
|
|
def size(self, dim=None):
|
|
|
|
if dim is None:
|
|
|
|
if dim is None:
|
|
|
|
return self.shape
|
|
|
|
return self.shape
|
|
|
@ -105,7 +109,7 @@ class ColoTensor(object):
|
|
|
|
device=self._device)
|
|
|
|
device=self._device)
|
|
|
|
return self._torch_tensor
|
|
|
|
return self._torch_tensor
|
|
|
|
|
|
|
|
|
|
|
|
def set_spec(self, spec: str, lazy_shard: bool=False) -> None:
|
|
|
|
def set_spec(self, spec: str, lazy_shard: bool = False) -> None:
|
|
|
|
self._shard_spec = spec
|
|
|
|
self._shard_spec = spec
|
|
|
|
if lazy_shard == False:
|
|
|
|
if lazy_shard == False:
|
|
|
|
self._shard()
|
|
|
|
self._shard()
|
|
|
@ -121,8 +125,8 @@ class ColoTensor(object):
|
|
|
|
# Reshape to get shard for this rank and we don't want autograd
|
|
|
|
# Reshape to get shard for this rank and we don't want autograd
|
|
|
|
# recording here for the narrow op and 'local_shard' should be a
|
|
|
|
# recording here for the narrow op and 'local_shard' should be a
|
|
|
|
# leaf variable in the autograd graph.
|
|
|
|
# leaf variable in the autograd graph.
|
|
|
|
self._torch_tensor = self._torch_tensor.narrow(dim,
|
|
|
|
self._torch_tensor = self._torch_tensor.narrow(dim, local_rank * chunk_size, chunk_size).detach(
|
|
|
|
local_rank * chunk_size, chunk_size).detach().contiguous() # TODO Shall we clone() here since detach() will point to the old tensor?
|
|
|
|
).contiguous() # TODO Shall we clone() here since detach() will point to the old tensor?
|
|
|
|
self._torch_tensor.requires_grad = self._requires_grad
|
|
|
|
self._torch_tensor.requires_grad = self._requires_grad
|
|
|
|
self._size = self._torch_tensor.size()
|
|
|
|
self._size = self._torch_tensor.size()
|
|
|
|
self._device = device # TODO A `fake` device now because torch_tensor.device always = cpu
|
|
|
|
self._device = device # TODO A `fake` device now because torch_tensor.device always = cpu
|
|
|
|