|
| 1 | +# Copyright 2025 Bytedance Ltd. and/or its affiliates |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# prepare eval dataset including AIME'24, AIME'25 |
| 16 | + |
| 17 | +# hf download math-ai/aime24 --repo-type dataset --local-dir /opt/tiger/datasets/math-ai/aime24 |
| 18 | +# hf download math-ai/aime25 --repo-type dataset --local-dir /opt/tiger/datasets/math-ai/aime25 |
| 19 | + |
| 20 | +import os |
| 21 | + |
| 22 | +import datasets |
| 23 | + |
| 24 | +from verl.utils.reward_score.math_reward import remove_boxed |
| 25 | + |
| 26 | +instruction_following = "Please reason step by step, and put your final answer within \\boxed{}." |
| 27 | + |
| 28 | + |
| 29 | +def make_map_fn(data_source): |
| 30 | + def process_fn(example, idx): |
| 31 | + question_raw = example.pop("problem") |
| 32 | + |
| 33 | + question = question_raw + " " + instruction_following |
| 34 | + |
| 35 | + if "solution" not in example: |
| 36 | + example["solution"] = example["answer"] |
| 37 | + |
| 38 | + answer_raw = example.pop("solution") |
| 39 | + |
| 40 | + example.clear() |
| 41 | + |
| 42 | + try: |
| 43 | + solution = remove_boxed(answer_raw) |
| 44 | + except Exception: |
| 45 | + solution = answer_raw |
| 46 | + |
| 47 | + data = { |
| 48 | + "data_source": data_source, |
| 49 | + "prompt": [ |
| 50 | + { |
| 51 | + "role": "user", |
| 52 | + "content": question, |
| 53 | + } |
| 54 | + ], |
| 55 | + "ability": "math", |
| 56 | + "reward_model": {"style": "rule", "ground_truth": solution}, |
| 57 | + "extra_info": { |
| 58 | + "index": idx, |
| 59 | + "answer": answer_raw, |
| 60 | + "question": question_raw, |
| 61 | + }, |
| 62 | + } |
| 63 | + return data |
| 64 | + |
| 65 | + return process_fn |
| 66 | + |
| 67 | + |
| 68 | +if __name__ == "__main__": |
| 69 | + import argparse |
| 70 | + |
| 71 | + parser = argparse.ArgumentParser() |
| 72 | + parser.add_argument("--local_dataset_path", default=None, help="The local path to the raw dataset, if it exists.") |
| 73 | + parser.add_argument( |
| 74 | + "--local_save_dir", default="~/data/math-ai", help="The save directory for the preprocessed dataset." |
| 75 | + ) |
| 76 | + |
| 77 | + args = parser.parse_args() |
| 78 | + |
| 79 | + if args.local_dataset_path is not None: |
| 80 | + aime24_dataset_path = os.path.join(args.local_dataset_path, "math-ai/aime24") |
| 81 | + aime25_dataset_path = os.path.join(args.local_dataset_path, "math-ai/aime25") |
| 82 | + else: |
| 83 | + aime24_dataset_path = "math-ai/aime24" |
| 84 | + aime25_dataset_path = "math-ai/aime25" |
| 85 | + |
| 86 | + aime24_dataset = datasets.load_dataset(aime24_dataset_path, split="test") |
| 87 | + aime25_dataset = datasets.load_dataset(aime25_dataset_path, split="test") |
| 88 | + |
| 89 | + aime24_dataset = aime24_dataset.map(function=make_map_fn("aime24"), with_indices=True) |
| 90 | + aime25_dataset = aime25_dataset.map(function=make_map_fn("aime25"), with_indices=True) |
| 91 | + |
| 92 | + local_save_dir = os.path.expanduser(args.local_save_dir) |
| 93 | + os.makedirs(local_save_dir, exist_ok=True) |
| 94 | + |
| 95 | + aime24_dataset.to_parquet(os.path.join(local_save_dir, "aime24_test.parquet")) |
| 96 | + aime25_dataset.to_parquet(os.path.join(local_save_dir, "aime25_test.parquet")) |
0 commit comments