(self, tensor)
| 446 | is not None, dtype) |
| 447 | |
| 448 | def move(self, tensor): |
| 449 | # TODO: consider the timing of deletion |
| 450 | # to save host resources when DP > 1。 |
| 451 | |
| 452 | # keep_module_on_host is used to keep the module on the host. Checkpoints are loaded to the host first (in some |
| 453 | # cases it can be done from the disk even to prevent filling host's memory), thus no need to create a new copy. |
| 454 | if tensor.is_meta: |
| 455 | # Keep tensor in meta device if tensor is meta. |
| 456 | return tensor |
| 457 | else: |
| 458 | device = 'cpu' if self.__class__.keep_module_on_host else get_accelerator().current_device_name() |
| 459 | return_new_copy = not self.__class__.keep_module_on_host |
| 460 | |
| 461 | # Using new tensors help in freeing memory (after split for example) was done before by calling clone(). |
| 462 | # Using copy=True instead of clone() will help in case of cpu --> cpu. |
| 463 | # Otherwise to() will not create a new copy for the view of the full tensor, and it will not be de-referenced. |
| 464 | cloned_tensor = tensor.to(device, copy=return_new_copy) |
| 465 | |
| 466 | if return_new_copy: |
| 467 | # free the memory of the original tensor to reduce memory peak |
| 468 | # Equivalent to directly deleting the tensor reference outside the function. |
| 469 | # see https://github.com/microsoft/DeepSpeed/pull/4353 |
| 470 | tensor.data = torch.empty(0, device=tensor.device) |
| 471 | return cloned_tensor |
| 472 | |
| 473 | |
| 474 | def configure_tensor_parallel_runtime(config): |
no test coverage detected