r""" Gets the current available device.
()
| 28 | |
| 29 | |
| 30 | def get_current_device() -> 'torch.device': |
| 31 | r""" |
| 32 | Gets the current available device. |
| 33 | """ |
| 34 | if is_torch_xpu_available(): |
| 35 | device = 'xpu:{}'.format(os.environ.get('LOCAL_RANK', '0')) |
| 36 | elif is_torch_npu_available(): |
| 37 | device = 'npu:{}'.format(os.environ.get('LOCAL_RANK', '0')) |
| 38 | elif is_torch_mps_available(): |
| 39 | device = 'mps:{}'.format(os.environ.get('LOCAL_RANK', '0')) |
| 40 | elif is_torch_cuda_available(): |
| 41 | device = 'cuda:{}'.format(os.environ.get('LOCAL_RANK', '0')) |
| 42 | else: |
| 43 | device = 'cpu' |
| 44 | |
| 45 | return torch.device(device) |
| 46 | |
| 47 | |
| 48 | def set_device(device_id) -> str: |
no test coverage detected