r""" Clean memory on the specified device, will be called from training scripts.
(device: Optional[Union[str, torch.device]])
| 40 | |
| 41 | |
| 42 | def clean_memory_on_device(device: Optional[Union[str, torch.device]]): |
| 43 | r""" |
| 44 | Clean memory on the specified device, will be called from training scripts. |
| 45 | """ |
| 46 | gc.collect() |
| 47 | if device is None: |
| 48 | return |
| 49 | if isinstance(device, str): |
| 50 | device = torch.device(device) |
| 51 | # device may "cuda" or "cuda:0", so we need to check the type of device |
| 52 | if device.type == "cuda": |
| 53 | torch.cuda.empty_cache() |
| 54 | if device.type == "xpu": |
| 55 | torch.xpu.empty_cache() |
| 56 | if device.type == "mps": |
| 57 | torch.mps.empty_cache() |
| 58 | |
| 59 | |
| 60 | def synchronize_device(device: Optional[Union[str, torch.device]]): |
no test coverage detected