Skip to content

More stable MBPP evaluation #2111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions opencompass/datasets/mbpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import multiprocessing
import os.path as osp
import re
import regex as re
import signal
import tempfile
from collections import defaultdict
Expand Down Expand Up @@ -330,7 +330,11 @@ def _process_answer(self, text):
r"'(.*)'\s*\[DONE\]",
]
for p in patterns:
match = re.search(p, text, re.DOTALL)
try:
match = re.search(p, text, re.DOTALL, timeout=10.0)
except TimeoutError:
match = None

if match:
text = match.group(1)
break
Expand Down Expand Up @@ -383,6 +387,22 @@ def _process_answer(self, text):
text = text[1:]
return text

def _execution(programs, timeout, key):
try:
# Add exec globals to prevent the exec to raise
# unnecessary NameError for correct answer
exec_globals = {}
with swallow_io():
with time_limit(timeout):
exec(programs, exec_globals)
key.append('pass')
except TimeOutException:
key.append('timeout')
except AssertionError:
key.append('wrong_answer')
except BaseException as e:
print(e)
key.append('failed')

def execution(programs, task_id, timeout):
"""Execution function for running generation code.
Expand All @@ -400,29 +420,12 @@ def execution(programs, task_id, timeout):
control the process.
"""

def _execution(programs, timeout):
try:
# Add exec globals to prevent the exec to raise
# unnecessary NameError for correct answer
exec_globals = {}
with swallow_io():
with time_limit(timeout):
exec(programs, exec_globals)
key.append('pass')
except TimeOutException:
key.append('timeout')
except AssertionError:
key.append('wrong_answer')
except BaseException as e:
print(e)
key.append('failed')

manager = multiprocessing.Manager()
key = manager.list()
# `signal` cannot be used in child thread, therefore, we
# need to create a process in the thread.
p = multiprocessing.Process(target=_execution,
args=(programs, timeout - 1))
args=(programs, timeout - 1, key))
p.start()
p.join(timeout=timeout)
if p.is_alive():
Expand Down