-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.py
54 lines (43 loc) · 1.68 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
####################################################################################################
# HELP: hardware-adaptive efficient latency prediction for nas via meta-learning, NeurIPS 2021
# Hayeon Lee, Sewoong Lee, Song Chong, Sung Ju Hwang
# github: https://github.com/HayeonLee/HELP, email: [email protected]
####################################################################################################
import os
import torch
from parser import get_parser
from help import HELP
def main(args):
set_seed(args)
args = set_gpu(args)
args = set_path(args)
print(f'==> mode is [{args.mode}] ...')
model = HELP(args)
if args.mode == 'meta-train':
model.meta_train()
elif args.mode == 'meta-test':
model.test_predictor()
elif args.mode == 'nas':
model.nas()
def set_seed(args):
# Set the random seed for reproducible experiments
torch.manual_seed(args.seed)
torch.cuda.manual_seed(args.seed)
def set_gpu(args):
os.environ['CUDA_VISIBLE_DEVICES']= '-1' if args.gpu == None else args.gpu
args.gpu = int(args.gpu)
return args
def set_path(args):
args.data_path = os.path.join(
args.main_path, 'data', args.search_space)
args.save_path = os.path.join(
args.save_path, args.search_space)
args.save_path = os.path.join(args.save_path, args.exp_name)
if not os.path.exists(args.save_path):
os.makedirs(args.save_path)
if args.mode != 'nas':
os.makedirs(os.path.join(args.save_path, 'checkpoint'))
print(f'==> save path is [{args.save_path}] ...')
return args
if __name__ == '__main__':
main(get_parser())