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

Method move

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

Source from the content-addressed store, hash-verified

540 is not None, dtype)
541
542 def move(self, tensor):
543 # TODO: consider the timing of deletion
544 # to save host resources when DP > 1。
545
546 # keep_module_on_host is used to keep the module on the host. Checkpoints are loaded to the host first (in some
547 # cases it can be done from the disk even to prevent filling host's memory), thus no need to create a new copy.
548 if tensor.is_meta:
549 # Keep tensor in meta device if tensor is meta.
550 return tensor
551 else:
552 device = 'cpu' if self.__class__.keep_module_on_host else get_accelerator().current_device_name()
553 return_new_copy = not self.__class__.keep_module_on_host
554
555 # Using new tensors help in freeing memory (after split for example) was done before by calling clone().
556 # Using copy=True instead of clone() will help in case of cpu --> cpu.
557 # Otherwise to() will not create a new copy for the view of the full tensor, and it will not be de-referenced.
558 cloned_tensor = tensor.to(device, copy=return_new_copy)
559
560 if return_new_copy:
561 # free the memory of the original tensor to reduce memory peak
562 # Equivalent to directly deleting the tensor reference outside the function.
563 # see https://github.com/microsoft/DeepSpeed/pull/4353
564 tensor.data = torch.empty(0, device=tensor.device)
565 return cloned_tensor
566
567
568def configure_tensor_parallel_runtime(config):

Callers 10

_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

Calls 3

get_acceleratorFunction · 0.90
current_device_nameMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected