MCPcopy Create free account
hub / github.com/PKU-Alignment/align-anything / get_current_device

Function get_current_device

align_anything/utils/device_utils.py:30–45  ·  view source on GitHub ↗

r""" Gets the current available device.

()

Source from the content-addressed store, hash-verified

28
29
30def 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
48def set_device(device_id) -> str:

Callers 4

mainFunction · 0.90
text_modal_cli.pyFile · 0.90
omni_modal_cli.pyFile · 0.90
sft.pyFile · 0.90

Calls 2

getMethod · 0.80
deviceMethod · 0.80

Tested by

no test coverage detected