|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +"""Unit tests for ``AIME25Benchmark`` after lighteval alignment. |
| 5 | +
|
| 6 | +Same shape as ``test_aime24_benchmark.py`` — the lighteval reference |
| 7 | +config is identical except for the dataset URL. |
| 8 | +""" |
| 9 | + |
| 10 | +from __future__ import annotations |
| 11 | + |
| 12 | +from typing import Any |
| 13 | +from unittest.mock import MagicMock, patch |
| 14 | + |
| 15 | +import pytest |
| 16 | + |
| 17 | +from aiperf.accuracy.benchmarks.aime25 import ( |
| 18 | + DEFAULT_GENERATION_SIZE, |
| 19 | + TASK_NAME, |
| 20 | + AIME25Benchmark, |
| 21 | +) |
| 22 | +from aiperf.accuracy.models import BenchmarkProblem |
| 23 | +from aiperf.plugin.enums import AccuracyBenchmarkType, EndpointType |
| 24 | +from tests.unit.conftest import make_benchmark_run |
| 25 | + |
| 26 | + |
| 27 | +def _make_run(): |
| 28 | + return make_benchmark_run( |
| 29 | + model_names=["test-model"], |
| 30 | + endpoint_type=EndpointType.COMPLETIONS, |
| 31 | + streaming=False, |
| 32 | + accuracy={"benchmark": AccuracyBenchmarkType.AIME25}, |
| 33 | + ) |
| 34 | + |
| 35 | + |
| 36 | +def _make_row(problem: str = "What is 1+1?", answer: int = 2) -> dict[str, Any]: |
| 37 | + return {"problem": problem, "answer": answer} |
| 38 | + |
| 39 | + |
| 40 | +def _make_fake_dataset(rows: list[dict[str, Any]]) -> MagicMock: |
| 41 | + ds = MagicMock() |
| 42 | + ds.__iter__ = MagicMock(side_effect=lambda: iter(rows)) |
| 43 | + ds.__len__ = MagicMock(return_value=len(rows)) |
| 44 | + ds.__getitem__ = MagicMock(side_effect=lambda i: rows[i]) |
| 45 | + return ds |
| 46 | + |
| 47 | + |
| 48 | +class TestPromptIsBareProblemText: |
| 49 | + @pytest.mark.asyncio |
| 50 | + async def test_flat_prompt_is_problem_text(self) -> None: |
| 51 | + rows = [_make_row("Compute the answer.", 42)] |
| 52 | + with patch( |
| 53 | + "aiperf.accuracy.benchmarks.aime25.load_dataset", |
| 54 | + return_value=_make_fake_dataset(rows), |
| 55 | + ): |
| 56 | + bench = AIME25Benchmark(run=_make_run()) |
| 57 | + problems = await bench.load_problems( |
| 58 | + tasks=None, n_shots=0, enable_cot=False |
| 59 | + ) |
| 60 | + assert problems[0].prompt == "Compute the answer." |
| 61 | + |
| 62 | + @pytest.mark.asyncio |
| 63 | + async def test_no_instruction_prefix(self) -> None: |
| 64 | + rows = [_make_row("Q?", 1)] |
| 65 | + with patch( |
| 66 | + "aiperf.accuracy.benchmarks.aime25.load_dataset", |
| 67 | + return_value=_make_fake_dataset(rows), |
| 68 | + ): |
| 69 | + bench = AIME25Benchmark(run=_make_run()) |
| 70 | + problems = await bench.load_problems( |
| 71 | + tasks=None, n_shots=0, enable_cot=False |
| 72 | + ) |
| 73 | + prompt = problems[0].prompt |
| 74 | + assert "**Problem**" not in prompt |
| 75 | + assert "competition math" not in prompt |
| 76 | + assert "Let's think" not in prompt |
| 77 | + assert "boxed" not in prompt |
| 78 | + |
| 79 | + @pytest.mark.asyncio |
| 80 | + async def test_chat_message_is_single_user_message(self) -> None: |
| 81 | + rows = [_make_row("Q?", 1)] |
| 82 | + with patch( |
| 83 | + "aiperf.accuracy.benchmarks.aime25.load_dataset", |
| 84 | + return_value=_make_fake_dataset(rows), |
| 85 | + ): |
| 86 | + bench = AIME25Benchmark(run=_make_run()) |
| 87 | + problems = await bench.load_problems( |
| 88 | + tasks=None, n_shots=0, enable_cot=False |
| 89 | + ) |
| 90 | + msgs = problems[0].raw_messages |
| 91 | + assert msgs is not None |
| 92 | + assert len(msgs) == 1 |
| 93 | + assert msgs[0]["role"] == "user" |
| 94 | + assert msgs[0]["content"] == "Q?" |
| 95 | + |
| 96 | + |
| 97 | +class TestNShotsAndCoTAreIgnored: |
| 98 | + @pytest.mark.asyncio |
| 99 | + async def test_n_shots_argument_does_not_affect_prompt(self) -> None: |
| 100 | + rows = [_make_row(f"q{i}", i) for i in range(3)] |
| 101 | + with patch( |
| 102 | + "aiperf.accuracy.benchmarks.aime25.load_dataset", |
| 103 | + return_value=_make_fake_dataset(rows), |
| 104 | + ): |
| 105 | + bench = AIME25Benchmark(run=_make_run()) |
| 106 | + zero_shot = await bench.load_problems( |
| 107 | + tasks=None, n_shots=0, enable_cot=False |
| 108 | + ) |
| 109 | + five_shot = await bench.load_problems( |
| 110 | + tasks=None, n_shots=5, enable_cot=False |
| 111 | + ) |
| 112 | + assert [p.prompt for p in zero_shot] == [p.prompt for p in five_shot] |
| 113 | + |
| 114 | + @pytest.mark.asyncio |
| 115 | + async def test_enable_cot_does_not_affect_prompt(self) -> None: |
| 116 | + rows = [_make_row("Q?", 1)] |
| 117 | + with patch( |
| 118 | + "aiperf.accuracy.benchmarks.aime25.load_dataset", |
| 119 | + return_value=_make_fake_dataset(rows), |
| 120 | + ): |
| 121 | + bench = AIME25Benchmark(run=_make_run()) |
| 122 | + no_cot = await bench.load_problems(tasks=None, n_shots=0, enable_cot=False) |
| 123 | + with_cot = await bench.load_problems(tasks=None, n_shots=0, enable_cot=True) |
| 124 | + assert no_cot[0].prompt == with_cot[0].prompt |
| 125 | + |
| 126 | + |
| 127 | +class TestLoadProblemsCore: |
| 128 | + @pytest.mark.asyncio |
| 129 | + async def test_returns_one_problem_per_row(self) -> None: |
| 130 | + rows = [_make_row(f"q{i}", i) for i in range(5)] |
| 131 | + with patch( |
| 132 | + "aiperf.accuracy.benchmarks.aime25.load_dataset", |
| 133 | + return_value=_make_fake_dataset(rows), |
| 134 | + ): |
| 135 | + bench = AIME25Benchmark(run=_make_run()) |
| 136 | + problems = await bench.load_problems( |
| 137 | + tasks=None, n_shots=0, enable_cot=False |
| 138 | + ) |
| 139 | + assert len(problems) == 5 |
| 140 | + assert all(isinstance(p, BenchmarkProblem) for p in problems) |
| 141 | + |
| 142 | + @pytest.mark.asyncio |
| 143 | + async def test_ground_truth_is_string_form_of_answer(self) -> None: |
| 144 | + rows = [_make_row("q", 42)] |
| 145 | + with patch( |
| 146 | + "aiperf.accuracy.benchmarks.aime25.load_dataset", |
| 147 | + return_value=_make_fake_dataset(rows), |
| 148 | + ): |
| 149 | + bench = AIME25Benchmark(run=_make_run()) |
| 150 | + problems = await bench.load_problems( |
| 151 | + tasks=None, n_shots=0, enable_cot=False |
| 152 | + ) |
| 153 | + assert problems[0].ground_truth == "42" |
| 154 | + |
| 155 | + @pytest.mark.asyncio |
| 156 | + async def test_task_name_is_aime25(self) -> None: |
| 157 | + rows = [_make_row("q", 1)] |
| 158 | + with patch( |
| 159 | + "aiperf.accuracy.benchmarks.aime25.load_dataset", |
| 160 | + return_value=_make_fake_dataset(rows), |
| 161 | + ): |
| 162 | + bench = AIME25Benchmark(run=_make_run()) |
| 163 | + problems = await bench.load_problems( |
| 164 | + tasks=None, n_shots=0, enable_cot=False |
| 165 | + ) |
| 166 | + assert problems[0].task == TASK_NAME |
| 167 | + |
| 168 | + @pytest.mark.asyncio |
| 169 | + async def test_generation_size_is_32k(self) -> None: |
| 170 | + rows = [_make_row("q", 1)] |
| 171 | + with patch( |
| 172 | + "aiperf.accuracy.benchmarks.aime25.load_dataset", |
| 173 | + return_value=_make_fake_dataset(rows), |
| 174 | + ): |
| 175 | + bench = AIME25Benchmark(run=_make_run()) |
| 176 | + problems = await bench.load_problems( |
| 177 | + tasks=None, n_shots=0, enable_cot=False |
| 178 | + ) |
| 179 | + assert problems[0].metadata["generation_size"] == DEFAULT_GENERATION_SIZE |
| 180 | + assert DEFAULT_GENERATION_SIZE == 32768 |
| 181 | + |
| 182 | + |
| 183 | +class TestPathologicalDatasetRows: |
| 184 | + @pytest.mark.asyncio |
| 185 | + async def test_empty_dataset_returns_empty_list(self) -> None: |
| 186 | + with patch( |
| 187 | + "aiperf.accuracy.benchmarks.aime25.load_dataset", |
| 188 | + return_value=_make_fake_dataset([]), |
| 189 | + ): |
| 190 | + bench = AIME25Benchmark(run=_make_run()) |
| 191 | + problems = await bench.load_problems( |
| 192 | + tasks=None, n_shots=0, enable_cot=False |
| 193 | + ) |
| 194 | + assert problems == [] |
| 195 | + |
| 196 | + @pytest.mark.asyncio |
| 197 | + async def test_unicode_problem_text_preserved(self) -> None: |
| 198 | + rows = [_make_row("Solve ∑₁ⁿ k² for n=10. ✓", 385)] |
| 199 | + with patch( |
| 200 | + "aiperf.accuracy.benchmarks.aime25.load_dataset", |
| 201 | + return_value=_make_fake_dataset(rows), |
| 202 | + ): |
| 203 | + bench = AIME25Benchmark(run=_make_run()) |
| 204 | + problems = await bench.load_problems( |
| 205 | + tasks=None, n_shots=0, enable_cot=False |
| 206 | + ) |
| 207 | + assert "∑₁ⁿ" in problems[0].prompt |
0 commit comments