11import argparse
22import copy
33import os
4+ import statistics
45
56import ray
67import yaml
@@ -22,6 +23,9 @@ def parse_args():
2223 parser .add_argument ("-per" , "--gpu-percent" , type = float , default = 0.5 )
2324 parser .add_argument ("-topn" , "--topn" , default = 5 , type = int )
2425 parser .add_argument ("-earlystop" , default = "ucir" , type = str )
26+ parser .add_argument ("-options" , "--options" , default = None , nargs = "+" )
27+ parser .add_argument ("-threads" , default = 2 , type = int )
28+ parser .add_argument ("-resume" , default = False , action = "store_true" )
2529
2630 return parser .parse_args ()
2731
@@ -31,15 +35,17 @@ def train_func(config, reporter):
3135 train_args .update (config )
3236
3337 train_args ["device" ] = [0 ]
34- train_args ["threads" ] = 2
35- train_args ["logging" ] = "critical"
38+ train_args ["logging" ] = "warning"
3639 train_args ["no_progressbar" ] = True
3740
38- for i , (avg_inc_acc , last_acc , _ ) in enumerate (inclearn .train .train (train_args )):
39- last_acc = last_acc * 100
41+ all_acc = []
42+ for i , (avg_inc_acc , last_acc , _ , is_last ) in enumerate (inclearn .train .train (train_args )):
43+ if is_last :
44+ all_acc .append (avg_inc_acc )
4045
41- reporter (avg_inc_acc = avg_inc_acc )
42- return avg_inc_acc
46+ total_avg_inc_acc = statistics .mean (all_acc )
47+ reporter (avg_inc_acc = total_avg_inc_acc )
48+ return total_avg_inc_acc
4349
4450
4551def _get_abs_path (path ):
@@ -61,6 +67,7 @@ def analyse_ray_dump(ray_directory, topn):
6167 elif col == "avg_inc_acc" :
6268 result_index = index
6369
70+ print ("Ray config: {}" .format (ray_directory ))
6471 print ("Best Config:" )
6572 print (
6673 "avg_inc_acc: {} with {}." .format (
@@ -90,7 +97,6 @@ def _get_line_results(df, row_index, mapping):
9097 for col , index in mapping .items ():
9198 if col .startswith ("var:" ):
9299 col = col [4 :]
93- 94100 results [col ] = df .iloc [row_index ][index ]
95101 return results
96102
@@ -109,7 +115,7 @@ def set_seen_gpus(gpus):
109115 os .environ ["CUDA_VISIBLE_DEVICES" ] = "," .join (gpus )
110116
111117
112- def get_tune_config (tune_options ):
118+ def get_tune_config (tune_options , options_files ):
113119 with open (tune_options ) as f :
114120 options = yaml .load (f , Loader = yaml .FullLoader )
115121
@@ -120,6 +126,10 @@ def get_tune_config(tune_options):
120126 else :
121127 config [k .replace ("var:" , "" )] = tune .grid_search (v )
122128
129+ if options_files is not None :
130+ print ("Options files: {}" .format (options_files ))
131+ config ["options" ] = [os .path .realpath (op ) for op in options_files ]
132+ 123133 return config
124134
125135
@@ -129,7 +139,8 @@ def main():
129139 set_seen_gpus (args .gpus )
130140
131141 if args .tune is not None :
132- config = get_tune_config (args .tune )
142+ config = get_tune_config (args .tune , args .options )
143+ config ["threads" ] = args .threads
133144 ray .init ()
134145 tune .run (
135146 train_func ,
@@ -140,11 +151,15 @@ def main():
140151 "cpu" : 2 ,
141152 "gpu" : args .gpu_percent
142153 },
143- local_dir = args .ray_directory
154+ local_dir = args .ray_directory ,
155+ resume = args .resume
144156 )
145157
146158 args .ray_directory = os .path .join (args .ray_directory , args .tune .rstrip ("/" ).split ("/" )[- 1 ])
147159
160+ if args .tune is not None :
161+ print ("\n \n " , args .tune , "\n \n " )
162+ 148163 if args .ray_directory is not None :
149164 best_config = analyse_ray_dump (_get_abs_path (args .ray_directory ), args .topn )
150165
0 commit comments