-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_aime_2024_samples.py
More file actions
191 lines (157 loc) Β· 6.13 KB
/
test_aime_2024_samples.py
File metadata and controls
191 lines (157 loc) Β· 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/env python3
"""
Test script for AIME 2024 samples using the adaptive CoT framework.
"""
import argparse
import json
import time
from pathlib import Path
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from src.benchmarks.math_benchmarks import MathBenchmarkLoader
from src.adaptive.adaptive_cot import AdaptiveCoT
from src.models.generic_model import GenericModel as HuggingFaceModel
def test_aime_2024_samples(
model_path: str,
branches: int = 8,
samples: int = 3,
output_file: str = "results/aime_2024_test.json",
mode: str = "static"
):
"""Test AIME 2024 samples with the adaptive CoT framework."""
print("π¬ AIME 2024 Sample Testing")
print("=" * 60)
print(f"Mode: {mode}")
print(f"Branch Count: {branches}")
print(f"Number of Samples: {samples}")
print(f"Output File: {output_file}")
print("=" * 60)
# Load model
print("π§ Loading model...")
model_config = {
"model_config": {},
"generation_params": {}
}
model = HuggingFaceModel(model_path, model_config)
model.load_model()
print(f"Model loaded successfully on {model.device}")
# Load AIME 2024 dataset
print("π Loading AIME 2024 dataset...")
benchmark_loader = MathBenchmarkLoader()
dataset = benchmark_loader.load_dataset("aime_2024", max_samples=samples)
if len(dataset) < samples:
print(f"π Limited to {len(dataset)} samples")
else:
print(f"π Using all {len(dataset)} samples")
# Configure adaptive CoT
config = {
"adaptive_branching": mode == "adaptive",
"min_branches": branches,
"max_branches": branches,
"default_branches": branches,
"num_fewshot": 0, # Zero-shot evaluation
"temperature": 0.7, # Non-deterministic for self-consistency
"top_p": 0.95,
"max_tokens": 32768,
"benchmark": "aime_2024" # Use AIME 2024-specific answer extraction
}
print(f"βοΈ Configuration:")
for key, value in config.items():
print(f" {key}: {value}")
print()
# Initialize adaptive CoT
adaptive_cot = AdaptiveCoT(model, config)
# Test problems
results = []
total_start_time = time.time()
print("π Starting evaluation...")
for i, sample in enumerate(dataset, 1):
print(f"π Problem {i}/{len(dataset)}: {sample['question'][:100]}...")
# Solve problem
start_time = time.time()
result = adaptive_cot.solve_problem(sample['question'])
solve_time = time.time() - start_time
# Extract ground truth answer
ground_truth_answer = str(sample['answer']).strip()
# Check correctness
is_correct = result['final_answer'] == ground_truth_answer
# Store result
problem_result = {
"problem_id": i,
"question": sample['question'],
"ground_truth": ground_truth_answer,
"predicted_answer": result['final_answer'],
"correct": is_correct,
"solve_time": solve_time,
"num_branches": result['num_branches'],
"consensus_confidence": result.get('consensus_confidence', 0.0),
"reasoning_paths": result['reasoning_paths'],
"extracted_answers": result['extracted_answers']
}
results.append(problem_result)
# Print result
print(f"π― Final answer: {result['final_answer']}")
print(f"π Consensus confidence: {result.get('consensus_confidence', 0.0):.3f}")
print(f" Answer: {result['final_answer']}")
print(f" Ground Truth: {ground_truth_answer}")
print(f" Correct: {'β
' if is_correct else 'β'}")
print(f" Confidence: {result.get('consensus_confidence', 0.0):.3f}")
print()
total_time = time.time() - total_start_time
# Calculate statistics
correct_count = sum(1 for r in results if r['correct'])
accuracy = correct_count / len(results) if results else 0
# Print summary
print("π Evaluation Results")
print("=" * 60)
print(f"Total Problems: {len(results)}")
print(f"Correct: {correct_count}")
print(f"Accuracy: {accuracy:.4f} ({accuracy*100:.2f}%)")
print(f"Total Duration: {total_time:.2f}s")
print(f"Average per Problem: {total_time/len(results):.2f}s")
print(f"Branch Count: {branches}")
print("=" * 60)
# Save results
output_path = Path(output_file)
output_path.parent.mkdir(parents=True, exist_ok=True)
summary = {
"dataset": "aime_2024",
"model_path": model_path,
"config": config,
"total_problems": len(results),
"correct": correct_count,
"accuracy": accuracy,
"total_time": total_time,
"average_time_per_problem": total_time / len(results),
"branch_count": branches,
"mode": mode,
"results": results
}
with open(output_path, 'w') as f:
json.dump(summary, f, indent=2)
print(f"πΎ Results saved to: {output_file}")
return summary
def main():
parser = argparse.ArgumentParser(description="Test AIME 2024 samples with adaptive CoT")
parser.add_argument("--model_path", type=str,
default="/raid/LLM/deepseek-r1-distill-qwen-14b",
help="Path to the model")
parser.add_argument("--branches", type=int, default=8,
help="Number of reasoning branches")
parser.add_argument("--samples", type=int, default=3,
help="Number of samples to test")
parser.add_argument("--output", type=str, default="results/aime_2024_test.json",
help="Output file path")
parser.add_argument("--mode", type=str, choices=["static", "adaptive"], default="static",
help="Branching mode")
args = parser.parse_args()
test_aime_2024_samples(
model_path=args.model_path,
branches=args.branches,
samples=args.samples,
output_file=args.output,
mode=args.mode
)
if __name__ == "__main__":
main()