MCPcopy Create free account
hub / github.com/modelscope/modelscope / test_create_device_torch

Method test_create_device_torch

tests/utils/test_device.py:56–81  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

54 verify_device(None)
55
56 def test_create_device_torch(self):
57 if torch.cuda.is_available():
58 target_device_type = 'cuda'
59 target_device_index = 0
60 else:
61 target_device_type = 'cpu'
62 target_device_index = None
63 device = create_device('gpu')
64 self.assertTrue(isinstance(device, torch.device))
65 self.assertTrue(device.type == target_device_type)
66 self.assertTrue(device.index == target_device_index)
67
68 device = create_device('gpu:0')
69 self.assertTrue(isinstance(device, torch.device))
70 self.assertTrue(device.type == target_device_type)
71 self.assertTrue(device.index == target_device_index)
72
73 device = create_device('cuda')
74 self.assertTrue(device.type == target_device_type)
75 self.assertTrue(isinstance(device, torch.device))
76 self.assertTrue(device.index == target_device_index)
77
78 device = create_device('cuda:0')
79 self.assertTrue(isinstance(device, torch.device))
80 self.assertTrue(device.type == target_device_type)
81 self.assertTrue(device.index == target_device_index)
82
83 def test_device_placement_cpu(self):
84 with device_placement(Frameworks.torch, 'cpu'):

Callers

nothing calls this directly

Calls 1

create_deviceFunction · 0.90

Tested by

no test coverage detected