-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheckpoint_utils.py
46 lines (35 loc) · 1.28 KB
/
checkpoint_utils.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
import logging
from os import fspath
from pathlib import Path
import pickle
def path_construct_fn(args, search_mode):
dir = 'checkpoints/{}/'.format(args.dataset)
Path(dir).mkdir(parents=True, exist_ok=True)
if not search_mode:
if args.SC:
filename = dir + "{}_{}_SC.pkl".format(args.model, args.prompt_style)
else:
filename = dir + "{}_{}.pkl".format(args.model, args.prompt_style)
else:
filename = dir + "{}_{}_{}_{}.pkl".format(args.model,
args.prompt_style,
args.search_style,
args.reward_types)
return filename
def save_checkpoint(args, state_dict):
if args.search_style == "none":
search_mode = False
else:
search_mode = True
filename = path_construct_fn(args, search_mode)
with open(filename, 'wb') as outfile:
pickle.dump(state_dict, outfile)
def load_checkpoint(args):
if args.search_style == "none":
search_mode = False
else:
search_mode = True
filename = path_construct_fn(args, search_mode)
with open(filename, 'rb') as outfile:
state_dict = pickle.load(outfile)
return state_dict