-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_experiment.py
More file actions
210 lines (176 loc) Β· 6.75 KB
/
run_experiment.py
File metadata and controls
210 lines (176 loc) Β· 6.75 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env python3
"""
Main experiment runner for Adaptive CoT Framework.
This is the main entry point for running research experiments.
Usage:
python run_experiment.py --model-path "/path/to/model" --datasets gsm8k math --strategies adaptive static
python run_experiment.py --model-path "/path/to/model" --datasets gsm8k --max-samples 50 --verbose
"""
import argparse
import sys
import os
import json
from pathlib import Path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from src.experiments.experiment_runner import ExperimentRunner
def create_parser():
"""Create command line argument parser."""
parser = argparse.ArgumentParser(
description="Run Adaptive CoT research experiments",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Run full evaluation on GSM8K and MATH datasets
python run_experiment.py --model-path "/path/to/model" --datasets gsm8k math --strategies adaptive static
# Run with limited samples for quick testing
python run_experiment.py --model-path "/path/to/model" --datasets gsm8k --max-samples 50 --verbose
# Run overnight experiment
python run_experiment.py --model-path "/path/to/model" --datasets gsm8k math aime --overnight
"""
)
# Model configuration
parser.add_argument(
"--model-path",
type=str,
required=True,
help="Path to the model"
)
parser.add_argument(
"--model-type",
type=str,
default="deepseek-r1-distill-qwen",
help="Model type (default: deepseek-r1-distill-qwen)"
)
# Dataset configuration
parser.add_argument(
"--datasets",
nargs="+",
default=["gsm8k"],
help="Datasets to evaluate on (default: gsm8k)"
)
parser.add_argument(
"--max-samples",
type=int,
default=100,
help="Maximum samples per dataset (default: 100)"
)
# Strategy configuration
parser.add_argument(
"--strategies",
nargs="+",
default=["adaptive", "static"],
help="Strategies to compare (default: adaptive static)"
)
parser.add_argument(
"--static-branches",
type=int,
default=3,
help="Number of branches for static strategy (default: 3)"
)
# Experiment configuration
parser.add_argument(
"--experiment-dir",
type=str,
default="experiments",
help="Directory to save experiment results (default: experiments)"
)
parser.add_argument(
"--overnight",
action="store_true",
help="Run overnight experiment with more samples"
)
# Debug options
parser.add_argument(
"--verbose",
action="store_true",
help="Enable verbose output"
)
return parser
def create_experiment_config(args):
"""Create experiment configuration from arguments."""
config = {
"model": {
"model_name": args.model_path,
"model_type": args.model_type,
"generation_params": {
"max_new_tokens": 2048,
"temperature": 0.6,
"top_p": 0.95,
}
},
"datasets": args.datasets,
"max_samples_per_dataset": args.max_samples,
"strategies": args.strategies,
"static_branches": args.static_branches,
"experiment_dir": args.experiment_dir,
"verbose": args.verbose,
"research_logging": True,
}
# Overnight experiment configuration
if args.overnight:
config["max_samples_per_dataset"] = 1000
config["datasets"] = ["gsm8k", "math", "aime"]
config["strategies"] = ["adaptive", "static"]
print("π Running overnight experiment with extended configuration")
return config
def main():
"""Main experiment function."""
parser = create_parser()
args = parser.parse_args()
print("π¬ Adaptive CoT Research Experiment")
print("=" * 50)
print("Running systematic evaluation of adaptive branching strategies")
print()
try:
# Create experiment configuration
config = create_experiment_config(args)
print(f"π¦ Model: {args.model_path}")
print(f"π Datasets: {', '.join(args.datasets)}")
print(f"π― Strategies: {', '.join(args.strategies)}")
print(f"π Max samples per dataset: {args.max_samples}")
print(f"π Experiment directory: {args.experiment_dir}")
print()
# Create experiment runner
runner = ExperimentRunner(config)
# Run full evaluation
print("π Starting experiment...")
results = runner.run_full_evaluation(
model_name=args.model_path,
datasets=args.datasets,
strategies=args.strategies,
max_samples_per_dataset=args.max_samples
)
# Display results summary
print("\\nπ Experiment Results Summary:")
print("-" * 40)
for dataset, dataset_results in results.items():
if isinstance(dataset_results, dict) and "overall" in dataset_results:
overall = dataset_results["overall"]
print(f"\\n{dataset.upper()}:")
print(f" Accuracy: {overall.get('accuracy', 0.0):.3f}")
print(f" Total samples: {overall.get('total_samples', 0)}")
print(f" Execution time: {overall.get('execution_time', 0.0):.2f}s")
# Show strategy comparison
if "strategy_comparison" in dataset_results:
print(f" Strategy comparison:")
for strategy, strategy_results in dataset_results["strategy_comparison"].items():
accuracy = strategy_results.get("accuracy", 0.0)
branches = strategy_results.get("avg_branches", 0)
print(f" {strategy}: {accuracy:.3f} accuracy, {branches:.1f} avg branches")
print(f"\\nβ
Experiment completed successfully!")
print(f"π Results saved to: {runner.run_dir}")
if args.verbose:
print(f"\\nπ§ Technical Details:")
print(f" - Model type: {args.model_type}")
print(f" - Backend: Auto-detected")
print(f" - Adaptive branching: Based on prefill analysis")
print(f" - Self-consistency: Majority voting with do_sample=True")
print(f" - Generation: num_return_sequences for parallel processing")
except Exception as e:
print(f"β Experiment failed: {e}")
if args.verbose:
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()