Download patch_local_data.py from JulianHJR/crest-f: direct link, hf CLI and curl.
- Browser
- Download file 4.24 kB
-
https://huggingface.co/datasets/JulianHJR/crest-f/resolve/main/patch_local_data.py
- Command line
-
hf download hf://datasets/JulianHJR/crest-f/patch_local_data.py
-
curl -L -o patch_local_data.py https://huggingface.co/datasets/JulianHJR/crest-f/resolve/main/patch_local_data.py
4.24 kB
| from pathlib import Path | |
| import re | |
| p = Path("main_vllm.py") | |
| s = p.read_text() | |
| if "import os" not in s[:1000]: | |
| s = s.replace("import json", "import json\nimport os", 1) | |
| if "LOCAL_AIME25_PATCH" not in s: | |
| aime_block = '''elif args.dataset == "aime25": | |
| # LOCAL_AIME25_PATCH | |
| local_path = "data/aime25_with_answers.jsonl" | |
| if os.path.exists(local_path): | |
| with open(local_path) as fin: | |
| for line in fin: | |
| if not line.strip(): | |
| continue | |
| example = json.loads(line) | |
| gt = str(example["answer"]) | |
| test_data.append({ | |
| "question": example["problem"], | |
| "answer": gt, | |
| "gt": gt, | |
| }) | |
| else: | |
| data = load_dataset("math-ai/aime25", split="test") | |
| for example in data: | |
| gt = str(example["answer"]) | |
| test_data.append({ | |
| "question": example["problem"], | |
| "answer": example["answer"], | |
| "gt": gt, | |
| }) | |
| ''' | |
| s2, n = re.subn( | |
| r'elif args\.dataset == "aime25":\n(?: .+\n)+? elif args\.dataset == "lcb":', | |
| aime_block + ' elif args.dataset == "lcb":', | |
| s, | |
| count=1, | |
| ) | |
| if n != 1: | |
| raise SystemExit("Failed to patch aime25 branch") | |
| s = s2 | |
| if "LOCAL_GPQA_D_PATCH" not in s: | |
| gpqa_block = '''elif args.dataset == "gpqa": | |
| # LOCAL_GPQA_D_PATCH | |
| local_path = "data/gpqa_d.jsonl" | |
| if os.path.exists(local_path): | |
| GPQA_QUERY_TEMPLATE = """Answer the following multiple choice question. | |
| The last line of your response should be of the following format: 'Answer: $LETTER' (without quotes) where LETTER is one of ABCD. Think step by step before answering. | |
| {Question}""".strip() | |
| for row in open(local_path): | |
| if not row.strip(): | |
| continue | |
| ex = json.loads(row) | |
| q = ex["problem"] | |
| q = re.sub(r"Answer with the letter.*?boxed\\{\\}\\.?", "", q, flags=re.I | re.S).strip() | |
| query = GPQA_QUERY_TEMPLATE.format(Question=q) | |
| test_data.append({ | |
| "Question": q, | |
| "gold_index": str(ex["answer"]).strip().upper(), | |
| "conversations": [{"role": "user", "content": query}], | |
| }) | |
| else: | |
| dataset = load_dataset('Idavidrein/gpqa', 'gpqa_diamond', split='train') | |
| INDEX_MAP = {0: "A", 1: "B", 2: "C", 3: "D"} | |
| GPQA_QUERY_TEMPLATE = """ Answer the following multiple choice question. | |
| The last line of your response should be of the following format: 'Answer: $LETTER' (without quotes) where LETTER is one of ABCD. Think step by step before answering. | |
| {Question} A) {A} B) {B} C) {C} D) {D} """.strip() | |
| for data in dataset: | |
| gold_index = random.randint(0, 3) | |
| choices = [data["Incorrect Answer 1"], data["Incorrect Answer 2"], data["Incorrect Answer 3"]] | |
| choices.insert(gold_index, data["Correct Answer"]) | |
| data['gold_index'] = INDEX_MAP[gold_index] | |
| data['choices'] = choices | |
| query = GPQA_QUERY_TEMPLATE.format( | |
| A=choices[0], B=choices[1], C=choices[2], D=choices[3], Question=data["Question"] | |
| ) | |
| data["conversations"] = [{"role": "user", "content": query}] | |
| test_data.append(data) | |
| ''' | |
| s2, n = re.subn( | |
| r'elif args\.dataset == "gpqa":\n(?: .+\n)+? elif args\.dataset == "cp":', | |
| gpqa_block + ' elif args.dataset == "cp":', | |
| s, | |
| count=1, | |
| ) | |
| if n != 1: | |
| raise SystemExit("Failed to patch gpqa branch") | |
| s = s2 | |
| old = 'match = re.search(r"(?i)^answer:\\\\s*([A-D])\\\\s*$", response.strip().splitlines()[-1])' | |
| new = 'match = re.search(r"(?i)^answer:\\\\s*([A-D])\\\\s*$", response.strip().splitlines()[-1]) or re.search(r"(?i)\\\\\\\\boxed\\\\{\\\\s*([A-D])\\\\s*\\\\}", response)' | |
| if old in s and new not in s: | |
| s = s.replace(old, new) | |
| p.write_text(s) | |