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