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

Method move

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

Source from the content-addressed store, hash-verified

404 is not None, dtype)
405
406 def move(self, tensor):
407 # TODO: consider the timing of deletion
408 # to save host resources when DP > 1。
409
410 # keep_module_on_host is used to keep the module on the host. Checkpoints are loaded to the host first (in some
411 # cases it can be done from the disk even to prevent filling host's memory), thus no need to create a new copy.
412 if tensor.is_meta:
413 # Keep tensor in meta device if tensor is meta.
414 return tensor
415 else:
416 device = 'cpu' if self.__class__.keep_module_on_host else get_accelerator().current_device_name()
417 return_new_copy = not self.__class__.keep_module_on_host
418
419 # Using new tensors help in freeing memory (after split for example) was done before by calling clone().
420 # Using copy=True instead of clone() will help in case of cpu --> cpu.
421 # Otherwise to() will not create a new copy for the view of the full tensor, and it will not be de-referenced.
422 cloned_tensor = tensor.to(device, copy=return_new_copy)
423
424 if return_new_copy:
425 # free the memory of the original tensor to reduce memory peak
426 # Equivalent to directly deleting the tensor reference outside the function.
427 # see https://github.com/microsoft/DeepSpeed/pull/4353
428 tensor.data = torch.empty(0, device=tensor.device)
429 return cloned_tensor
430
431
432def configure_tensor_parallel_runtime(config):

Callers 11

_tp_partitionMethod · 0.80
uneven_partitionMethod · 0.80
_tp_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

Calls 3

get_acceleratorFunction · 0.90
current_device_nameMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected