-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuda_test.py
40 lines (28 loc) · 1.26 KB
/
cuda_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import torch
import torchvision
import os
from tools.logistics import get_project_root_path
from tools.network_architectures import load_params
from architectures.MLP import LayerwiseClassifiers
print(f'torch version: {torch.__version__}')
print(f'torchvision version: {torchvision.__version__}')
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
print(f'device: {device}')
# print('memory_stats')
# print(torch.cuda.memory_stats(device))
# print('memory_summary')
# print(torch.cuda.memory_summary(device))
os.system('nvidia-smi')
os.system('kill -9 ')
path_root = get_project_root_path()
path_sdn = os.path.join(path_root, 'TrojAI-data', 'round1-dataset-train', 'models', 'id-00000001')
path_load = os.path.join(path_root, 'TrojAI-data', 'round1-dataset-train', 'models', 'id-00000001', 'ics_train100_test0_bs25', 'last')
print('loading model params')
model_params = load_params(path_sdn, 'ics_train100_test0_bs25', epoch=-1)
print('creating LayerwiseClassifiers object')
model = LayerwiseClassifiers(model_params['output_params'], model_params['architecture_params'])
print('loading model state')
model_state = torch.load(path_load, map_location=device)
print('loading state to model')
model.load_state_dict(model_state, strict=False)
print('script ended')