-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_init.py
More file actions
24 lines (19 loc) · 695 Bytes
/
_init.py
File metadata and controls
24 lines (19 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import random
import torch
class Config:
def __init__(self):
self.seed = None
self.device_id = torch.cuda.current_device()
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
def set_seed(self, seed: int = None):
if seed is None:
seed = random.randint(0, 100000)
self.seed = seed
return seed
if __name__ == '__main__':
print(torch.cuda.is_available())
print(torch.version.cuda)
print(torch.cuda.get_device_name(torch.cuda.current_device()))
print(torch.device("cuda" if torch.cuda.is_available() else "cpu"))
x = torch.tensor([1, 2, 3], device=torch.device('cuda'))
print(x)