-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrun_cross_model_compact.py
More file actions
181 lines (159 loc) · 6.73 KB
/
run_cross_model_compact.py
File metadata and controls
181 lines (159 loc) · 6.73 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
from __future__ import annotations
import argparse
import json
import os
from pathlib import Path
import httpx
from lockr.runners.benchmark import BenchmarkRunner
from lockr.schemas import BenchmarkConfig
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="Run frozen harness v1 compact cross-model tests via OpenRouter.")
parser.add_argument("--config", type=Path, default=Path("configs/frozen_harness_v1_compact.json"))
parser.add_argument("--output-root", type=Path, default=Path("results/cross_model_compact"))
return parser
def load_config(path: Path) -> BenchmarkConfig:
payload = json.loads(path.read_text(encoding="utf-8"))
if isinstance(payload, dict):
payload = {key: value for key, value in payload.items() if not str(key).startswith("$")}
return BenchmarkConfig.model_validate(payload)
def clone_config(config: BenchmarkConfig) -> BenchmarkConfig:
return BenchmarkConfig.model_validate(config.model_dump(mode="json"))
def prepare_openrouter_config(
base: BenchmarkConfig,
*,
suite_name: str,
model: str,
proposal_mode: str,
verifier_mode: str,
) -> BenchmarkConfig:
config = clone_config(base)
config.suite_name = suite_name
config.parallel_workers = 4
config.agent.kind = "openai_compatible_json"
config.agent.proposal_generation_mode = proposal_mode # type: ignore[assignment]
config.agent.verifier_generation_mode = verifier_mode # type: ignore[assignment]
config.agent.repair_generation_mode = "qwen_nonthinking_eval"
config.backend.provider = "openrouter"
config.backend.base_url = "https://openrouter.ai/api/v1"
config.backend.base_url_env = "OPENROUTER_BASE_URL"
config.backend.api_key_env = "OPENROUTER_API_KEY"
config.backend.model_env = "OPENROUTER_MODEL"
config.backend.model = model
config.backend.api_key = ""
config.backend.app_title = "LOCK-R"
config.backend.app_url = "https://github.com/openai/lockr-local"
return config
def run_suite(config: BenchmarkConfig, output_root: Path) -> dict[str, object]:
output_dir = output_root / config.suite_name
return BenchmarkRunner(config=config, output_dir=output_dir).run().model_dump(mode="json")
def safe_run_suite(config: BenchmarkConfig, output_root: Path) -> dict[str, object]:
try:
return run_suite(config, output_root)
except httpx.HTTPStatusError as exc:
if (
config.backend.model == "google/gemini-3.1-pro-preview"
and config.agent.proposal_generation_mode == "qwen_nonthinking_eval"
):
unsupported = {
"suite_name": f"{config.suite_name}__unsupported",
"model": config.backend.model,
"reason": str(exc),
"note": "OpenRouter reports that reasoning is mandatory for this Gemini endpoint.",
}
(output_root / f"{config.suite_name}__unsupported.json").write_text(
json.dumps(unsupported, indent=2),
encoding="utf-8",
)
return unsupported
if config.backend.model == "openai/gpt-5.4" and config.agent.proposal_generation_mode == "qwen_nonthinking_eval":
fallback = clone_config(config)
fallback.suite_name = f"{config.suite_name}__fallback_gpt53chat"
fallback.backend.model = "openai/gpt-5.3-chat"
return run_suite(fallback, output_root)
errored = {
"suite_name": f"{config.suite_name}__error",
"model": config.backend.model,
"proposal_mode": config.agent.proposal_generation_mode,
"reason": str(exc),
}
(output_root / f"{config.suite_name}__error.json").write_text(
json.dumps(errored, indent=2),
encoding="utf-8",
)
return errored
except Exception as exc:
errored = {
"suite_name": f"{config.suite_name}__error",
"model": config.backend.model,
"proposal_mode": config.agent.proposal_generation_mode,
"reason": repr(exc),
}
(output_root / f"{config.suite_name}__error.json").write_text(
json.dumps(errored, indent=2),
encoding="utf-8",
)
return errored
def main() -> None:
args = build_parser().parse_args()
api_key = os.getenv("OPENROUTER_API_KEY") or os.getenv("OPENAI_API_KEY")
if not api_key:
raise SystemExit("OPENROUTER_API_KEY is required for cross-model tests.")
os.environ["OPENROUTER_API_KEY"] = api_key
base = load_config(args.config)
suites = [
prepare_openrouter_config(
base,
suite_name="openrouter_gpt54_nonthinking",
model="openai/gpt-5.4",
proposal_mode="qwen_nonthinking_eval",
verifier_mode="qwen_nonthinking_eval",
),
prepare_openrouter_config(
base,
suite_name="openrouter_gpt54_thinking",
model="openai/gpt-5.4",
proposal_mode="qwen_precise_coding_thinking",
verifier_mode="qwen_nonthinking_eval",
),
prepare_openrouter_config(
base,
suite_name="openrouter_gemini31pro_nonthinking",
model="google/gemini-3.1-pro-preview",
proposal_mode="qwen_nonthinking_eval",
verifier_mode="qwen_nonthinking_eval",
),
prepare_openrouter_config(
base,
suite_name="openrouter_gemini31pro_thinking",
model="google/gemini-3.1-pro-preview",
proposal_mode="qwen_precise_coding_thinking",
verifier_mode="qwen_nonthinking_eval",
),
prepare_openrouter_config(
base,
suite_name="openrouter_gpt53chat_default",
model="openai/gpt-5.3-chat",
proposal_mode="qwen_nonthinking_eval",
verifier_mode="qwen_nonthinking_eval",
),
]
args.output_root.mkdir(parents=True, exist_ok=True)
index: list[dict[str, object]] = []
for suite in suites:
summary = safe_run_suite(suite, args.output_root)
if "regime_summaries" not in summary:
print(json.dumps(summary, indent=2))
index.append(summary)
continue
index.append(
{
"suite_name": summary["suite_name"],
"model": suite.backend.model,
"proposal_mode": suite.agent.proposal_generation_mode,
"regime_summaries": summary["regime_summaries"],
}
)
print(json.dumps({"suite_name": summary["suite_name"], "regime_summaries": summary["regime_summaries"]}, indent=2))
(args.output_root / "index.json").write_text(json.dumps(index, indent=2), encoding="utf-8")
if __name__ == "__main__":
main()