(args, multiple_choice_tasks=MULTIPLE_CHOICE_TASKS, free_form_tasks=FREE_FORM_TASKS)
| 208 | |
| 209 | |
| 210 | def main(args, multiple_choice_tasks=MULTIPLE_CHOICE_TASKS, free_form_tasks=FREE_FORM_TASKS): |
| 211 | |
| 212 | run_multiple_choice = args.task == 'all' or args.task == 'multiple_choice' |
| 213 | run_free_form = args.task == 'all' or args.task == 'free_form' |
| 214 | |
| 215 | path_split = args.pretrained_path[0].split('/') if isinstance(args.pretrained_path,list) else args.pretrained_path.split('/') |
| 216 | if path_split[-1] == '': |
| 217 | path_split.pop(-1) |
| 218 | model_name = path_split[-1] |
| 219 | infer_path = os.path.join('results', model_name, 'bbh/infer') |
| 220 | os.makedirs(infer_path, exist_ok=True) |
| 221 | eval_path = os.path.join('results', model_name, 'bbh/eval') |
| 222 | os.makedirs(eval_path, exist_ok=True) |
| 223 | |
| 224 | model = load(args) |
| 225 | |
| 226 | |
| 227 | if run_multiple_choice: |
| 228 | run_infer(model, args.max_seq_len, multiple_choice_tasks, args.data_dir, infer_path, 'multiple_choice', args.overwrite) |
| 229 | if run_free_form: |
| 230 | run_infer(model, args.max_seq_len, free_form_tasks, args.data_dir, infer_path, 'free_form', args.overwrite) |
| 231 | |
| 232 | |
| 233 | torch.distributed.barrier() |
| 234 | if torch.distributed.get_rank() == 0: |
| 235 | |
| 236 | score = {} |
| 237 | total_results = [] |
| 238 | |
| 239 | if run_multiple_choice: |
| 240 | score['multiple_choice'], task_results = run_eval(multiple_choice_tasks, infer_path, mode='multiple_choice') |
| 241 | total_results.extend(task_results) |
| 242 | |
| 243 | if run_free_form: |
| 244 | score['free_form'], task_results = run_eval(free_form_tasks, infer_path, mode='free_form') |
| 245 | total_results.extend(task_results) |
| 246 | |
| 247 | if args.task == 'all': |
| 248 | score['TOTAL'] = '%.4f' %(sum(total_results) / len(total_results)) |
| 249 | |
| 250 | result_path = os.path.join(eval_path, 'run_results.json') |
| 251 | |
| 252 | with open(result_path, 'w') as f: |
| 253 | json.dump(score, f, ensure_ascii=False, indent=2) |
| 254 | |
| 255 | return |
| 256 | |
| 257 | if __name__ == '__main__': |
| 258 |
no test coverage detected