MCPcopy Create free account
hub / github.com/SalesforceAIResearch/perfcodegen / verify_predictions

Method verify_predictions

src/evaluate.py:424–487  ·  view source on GitHub ↗
(self, debug = False, load_temp_data = False, start_index = None, verify_num = None, failed_case = False)

Source from the content-addressed store, hash-verified

422
423
424 def verify_predictions(self, debug = False, load_temp_data = False, start_index = None, verify_num = None, failed_case = False):
425 prompts, overlong_prompts = self.dataset.get_all_prompts()
426 if not load_temp_data:
427 passed_solutions = {}
428 failed_cases = {}
429 else:
430 passed_solutions = self.load_temp_data()
431 failed_cases = {}
432 for index, prompt in enumerate(prompts + overlong_prompts):
433 if len(self.dataset.prompt2testcase[prompt]) == 0:
434 continue
435 if len(self.dataset.prompt2groundtruth[prompt]) == 0 and self.dataset.name != "NTU-NLP-sg/xCodeEval":
436 continue
437 if start_index != None and index < start_index:
438 continue
439 if start_index != None and verify_num != None and index >= start_index + verify_num:
440 break
441 if prompt in passed_solutions:
442 continue
443 if prompt not in self.solutions:
444 continue
445 if len(self.solutions[prompt]) == 0:
446 continue
447
448 correct_count = 0
449 passed_solutions[prompt] = []
450 failed_cases[prompt] = []
451 total_timeout = 10
452 if self.dataset.name == "NTU-NLP-sg/xCodeEval":
453 instance = self.dataset.prompt2instance[prompt]
454 try:
455 total_timeout = len(self.dataset.prompt2testcase[prompt]) * float(instance["time_limit"].replace(" seconds", "").replace(" second", ""))
456 except:
457 total_timeout = len(self.dataset.prompt2testcase[prompt])
458 for i, solution in enumerate(self.solutions[prompt]):
459 print("Verifying prediction #{} for instance #{} ".format(i, index), end = "\r", file = sys.stderr)
460 cur_failed_cases = []
461 s, io = solution
462 if s == -1:
463 continue
464 stat, r = self.execute_code(s, io, self.dataset.prompt2testcase[prompt], check = True, fast_check = True, total_timeout = total_timeout)
465 if stat == "pass":
466 correct_count += 1
467 passed_solutions[prompt].append(solution)
468 else:
469 if failed_case:
470 for result in r:
471 if result["status"] == FAILED:
472 try:
473 json.dumps(result)
474 except Exception as e:
475 del result["model_output"]
476 cur_failed_cases.append(result)
477 failed_cases[prompt].append(cur_failed_cases)
478
479
480 #if index % 200 == 0 and self.dataset.name == "codeparrot/apps" and start_index == None and verify_num == None:
481 # print("Save passed solutions at instance #{}".format(index))

Callers 1

run_correctness_checkMethod · 0.95

Calls 3

load_temp_dataMethod · 0.95
execute_codeMethod · 0.95
get_all_promptsMethod · 0.80

Tested by

no test coverage detected