From bdd85358cc52c4f1b64d801402827a2cbe8658fd Mon Sep 17 00:00:00 2001 From: Fengzhe Zhou Date: Mon, 11 Mar 2024 22:34:19 +0800 Subject: [PATCH] [Sync] update 20240308 (#953) --- .../MathBench/mathbench_2024_gen_649349.py | 114 ++++++++++++++++ .../mathbench_2024_wocircular_gen_649349.py | 124 ++++++++++++++++++ configs/datasets/collections/base_core.py | 2 +- configs/datasets/gpqa/gpqa_gen.py | 2 +- ...{gpqa_gen_a27c4d.py => gpqa_gen_4baadb.py} | 6 +- configs/datasets/gpqa/gpqa_ppl_6bf57a.py | 40 ++++++ ...d81d7.py => winogrande_5shot_ll_252f01.py} | 4 +- .../hf_internlm/hf_internlm2_chat_1_8b.py | 35 +++++ configs/summarizers/mathbench_v1.py | 9 ++ configs/summarizers/tiny.py | 30 +++++ opencompass/datasets/gpqa.py | 42 ++---- opencompass/datasets/mbpp.py | 8 +- opencompass/models/openai_api.py | 1 + 13 files changed, 374 insertions(+), 43 deletions(-) create mode 100644 configs/datasets/MathBench/mathbench_2024_gen_649349.py create mode 100644 configs/datasets/MathBench/mathbench_2024_wocircular_gen_649349.py rename configs/datasets/gpqa/{gpqa_gen_a27c4d.py => gpqa_gen_4baadb.py} (89%) create mode 100644 configs/datasets/gpqa/gpqa_ppl_6bf57a.py rename configs/datasets/winogrande/{winogrande_5shot_ll_9d81d7.py => winogrande_5shot_ll_252f01.py} (85%) create mode 100644 configs/models/hf_internlm/hf_internlm2_chat_1_8b.py create mode 100644 configs/summarizers/tiny.py diff --git a/configs/datasets/MathBench/mathbench_2024_gen_649349.py b/configs/datasets/MathBench/mathbench_2024_gen_649349.py new file mode 100644 index 000000000..a73ce1d6e --- /dev/null +++ b/configs/datasets/MathBench/mathbench_2024_gen_649349.py @@ -0,0 +1,114 @@ +from opencompass.openicl.icl_prompt_template import PromptTemplate +from opencompass.openicl.icl_retriever import ZeroRetriever +from opencompass.openicl.icl_inferencer import GenInferencer +from opencompass.openicl.icl_evaluator import CircularEvaluator, AccEvaluator +from opencompass.datasets import MathBenchDataset, mathbench_postprocess +from opencompass.utils.text_postprocessors import first_option_postprocess + +single_choice_prompts = { + "single_choice_cn_with_reasoning": "以下是一道关于数学的单项选择题,请你一步一步推理,并在最后用“所以答案为选项X”给出答案,其中“X”为选项A,B,C,D中你认为正确的选项。下面是你要回答的问题\n{question}\n让我们一步一步思考:\n", + "single_choice_cn": "以下是一道关于数学的单项选择题,请你直接回答正确答案的选项序号。\n下面是你要回答的题目:\n{question}\n答案选项:", + "single_choice_en_with_reasoning": "Here is a multiple-choice question about mathematics. Please reason through it step by step, and at the end, provide your answer option with 'Therefore, the correct answer is option X', Where 'X' is the correct option you think from A,B,C,D. Here is the question you need to answer:\n{question}\nLet's think step by step:", + "single_choice_en": "Here is a multiple-choice question about mathematics. Please provide the correct answer option directly.\nHere is the question you need to answer:\n{question}\nAnswer option:", +} + +cloze_prompts = { + "cloze_cn": [ + dict(role='HUMAN', prompt='Q: 林中有15棵树。林务工人员今天将在林中种植树木。完成后,将有21棵树。林务工人员今天种植了多少棵树?'), + dict(role='BOT', prompt='A: 我们从15棵树开始。后来有21棵树。差值必定是他们种植的树木数量。所以,他们必须种植了21 - 15 = 6棵树。答案是 6\n'), + dict(role='HUMAN', prompt='Q: 如果停车场有3辆车,又有2辆车进来,停车场里有多少辆车?'), + dict(role='BOT', prompt='A: 停车场已经有3辆车。又进来了2辆车。现在有3 + 2 = 5辆车。答案是 5\n'), + dict(role='HUMAN', prompt='Q: 黎恩有32块巧克力,她的妹妹有42块。如果他们吃了35块,他们总共剩下多少块?'), + dict(role='BOT', prompt='A: 黎恩有32块巧克力,Leah的妹妹有42块。这意味着原本有32 + 42 = 74块巧克力。被吃掉了35块。所以他们总共还剩下74 - 35 = 39块巧克力。答案是 39\n'), + dict(role='HUMAN', prompt='Q: 杰森有20个棒棒糖。他给丹妮一些棒棒糖。现在Jason只剩下12个棒棒糖。杰森给丹妮多少个棒棒糖?'), + dict(role='BOT', prompt='A: 杰森有20个棒棒糖。因为他现在只剩下12个,所以他必须把剩下的都给了丹妮。他给丹妮的棒棒糖数量必定是20 - 12 = 8个。答案是 8\n'), + dict(role='HUMAN', prompt='Q: 莎莎有五个玩具。在圣诞节,他从他的爸爸和妈妈那里各得到了两个玩具。现在他有多少个玩具?'), + dict(role='BOT', prompt='A: 她有5个玩具。他从妈妈那里得到了2个,所以之后他有5 + 2 = 7个玩具。然后他从爸爸那里得到了2个,所以总共他有7 + 2 = 9个玩具。答案是 9\n'), + dict(role='HUMAN', prompt='Q: 服务器房间里有九台电脑。从周一到周四每天增加五台电脑。现在服务器房里有多少台电脑?'), + dict(role='BOT', prompt='A: 从周一到周四有4天。每天增加5台电脑。这意味着总共增加了4 * 5 = 20台电脑。一开始有9台电脑,所以现在有9 + 20 = 29台电脑。答案是 29\n'), + dict(role='HUMAN', prompt='Q: 迈克尔有58个高尔夫球。星期二,他丢失了23个高尔夫球。星期三,他又丢失了2个。星期三结束时他还剩下多少个高尔夫球?'), + dict(role='BOT', prompt='A: 迈克尔一开始有58个球。星期二他丢失了23个,所以之后他还剩下58 - 23 = 35个球。星期三他又丢失了2个,所以现在他还剩下35 - 2 = 33个球。答案是 33\n'), + dict(role='HUMAN', prompt='Q: 奥利弗有23美元。她用每个3美元的价格买了五个百吉饼。她还剩下多少钱?'), + dict(role='BOT', prompt='A: 她以每个3美元的价格买了5个百吉饼。这意味着她在百吉饼上花费了5 * 3 = 15美元。她一开始有23美元,所以现在她还剩下23 - 15 = 8美元。答案是 8\n'), + dict(role='HUMAN', prompt='Q: {question}'), + dict(role='BOT', prompt='A: {answer}'), + ], + "cloze_en": [ + dict(role='HUMAN', prompt='Q: There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?'), + dict(role='BOT', prompt='A: We start with 15 trees. Later we have 21 trees. The difference must be the number of trees they planted. So, they must have planted 21 - 15 = 6 trees. The answer is 6.\n'), + dict(role='HUMAN', prompt='Q: If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?'), + dict(role='BOT', prompt='A: There are 3 cars in the parking lot already. 2 more arrive. Now there are 3 + 2 = 5 cars. The answer is 5.\n'), + dict(role='HUMAN', prompt='Q: Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?'), + dict(role='BOT', prompt="A: Leah had 32 chocolates and Leah's sister had 42. That means there were originally 32 + 42 = 74 chocolates. 35 have been eaten. So in total they still have 74 - 35 = 39 chocolates. The answer is 39.\n"), + dict(role='HUMAN', prompt='Q: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?'), + dict(role='BOT', prompt='A: Jason had 20 lollipops. Since he only has 12 now, he must have given the rest to Denny. The number of lollipops he has given to Denny must have been 20 - 12 = 8 lollipops. The answer is 8.\n'), + dict(role='HUMAN', prompt='Q: Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?'), + dict(role='BOT', prompt='A: He has 5 toys. He got 2 from mom, so after that he has 5 + 2 = 7 toys. Then he got 2 more from dad, so in total he has 7 + 2 = 9 toys. The answer is 9.\n'), + dict(role='HUMAN', prompt='Q: There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?'), + dict(role='BOT', prompt='A: There are 4 days from monday to thursday. 5 computers were added each day. That means in total 4 * 5 = 20 computers were added. There were 9 computers in the beginning, so now there are 9 + 20 = 29 computers. The answer is 29.\n'), + dict(role='HUMAN', prompt='Q: Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?'), + dict(role='BOT', prompt='A: Michael initially had 58 balls. He lost 23 on Tuesday, so after that he has 58 - 23 = 35 balls. On Wednesday he lost 2 more so now he has 35 - 2 = 33 balls. The answer is 33.\n'), + dict(role='HUMAN', prompt='Q: Olivia has $23. She bought five bagels for $3 each. How much money does she have left?'), + dict(role='BOT', prompt='A: She bought 5 bagels for $3 each. This means she spent 5 * $3 = $15 on the bagels. She had $23 in beginning, so now she has $23 - $15 = $8. The answer is 8.\n'), + dict(role='HUMAN', prompt='Q: {question}'), + dict(role='BOT', prompt='A: {answer}\n'), +]} + +mathbench_sets = { + # Practice Part + 'college': ['single_choice_cn', 'single_choice_en'], + 'high': ['single_choice_cn', 'single_choice_en'], + 'middle': ['single_choice_cn', 'single_choice_en'], + 'primary': ['cloze_cn', 'cloze_en'], + 'calculate': ['cloze_en'], + # Theory part + 'college_knowledge': ['single_choice_cn','single_choice_en'], + 'high_knowledge': ['single_choice_cn','single_choice_en'], + 'middle_knowledge': ['single_choice_cn','single_choice_en'], + 'primary_knowledge': ['single_choice_cn','single_choice_en'], +} + +# Generate reasoning path or not, only for single choice +with_reasoning = True + +# Use circular evaluation or not +with_circular_eval = True + +mathbench_datasets = [] + +for _split in list(mathbench_sets.keys()): + for _name in mathbench_sets[_split]: + mathbench_infer_cfg = dict( + prompt_template=dict( + type=PromptTemplate, + template=dict( + round=[ + dict( + role="HUMAN", + prompt=single_choice_prompts[_name + "_with_reasoning"] if with_reasoning else single_choice_prompts[_name], + ), + dict(role="BOT", prompt="{answer}")] if 'choice' in _name else cloze_prompts[_name], + ), + ), + retriever=dict(type=ZeroRetriever), + inferencer=dict(type=GenInferencer, max_out_len=512), + ) + + mathbench_eval_cfg = dict( + evaluator=dict(type=CircularEvaluator if 'choice' in _name and with_circular_eval else AccEvaluator), + pred_postprocessor=dict(type=first_option_postprocess, options='ABCD') if 'single_choice' in _name else dict(type=mathbench_postprocess, name=_name)) + + mathbench_datasets.append( + dict( + abbr="mathbench-" + _split + '-' + _name, + type=MathBenchDataset, + path=f"./data/mathbench_v1_ori/{_split}", + name=_name, + with_circular=with_circular_eval, + reader_cfg=dict( + input_columns=["question"], + output_column="answer" + ), + infer_cfg=mathbench_infer_cfg, + eval_cfg=mathbench_eval_cfg, + )) diff --git a/configs/datasets/MathBench/mathbench_2024_wocircular_gen_649349.py b/configs/datasets/MathBench/mathbench_2024_wocircular_gen_649349.py new file mode 100644 index 000000000..f9ae91d8a --- /dev/null +++ b/configs/datasets/MathBench/mathbench_2024_wocircular_gen_649349.py @@ -0,0 +1,124 @@ +from opencompass.openicl.icl_prompt_template import PromptTemplate +from opencompass.openicl.icl_retriever import ZeroRetriever +from opencompass.openicl.icl_inferencer import GenInferencer +from opencompass.openicl.icl_evaluator import CircularEvaluator, AccEvaluator +from opencompass.datasets import MathBenchDataset, mathbench_postprocess +from opencompass.utils.text_postprocessors import first_option_postprocess + +single_choice_prompts = { + "single_choice_cn_with_reasoning": "以下是一道关于数学的单项选择题,请你一步一步推理,并在最后用“所以答案为选项X”给出答案,其中“X”为选项A,B,C,D中你认为正确的选项。下面是你要回答的问题\n{question}\n让我们一步一步思考:\n", + "single_choice_cn": "以下是一道关于数学的单项选择题,请你直接回答正确答案的选项序号。\n下面是你要回答的题目:\n{question}\n答案选项:", + "single_choice_en_with_reasoning": "Here is a multiple-choice question about mathematics. Please reason through it step by step, and at the end, provide your answer option with 'Therefore, the correct answer is option X', Where 'X' is the correct option you think from A,B,C,D. Here is the question you need to answer:\n{question}\nLet's think step by step:", + "single_choice_en": "Here is a multiple-choice question about mathematics. Please provide the correct answer option directly.\nHere is the question you need to answer:\n{question}\nAnswer option:", +} + +cloze_prompts = { + "cloze_cn": [ + dict(role="HUMAN", prompt="Q: 林中有15棵树。林务工人员今天将在林中种植树木。完成后,将有21棵树。林务工人员今天种植了多少棵树?"), + dict(role="BOT", prompt="A: 我们从15棵树开始。后来有21棵树。差值必定是他们种植的树木数量。所以,他们必须种植了21 - 15 = 6棵树。答案是 6\n"), + dict(role="HUMAN", prompt="Q: 如果停车场有3辆车,又有2辆车进来,停车场里有多少辆车?"), + dict(role="BOT", prompt="A: 停车场已经有3辆车。又进来了2辆车。现在有3 + 2 = 5辆车。答案是 5\n"), + dict(role="HUMAN", prompt="Q: 黎恩有32块巧克力,她的妹妹有42块。如果他们吃了35块,他们总共剩下多少块?"), + dict(role="BOT", prompt="A: 黎恩有32块巧克力,Leah的妹妹有42块。这意味着原本有32 + 42 = 74块巧克力。被吃掉了35块。所以他们总共还剩下74 - 35 = 39块巧克力。答案是 39\n"), + dict(role="HUMAN", prompt="Q: 杰森有20个棒棒糖。他给丹妮一些棒棒糖。现在Jason只剩下12个棒棒糖。杰森给丹妮多少个棒棒糖?"), + dict(role="BOT", prompt="A: 杰森有20个棒棒糖。因为他现在只剩下12个,所以他必须把剩下的都给了丹妮。他给丹妮的棒棒糖数量必定是20 - 12 = 8个。答案是 8\n"), + dict(role="HUMAN", prompt="Q: 莎莎有五个玩具。在圣诞节,他从他的爸爸和妈妈那里各得到了两个玩具。现在他有多少个玩具?"), + dict(role="BOT", prompt="A: 她有5个玩具。他从妈妈那里得到了2个,所以之后他有5 + 2 = 7个玩具。然后他从爸爸那里得到了2个,所以总共他有7 + 2 = 9个玩具。答案是 9\n"), + dict(role="HUMAN", prompt="Q: 服务器房间里有九台电脑。从周一到周四每天增加五台电脑。现在服务器房里有多少台电脑?"), + dict(role="BOT", prompt="A: 从周一到周四有4天。每天增加5台电脑。这意味着总共增加了4 * 5 = 20台电脑。一开始有9台电脑,所以现在有9 + 20 = 29台电脑。答案是 29\n"), + dict(role="HUMAN", prompt="Q: 迈克尔有58个高尔夫球。星期二,他丢失了23个高尔夫球。星期三,他又丢失了2个。星期三结束时他还剩下多少个高尔夫球?"), + dict(role="BOT", prompt="A: 迈克尔一开始有58个球。星期二他丢失了23个,所以之后他还剩下58 - 23 = 35个球。星期三他又丢失了2个,所以现在他还剩下35 - 2 = 33个球。答案是 33\n"), + dict(role="HUMAN", prompt="Q: 奥利弗有23美元。她用每个3美元的价格买了五个百吉饼。她还剩下多少钱?"), + dict(role="BOT", prompt="A: 她以每个3美元的价格买了5个百吉饼。这意味着她在百吉饼上花费了5 * 3 = 15美元。她一开始有23美元,所以现在她还剩下23 - 15 = 8美元。答案是 8\n"), + dict(role="HUMAN", prompt="Q: {question}"), + dict(role="BOT", prompt="A: {answer}"), + ], + "cloze_en": [ + dict(role="HUMAN", prompt="Q: There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?"), + dict(role="BOT", prompt="A: We start with 15 trees. Later we have 21 trees. The difference must be the number of trees they planted. So, they must have planted 21 - 15 = 6 trees. The answer is 6.\n"), + dict(role="HUMAN", prompt="Q: If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?"), + dict(role="BOT", prompt="A: There are 3 cars in the parking lot already. 2 more arrive. Now there are 3 + 2 = 5 cars. The answer is 5.\n"), + dict(role="HUMAN", prompt="Q: Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?"), + dict(role="BOT", prompt="A: Leah had 32 chocolates and Leah's sister had 42. That means there were originally 32 + 42 = 74 chocolates. 35 have been eaten. So in total they still have 74 - 35 = 39 chocolates. The answer is 39.\n"), + dict(role="HUMAN", prompt="Q: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?"), + dict(role="BOT", prompt="A: Jason had 20 lollipops. Since he only has 12 now, he must have given the rest to Denny. The number of lollipops he has given to Denny must have been 20 - 12 = 8 lollipops. The answer is 8.\n"), + dict(role="HUMAN", prompt="Q: Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?"), + dict(role="BOT", prompt="A: He has 5 toys. He got 2 from mom, so after that he has 5 + 2 = 7 toys. Then he got 2 more from dad, so in total he has 7 + 2 = 9 toys. The answer is 9.\n"), + dict(role="HUMAN", prompt="Q: There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?"), + dict(role="BOT", prompt="A: There are 4 days from monday to thursday. 5 computers were added each day. That means in total 4 * 5 = 20 computers were added. There were 9 computers in the beginning, so now there are 9 + 20 = 29 computers. The answer is 29.\n"), + dict(role="HUMAN", prompt="Q: Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?"), + dict(role="BOT", prompt="A: Michael initially had 58 balls. He lost 23 on Tuesday, so after that he has 58 - 23 = 35 balls. On Wednesday he lost 2 more so now he has 35 - 2 = 33 balls. The answer is 33.\n"), + dict(role="HUMAN", prompt="Q: Olivia has $23. She bought five bagels for $3 each. How much money does she have left?"), + dict(role="BOT", prompt="A: She bought 5 bagels for $3 each. This means she spent 5 * $3 = $15 on the bagels. She had $23 in beginning, so now she has $23 - $15 = $8. The answer is 8.\n"), + dict(role="HUMAN", prompt="Q: {question}"), + dict(role="BOT", prompt="A: {answer}\n"), + ], +} + +mathbench_sets = { + # Practice Part + "college": ["single_choice_cn", "single_choice_en"], + "high": ["single_choice_cn", "single_choice_en"], + "middle": ["single_choice_cn", "single_choice_en"], + "primary": ["cloze_cn", "cloze_en"], + "calculate": ["cloze_en"], + # Theory part + "college_knowledge": ["single_choice_cn", "single_choice_en"], + "high_knowledge": ["single_choice_cn", "single_choice_en"], + "middle_knowledge": ["single_choice_cn", "single_choice_en"], + "primary_knowledge": ["single_choice_cn", "single_choice_en"], +} + +# Generate reasoning path or not, only for single choice +with_reasoning = True + +# Use circular evaluation or not +with_circular_eval = False + +mathbench_datasets = [] + +for _split in list(mathbench_sets.keys()): + for _name in mathbench_sets[_split]: + mathbench_reader_cfg = dict( + input_columns=["question"], + output_column="answer", + ) + + if "single_choice" in _name: + template_round = [ + dict(role="HUMAN", prompt=(single_choice_prompts[_name + "_with_reasoning"] if with_reasoning else single_choice_prompts[_name])), + dict(role="BOT", prompt="{answer}") + ] + else: + template_round = cloze_prompts[_name] + mathbench_infer_cfg = dict( + prompt_template=dict(type=PromptTemplate, template=dict(round=template_round)), + retriever=dict(type=ZeroRetriever), + inferencer=dict(type=GenInferencer, max_out_len=512), + ) + + if "single_choice" in _name: + pred_postprocessor = dict(type=first_option_postprocess, options="ABCD") + else: + pred_postprocessor = dict(type=mathbench_postprocess, name=_name) + if "single_choice" in _name and with_circular_eval: + evaluator = dict(type=CircularEvaluator) + else: + evaluator = dict(type=AccEvaluator) + mathbench_eval_cfg = dict( + evaluator=evaluator, + pred_postprocessor=pred_postprocessor, + ) + + mathbench_datasets.append( + dict( + abbr="mathbench-" + _split + "-" + _name, + type=MathBenchDataset, + path=f"./data/mathbench_v1_ori/{_split}", + name=_name, + with_circular=with_circular_eval, + reader_cfg=mathbench_reader_cfg, + infer_cfg=mathbench_infer_cfg, + eval_cfg=mathbench_eval_cfg, + ) + ) diff --git a/configs/datasets/collections/base_core.py b/configs/datasets/collections/base_core.py index fc490e77a..ab81496d2 100644 --- a/configs/datasets/collections/base_core.py +++ b/configs/datasets/collections/base_core.py @@ -8,7 +8,7 @@ from ..triviaqa.triviaqa_wiki_1shot_gen_20a989 import triviaqa_datasets from ..nq.nq_open_1shot_gen_20a989 import nq_datasets from ..race.race_ppl_abed12 import race_datasets - from ..winogrande.winogrande_5shot_ll_9d81d7 import winogrande_datasets + from ..winogrande.winogrande_5shot_ll_252f01 import winogrande_datasets from ..hellaswag.hellaswag_10shot_ppl_59c85e import hellaswag_datasets from ..bbh.bbh_gen_0a5495 import bbh_datasets from ..gsm8k.gsm8k_gen_ee684f import gsm8k_datasets diff --git a/configs/datasets/gpqa/gpqa_gen.py b/configs/datasets/gpqa/gpqa_gen.py index 2f132824c..f666825f3 100644 --- a/configs/datasets/gpqa/gpqa_gen.py +++ b/configs/datasets/gpqa/gpqa_gen.py @@ -1,4 +1,4 @@ from mmengine.config import read_base with read_base(): - from .gpqa_gen_a27c4d import gpqa_datasets + from .gpqa_gen_4baadb import gpqa_datasets diff --git a/configs/datasets/gpqa/gpqa_gen_a27c4d.py b/configs/datasets/gpqa/gpqa_gen_4baadb.py similarity index 89% rename from configs/datasets/gpqa/gpqa_gen_a27c4d.py rename to configs/datasets/gpqa/gpqa_gen_4baadb.py index 51d6c52e2..f4d39ed5e 100644 --- a/configs/datasets/gpqa/gpqa_gen_a27c4d.py +++ b/configs/datasets/gpqa/gpqa_gen_4baadb.py @@ -13,7 +13,7 @@ type=PromptTemplate, template=dict( round=[ - dict(role='HUMAN', prompt='{question}\nChoices:\n' + dict(role='HUMAN', prompt='What is the correct answer to this question: {question}\nChoices:\n' '(A){A}\n' '(B){B}\n' '(C){C}\n' @@ -28,8 +28,8 @@ gpqa_datasets = [] gpqa_subsets = { - 'extended': 'gpqa_extended.csv', - 'main': 'gpqa_main.csv', + # 'extended': 'gpqa_extended.csv', + # 'main': 'gpqa_main.csv', 'diamond': 'gpqa_diamond.csv' } diff --git a/configs/datasets/gpqa/gpqa_ppl_6bf57a.py b/configs/datasets/gpqa/gpqa_ppl_6bf57a.py new file mode 100644 index 000000000..8b1120090 --- /dev/null +++ b/configs/datasets/gpqa/gpqa_ppl_6bf57a.py @@ -0,0 +1,40 @@ +from opencompass.openicl.icl_prompt_template import PromptTemplate +from opencompass.openicl.icl_retriever import ZeroRetriever +from opencompass.openicl.icl_inferencer import PPLInferencer +from opencompass.datasets import GPQADataset, GPQAEvaluator +from opencompass.utils import first_option_postprocess + +gpqa_reader_cfg = dict( + input_columns=['question', 'A', 'B', 'C', 'D'], + output_column='answer') + +gpqa_infer_cfg = dict( + prompt_template=dict( + type=PromptTemplate, + template={ + opt: f'Question: {{question}}\n(A){{A}}\n(B){{B}}\n(C){{C}}\n(D){{D}}\nAnswer: {opt}' for opt in ['A', 'B', 'C', 'D'] + }), + retriever=dict(type=ZeroRetriever), + inferencer=dict(type=PPLInferencer)) + +gpqa_eval_cfg = dict(evaluator=dict(type=GPQAEvaluator), + pred_postprocessor=dict(type=first_option_postprocess, options='ABCD')) + +gpqa_datasets = [] +gpqa_subsets = { + # 'extended': 'gpqa_extended.csv', + # 'main': 'gpqa_main.csv', + 'diamond': 'gpqa_diamond.csv' +} + +for split in list(gpqa_subsets.keys()): + gpqa_datasets.append( + dict( + abbr='GPQA_' + split, + type=GPQADataset, + path='./data/gpqa/', + name=gpqa_subsets[split], + reader_cfg=gpqa_reader_cfg, + infer_cfg=gpqa_infer_cfg, + eval_cfg=gpqa_eval_cfg) + ) diff --git a/configs/datasets/winogrande/winogrande_5shot_ll_9d81d7.py b/configs/datasets/winogrande/winogrande_5shot_ll_252f01.py similarity index 85% rename from configs/datasets/winogrande/winogrande_5shot_ll_9d81d7.py rename to configs/datasets/winogrande/winogrande_5shot_ll_252f01.py index 53528c34f..eac643501 100644 --- a/configs/datasets/winogrande/winogrande_5shot_ll_9d81d7.py +++ b/configs/datasets/winogrande/winogrande_5shot_ll_252f01.py @@ -15,11 +15,11 @@ winogrande_infer_cfg = dict( ice_template=dict( type=PromptTemplate, - template={answer: f"{question_and_options}\nAnswer: {answer}\n" for answer in ["A", "B"]}, + template={'A': '{opt1}', 'B': '{opt2}'}, ), prompt_template=dict( type=PromptTemplate, - template={answer: f"{question_and_options}\nAnswer: {answer}" for answer in ["A", "B"]}, + template={'A': '{opt1}', 'B': '{opt2}'}, ice_token="", ), retriever=dict(type=FixKRetriever, fix_id_list=[0, 2, 4, 6, 8]), diff --git a/configs/models/hf_internlm/hf_internlm2_chat_1_8b.py b/configs/models/hf_internlm/hf_internlm2_chat_1_8b.py new file mode 100644 index 000000000..b5c109fe8 --- /dev/null +++ b/configs/models/hf_internlm/hf_internlm2_chat_1_8b.py @@ -0,0 +1,35 @@ +from opencompass.models import HuggingFaceCausalLM + + +_meta_template = dict( + round=[ + dict(role='HUMAN', begin='<|im_start|>user\n', end='<|im_end|>\n'), + dict(role='BOT', begin='<|im_start|>assistant\n', end='<|im_end|>\n', generate=True), + ], + eos_token_id=92542 +) + +models = [ + dict( + type=HuggingFaceCausalLM, + abbr='internlm2-chat-1.8b-hf', + path="internlm/internlm2-chat-1_8b", + tokenizer_path='internlm/internlm2-chat-1_8b', + model_kwargs=dict( + trust_remote_code=True, + device_map='auto', + ), + tokenizer_kwargs=dict( + padding_side='left', + truncation_side='left', + use_fast=False, + trust_remote_code=True, + ), + max_out_len=100, + max_seq_len=2048, + batch_size=8, + meta_template=_meta_template, + run_cfg=dict(num_gpus=1, num_procs=1), + end_str='<|im_end|>', + ) +] diff --git a/configs/summarizers/mathbench_v1.py b/configs/summarizers/mathbench_v1.py index a3112fe92..2a70ea1f6 100644 --- a/configs/summarizers/mathbench_v1.py +++ b/configs/summarizers/mathbench_v1.py @@ -17,6 +17,15 @@ ['mathbench-high-single_choice_en', 'perf_4'], ['mathbench-middle-single_choice_cn', 'perf_4'], ['mathbench-middle-single_choice_en', 'perf_4'], + '######## MathBench Knowledge ########', # category + ['mathbench-college_knowledge-single_choice_cn', 'perf_4'], + ['mathbench-college_knowledge-single_choice_en', 'perf_4'], + ['mathbench-high_knowledge-single_choice_cn', 'perf_4'], + ['mathbench-high_knowledge-single_choice_en', 'perf_4'], + ['mathbench-middle_knowledge-single_choice_cn', 'perf_4'], + ['mathbench-middle_knowledge-single_choice_en', 'perf_4'], + ['mathbench-primary_knowledge-single_choice_cn', 'perf_4'], + ['mathbench-primary_knowledge-single_choice_en', 'perf_4'], ], summary_groups=sum( [v for k, v in locals().items() if k.endswith("_summary_groups")], []) diff --git a/configs/summarizers/tiny.py b/configs/summarizers/tiny.py new file mode 100644 index 000000000..526531397 --- /dev/null +++ b/configs/summarizers/tiny.py @@ -0,0 +1,30 @@ +from mmengine.config import read_base + +with read_base(): + from .groups.mmlu import mmlu_summary_groups + from .groups.ceval import ceval_summary_groups + from .groups.bbh import bbh_summary_groups + from .groups.GaokaoBench import GaokaoBench_summary_groups + from .groups.cmmlu import cmmlu_summary_groups + +summarizer = dict( + dataset_abbrs=[ + ['mmlu', 'naive_average'], + ['cmmlu', 'naive_average'], + ['ceval-test', 'naive_average'], + ['GaokaoBench', 'weighted_average'], + ['triviaqa_wiki_1shot', 'score'], + ['nq_open_1shot', 'score'], + ['race-high', 'accuracy'], + ['winogrande', 'accuracy'], + ['hellaswag', 'accuracy'], + ['bbh', 'naive_average'], + ['gsm8k', 'accuracy'], + ['math', 'accuracy'], + ['TheoremQA', 'accuracy'], + ['openai_humaneval', 'humaneval_pass@1'], + ['sanitized_mbpp', 'score'], + ], + summary_groups=sum( + [v for k, v in locals().items() if k.endswith("_summary_groups")], []), +) diff --git a/opencompass/datasets/gpqa.py b/opencompass/datasets/gpqa.py index 1c0396474..20ba4c39d 100644 --- a/opencompass/datasets/gpqa.py +++ b/opencompass/datasets/gpqa.py @@ -1,4 +1,3 @@ -import copy import csv import os @@ -17,7 +16,6 @@ class GPQADataset(BaseDataset): def load(path: str, name: str): cnt = 0 data = [] - data_new = [] with open(os.path.join(path, name), 'r', encoding='utf-8') as f: reader = csv.reader(f, delimiter=',') for row in reader: @@ -25,38 +23,20 @@ def load(path: str, name: str): continue cnt = cnt + 1 question = row[7] - A = row[8] - B = row[9] - C = row[10] - D = row[11] + # 第一个是正确选项 options = [row[8], row[9], row[10], row[11]] - answer = 'A' - - data.append({ - 'question': question, - 'A': A, - 'B': B, - 'C': C, - 'D': D, - 'options': options, - 'answer': answer - }) - - circular_patterns = ['ABCD', 'BCDA', 'CDAB', 'DABC'] # 更新选项顺序 - c = circular_patterns[cnt % 4] - line = copy.deepcopy(data[cnt - 1]) - tmp = line['A'] + shuffle_patterns = ['ABCD', 'BCDA', 'CDAB', 'DABC'] # 更新选项顺序 + c = shuffle_patterns[cnt % 4] + line = {'question': question} + ground_truth = options[0] for i in range(4): - line['ABCD'[i]] = line['options'][ord(c[i]) - ord('A')] - + line['ABCD'[i]] = options[ord(c[i]) - ord('A')] for i in range(4): - if line['ABCD'[i]] == tmp: + if line['ABCD'[i]] == ground_truth: line['answer'] = 'ABCD'[i] break - data_new.append(line) - - dataset = Dataset.from_list(data_new) - + data.append(line) + dataset = Dataset.from_list(data) return dataset @@ -64,9 +44,7 @@ class GPQAEvaluator(BaseEvaluator): def score(self, predictions, references): if len(predictions) != len(references): - return { - 'error': 'predictions and references have different length' - } + return {'error': 'preds and refrs have different length'} correct = 0 count = 0 details = [] diff --git a/opencompass/datasets/mbpp.py b/opencompass/datasets/mbpp.py index 4f760d45f..e9a3c81fd 100644 --- a/opencompass/datasets/mbpp.py +++ b/opencompass/datasets/mbpp.py @@ -213,15 +213,15 @@ def score(self, predictions, references): programs = self._process_test(refer, pred) future = executor.submit(execution, programs, i, 3) futures.append(future) + details[str(i)] = {} + details[str(i)]['origin'] = predictions[i] + details[str(i)]['programs'] = programs from tqdm import tqdm for future in tqdm(as_completed(futures), total=len(futures)): index, key = future.result() result[key] += 1 - details[str(index)] = { - 'programs': predictions[index], - 'result': key - } + details[str(index)]['result'] = key result['score'] = result['pass'] / len(predictions) * 100 result['details'] = details diff --git a/opencompass/models/openai_api.py b/opencompass/models/openai_api.py index 3c3fd9111..251e97972 100644 --- a/opencompass/models/openai_api.py +++ b/opencompass/models/openai_api.py @@ -239,6 +239,7 @@ def _generate(self, input: str or PromptList, max_out_len: int, if 'error' in response: if response['error']['code'] == 'rate_limit_exceeded': time.sleep(1) + self.logger.warn('Rate limit exceeded, retrying...') continue elif response['error']['code'] == 'insufficient_quota': self.invalid_keys.add(key)