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

Method move

deepspeed/module_inject/layers.py:651–674  ·  view source on GitHub ↗
(self, tensor)

Source from the content-addressed store, hash-verified

649 is not None, dtype)
650
651 def move(self, tensor):
652 # TODO: consider the timing of deletion
653 # to save host resources when DP > 1。
654
655 # keep_module_on_host is used to keep the module on the host. Checkpoints are loaded to the host first (in some
656 # cases it can be done from the disk even to prevent filling host's memory), thus no need to create a new copy.
657 if tensor.is_meta:
658 # Keep tensor in meta device if tensor is meta.
659 return tensor
660 else:
661 device = 'cpu' if self.__class__.keep_module_on_host else get_accelerator().current_device_name()
662 return_new_copy = not self.__class__.keep_module_on_host
663
664 # Using new tensors help in freeing memory (after split for example) was done before by calling clone().
665 # Using copy=True instead of clone() will help in case of cpu --> cpu.
666 # Otherwise to() will not create a new copy for the view of the full tensor, and it will not be de-referenced.
667 cloned_tensor = tensor.to(device, copy=return_new_copy)
668
669 if return_new_copy:
670 # free the memory of the original tensor to reduce memory peak
671 # Equivalent to directly deleting the tensor reference outside the function.
672 # see https://github.com/microsoft/DeepSpeed/pull/4353
673 tensor.data = torch.empty(0, device=tensor.device)
674 return cloned_tensor
675
676
677def configure_tensor_parallel_runtime(config):

Callers 12

_tp_partitionMethod · 0.80
uneven_partitionMethod · 0.80
uneven_partitionMethod · 0.80
_tp_partitionMethod · 0.80
_tp_partitionMethod · 0.80
_tp_partitionMethod · 0.80
_tp_partitionMethod · 0.80
_tp_partitionMethod · 0.80
_tp_partitionMethod · 0.80
_tp_partitionMethod · 0.80
_tp_partitionMethod · 0.80

Calls 3

get_acceleratorFunction · 0.90
current_device_nameMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected