MCPcopy Index your code
hub / github.com/modelscope/modelscope / create_device

Function create_device

modelscope/utils/device.py:85–105  ·  view source on GitHub ↗

create torch device Args: device_name (str): cpu, gpu, gpu:0, cuda:0 etc.

(device_name)

Source from the content-addressed store, hash-verified

83
84
85def create_device(device_name):
86 """ create torch device
87
88 Args:
89 device_name (str): cpu, gpu, gpu:0, cuda:0 etc.
90 """
91 import torch
92 device_type, device_id = verify_device(device_name)
93 use_cuda = False
94 if device_type == Devices.gpu:
95 use_cuda = True
96 if not torch.cuda.is_available():
97 logger.info('cuda is not available, using cpu instead.')
98 use_cuda = False
99
100 if use_cuda:
101 device = torch.device(f'cuda:{device_id}')
102 else:
103 device = torch.device('cpu')
104
105 return device
106
107
108def get_device():

Callers 15

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
_init_swiftMethod · 0.90
__init__Method · 0.90
__init__Method · 0.90
get_deviceMethod · 0.90
trainMethod · 0.90

Calls 3

verify_deviceFunction · 0.85
infoMethod · 0.80
deviceMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…