-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsweep_program_synth_evo_smartbatch.py
More file actions
191 lines (165 loc) · 6.17 KB
/
sweep_program_synth_evo_smartbatch.py
File metadata and controls
191 lines (165 loc) · 6.17 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
"""Sweep program_synth_evo_smartbatch.py across Evo 2 checkpoints.
This driver enforces per-trial randomized encodings for every run by passing
`--per-trial-random` to the smartbatch harness.
"""
from __future__ import annotations
import argparse
import json
import subprocess
from pathlib import Path
from typing import List, Sequence, Tuple
DEFAULT_SHOTS: Sequence[int] = (1, 2, 4, 8, 16, 32, 64, 128)
DEFAULT_MODELS: Tuple[str, ...] = ("evo2_1b_base", "evo2_7b", "evo2_40b")
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description=(
"Sweep program_synth_evo_smartbatch.py across Evo models with per-trial randomized encodings."
)
)
parser.add_argument(
"--models",
type=str,
nargs="*",
default=list(DEFAULT_MODELS),
help=(
"Evo model identifiers to evaluate (default: evo2_1b_base evo2_7b). "
"Each value is forwarded to --model."
),
)
parser.add_argument(
"--programs",
type=Path,
default=Path("curated_transformations.jsonl"),
help="Path to the JSONL file of programs to evaluate (default: curated_transformations.jsonl).",
)
parser.add_argument(
"--output-dir",
type=Path,
default=Path("sweep_results_evo_smartbatch"),
help="Directory to store per-run results and the summary JSON (default: sweep_results_evo_smartbatch).",
)
parser.add_argument(
"--shots",
type=int,
nargs="*",
default=list(DEFAULT_SHOTS),
help="Explicit list of in-context example counts to sweep (default: 1 2 4 8 16 32 64 128).",
)
parser.add_argument(
"--trials-per-program",
type=int,
default=8,
help="Number of trials per program passed to program_synth_evo_smartbatch.py (default: 8).",
)
parser.add_argument(
"--bit-length",
type=int,
default=8,
help="Bit length argument forwarded to program_synth_evo_smartbatch.py (default: 8).",
)
parser.add_argument(
"--max-new-tokens",
type=int,
default=None,
help="Optional max_new_tokens forwarded to program_synth_evo_smartbatch.py (default: bit length).",
)
parser.add_argument(
"--seed",
type=int,
default=42,
help="Seed value forwarded to program_synth_evo_smartbatch.py (default: 42).",
)
parser.add_argument(
"--python-exe",
default="python",
help="Python executable used to invoke program_synth_evo_smartbatch.py (default: python).",
)
parser.add_argument(
"--program-synth",
type=Path,
default=Path("program_synth_evo_smartbatch.py"),
help="Path to the program_synth_evo_smartbatch.py script (default: program_synth_evo_smartbatch.py).",
)
return parser.parse_args()
def run_command(command: Sequence[str]) -> None:
subprocess.run(command, check=True)
def slugify_model(identifier: str) -> str:
return identifier.replace("/", "_")
def main() -> None:
args = parse_args()
backend = "evo"
model_entries = [(model_id, slugify_model(model_id)) for model_id in args.models]
if not model_entries:
raise SystemExit("No models provided for sweeping.")
output_dir = args.output_dir
output_dir.mkdir(parents=True, exist_ok=True)
summary_runs: List[dict] = []
for model_identifier, model_slug in model_entries:
for shots in args.shots:
output_file = output_dir / f"{model_slug}_ic{shots}.json"
command = [
args.python_exe,
str(args.program_synth),
"--model",
model_identifier,
"--programs",
str(args.programs),
"--output",
str(output_file),
"--in-context-examples",
str(shots),
"--trials-per-program",
str(args.trials_per_program),
"--bit-length",
str(args.bit_length),
"--seed",
str(args.seed),
"--backend",
backend,
"--per-trial-random",
]
if args.max_new_tokens is not None:
command.extend(["--max-new-tokens", str(args.max_new_tokens)])
print("Running:", " ".join(command))
run_command(command)
with output_file.open("r", encoding="utf-8") as handle:
result_data = json.load(handle)
overall = result_data.get("overall", {})
config = result_data.get("config", {})
summary_runs.append(
{
"model": model_identifier,
"model_slug": model_slug,
"backend": backend,
"in_context_examples": shots,
"trials_per_program": args.trials_per_program,
"bit_length": args.bit_length,
"max_new_tokens": config.get(
"max_new_tokens", args.max_new_tokens or args.bit_length
),
"per_trial_random": config.get("per_trial_random", True),
"mean_accuracy": overall.get("mean_accuracy"),
"accuracy_stderr": overall.get("stderr"),
"mean_edit_distance": overall.get("mean_edit_distance"),
"edit_distance_stderr": overall.get("edit_distance_stderr"),
"output_file": str(output_file),
}
)
summary = {
"models": list(args.models),
"programs_file": str(args.programs),
"shots": list(args.shots),
"trials_per_program": args.trials_per_program,
"bit_length": args.bit_length,
"max_new_tokens": args.max_new_tokens,
"seed": args.seed,
"backend": backend,
"per_trial_random": True,
"runs": summary_runs,
}
summary_path = output_dir / "sweep_summary.json"
with summary_path.open("w", encoding="utf-8") as handle:
json.dump(summary, handle, indent=2)
print(f"Wrote summary to {summary_path}")
if __name__ == "__main__":
main()