@@ -51,6 +51,9 @@ def get_args():
5151 parser .add_argument ("--nodelete-failed" ,
5252 help = "do not delete failed results (submission checker will fail)" ,
5353 default = False , action = "store_true" )
54+ parser .add_argument ("--keep-structure" ,
55+ help = "keep folder structure (newer versions of submission checker might fail)" ,
56+ default = False , action = "store_true" )
5457
5558 parser .add_argument (
5659 "--version" ,
@@ -96,7 +99,7 @@ def delete_empty_dirs(src):
9699 return False
97100
98101
99- def copy_submission_dir (src , dst , filter_submitter ):
102+ def copy_submission_dir (src , dst , filter_submitter , keep_structure = True ):
100103 """
101104 Copies the submission tree to output directory for processing
102105 """
@@ -106,10 +109,25 @@ def copy_submission_dir(src, dst, filter_submitter):
106109 for submitter in next (os .walk (os .path .join (src , division )))[1 ]:
107110 if filter_submitter and submitter != filter_submitter :
108111 continue
109- shutil .copytree (
110- os .path .join (src , division , submitter ),
111- os .path .join (dst , division , submitter ),
112- )
112+ if keep_structure :
113+ shutil .copytree (
114+ os .path .join (src , division , submitter ),
115+ os .path .join (dst , division , submitter ),
116+ )
117+ else :
118+ for object in os .listdir (os .path .join (src , division , submitter )):
119+ if os .path .isfile (os .path .join (src , division , submitter , object )):
120+ shutil .copyfile (
121+ os .path .join (src , division , submitter , object ),
122+ os .path .join (dst , division , submitter , object )
123+ )
124+ elif os .path .isdir (os .path .join (src , division , submitter , object )):
125+ target_dir = "results" if object in ["compliance" , "measurements" ] else object
126+ shutil .copytree (
127+ os .path .join (src , division , submitter , object ),
128+ os .path .join (dst , division , submitter , target_dir ),
129+ dirs_exist_ok = True
130+ )
113131
114132
115133def change_first_directory_to_open (path ):
@@ -247,8 +265,7 @@ def clean_invalid_results(args, log_path, config, system_desc, system_json,
247265
248266 compliance_is_valid = True
249267 if is_closed_or_network :
250- compliance_dir = change_folder_name_in_path (
251- scenario_path , "results" , "compliance" )
268+ compliance_dir = scenario_path
252269 if not checker .check_compliance_dir (
253270 compliance_dir ,
254271 mlperf_model ,
@@ -262,12 +279,10 @@ def clean_invalid_results(args, log_path, config, system_desc, system_json,
262279
263280 is_valid = accuracy_is_valid and perf_is_valid and compliance_is_valid
264281 if not is_valid : # Remove the scenario result
265- scenario_measurements_path = change_folder_name_in_path (
266- scenario_path , "results" , "measurements" )
282+ scenario_measurements_path = scenario_path
267283 if scenario in [
268284 "Offline" , "MultiStream" ] and (not accuracy_is_valid or not perf_is_valid ) or division == "open" : # they can be inferred
269- scenario_compliance_path = change_folder_name_in_path (
270- scenario_path , "results" , "compliance" )
285+ scenario_compliance_path = scenario_path
271286 log .warning (
272287 f"{ scenario } scenario result is invalid for { system_desc } : { model } in { division } division. Accuracy: { accuracy_is_valid } , Performance: { perf_is_valid } . Removing..." )
273288 if os .path .exists (scenario_path ):
@@ -278,10 +293,8 @@ def clean_invalid_results(args, log_path, config, system_desc, system_json,
278293 shutil .rmtree (scenario_compliance_path )
279294 elif division in ["closed" , "network" ]:
280295 model_results_path = os .path .dirname (scenario_path )
281- model_measurements_path = change_folder_name_in_path (
282- model_results_path , "results" , "measurements" )
283- model_compliance_path = change_folder_name_in_path (
284- model_results_path , "results" , "compliance" )
296+ model_measurements_path = model_results_path
297+ model_compliance_path = model_results_path
285298 model_code_path = os .path .join (
286299 change_folder_name_in_path (
287300 log_path , "results" , "code" ), model )
@@ -301,8 +314,7 @@ def clean_invalid_results(args, log_path, config, system_desc, system_json,
301314 f"{ scenario } scenario result is invalid for { system_desc } : { model } in { division } and open divisions. Accuracy: { accuracy_is_valid } , Performance: { perf_is_valid } . Removing it..." )
302315 if os .path .exists (scenario_path ):
303316 shutil .rmtree (scenario_path )
304- scenario_measurements_path = change_folder_name_in_path (
305- scenario_path , "results" , "measurements" )
317+ scenario_measurements_path = scenario_path
306318 if os .path .exists (scenario_measurements_path ):
307319 shutil .rmtree (scenario_measurements_path )
308320 if not os .path .exists (target_results_path ):
@@ -367,9 +379,7 @@ def infer_scenario_results(args, config):
367379 continue
368380
369381 # process results
370- for directory in ["results" , "measurements" ] + \
371- (["compliance" ] if division == "closed" else []):
372-
382+ for directory in ["results" ]:
373383 log_path = os .path .join (division , submitter , directory )
374384 if not os .path .exists (log_path ):
375385 log .error ("no submission in %s" , log_path )
@@ -550,7 +560,7 @@ def main():
550560 log .error (f"output directory { args .output } already exists" )
551561 sys .exit (1 )
552562 os .makedirs (args .output )
553- copy_submission_dir (args .input , args .output , args .submitter )
563+ copy_submission_dir (args .input , args .output , args .submitter , args . keep_structure )
554564 src_dir = args .output
555565
556566 config = checker .Config (
@@ -574,3 +584,6 @@ def main():
574584
575585if __name__ == "__main__" :
576586 sys .exit (main ())
587+
588+ if __name__ == "__main__" :
589+ sys .exit (main ())
0 commit comments