specbench-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- specbench_cli-0.1.0.dist-info/METADATA +236 -0
- specbench_cli-0.1.0.dist-info/RECORD +22 -0
- specbench_cli-0.1.0.dist-info/WHEEL +4 -0
- specbench_cli-0.1.0.dist-info/entry_points.txt +2 -0
- specbench_cli-0.1.0.dist-info/licenses/LICENSE +201 -0
- speculation_benchmark/__init__.py +45 -0
- speculation_benchmark/backends/__init__.py +27 -0
- speculation_benchmark/backends/base.py +73 -0
- speculation_benchmark/backends/llamacpp.py +660 -0
- speculation_benchmark/cli.py +661 -0
- speculation_benchmark/config.py +415 -0
- speculation_benchmark/hf_jobs.py +379 -0
- speculation_benchmark/publisher.py +196 -0
- speculation_benchmark/runner.py +479 -0
- speculation_benchmark/suites/__init__.py +19 -0
- speculation_benchmark/suites/base.py +96 -0
- speculation_benchmark/suites/bundled/assets/sample_architecture.png +0 -0
- speculation_benchmark/suites/bundled/assets/sample_bar_chart.png +0 -0
- speculation_benchmark/suites/bundled/coding_smoke.jsonl +5 -0
- speculation_benchmark/suites/bundled/multimodal_smoke.jsonl +2 -0
- speculation_benchmark/suites/loaders.py +715 -0
- speculation_benchmark/visualize.py +1228 -0
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import ast
|
|
4
|
+
import json
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
from urllib.parse import parse_qs
|
|
9
|
+
|
|
10
|
+
from speculation_benchmark.config import SuiteSpec
|
|
11
|
+
from speculation_benchmark.suites.base import (
|
|
12
|
+
BenchmarkSample,
|
|
13
|
+
build_chat_messages,
|
|
14
|
+
encode_image_to_data_url,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
REPO_ROOT = Path(__file__).resolve().parents[3]
|
|
18
|
+
BUNDLED_SUITES_DIR = Path(__file__).resolve().parent / "bundled"
|
|
19
|
+
DEFAULT_SUITES_DIR = (REPO_ROOT / "suites") if (REPO_ROOT / "suites").is_dir() else BUNDLED_SUITES_DIR
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class SuitePreset:
|
|
24
|
+
name: str
|
|
25
|
+
description: str
|
|
26
|
+
kind: str # "hf" | "hf_jsonl" | "local" | "aa_briefcase_lite"
|
|
27
|
+
target: str
|
|
28
|
+
hf_config: str | None = None
|
|
29
|
+
hf_split: str = "test"
|
|
30
|
+
hf_filename: str | None = None
|
|
31
|
+
prompt_column: str | None = None
|
|
32
|
+
image_columns: tuple[str, ...] = ()
|
|
33
|
+
id_column: str | None = None
|
|
34
|
+
options_column: str | None = None
|
|
35
|
+
system_prompt: str | None = None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
SUITE_PRESETS: dict[str, SuitePreset] = {
|
|
39
|
+
"coding": SuitePreset(
|
|
40
|
+
name="coding",
|
|
41
|
+
description="Artificial Analysis SWE-Atlas-QnA-AA (124 software engineering questions across Go/Python/C/TS)",
|
|
42
|
+
kind="hf",
|
|
43
|
+
target="ArtificialAnalysis/SWE-Atlas-QnA-AA",
|
|
44
|
+
hf_split="test",
|
|
45
|
+
prompt_column="prompt",
|
|
46
|
+
id_column="task_id",
|
|
47
|
+
system_prompt="You are an expert software engineer. Provide a clear, technically accurate, and thorough answer.",
|
|
48
|
+
),
|
|
49
|
+
"swe-atlas-qna": SuitePreset(
|
|
50
|
+
name="swe-atlas-qna",
|
|
51
|
+
description="Alias for ArtificialAnalysis/SWE-Atlas-QnA-AA",
|
|
52
|
+
kind="hf",
|
|
53
|
+
target="ArtificialAnalysis/SWE-Atlas-QnA-AA",
|
|
54
|
+
hf_split="test",
|
|
55
|
+
prompt_column="prompt",
|
|
56
|
+
id_column="task_id",
|
|
57
|
+
system_prompt="You are an expert software engineer. Provide a clear, technically accurate, and thorough answer.",
|
|
58
|
+
),
|
|
59
|
+
"livecodebench": SuitePreset(
|
|
60
|
+
name="livecodebench",
|
|
61
|
+
description="LiveCodeBench code generation problems (livecodebench/code_generation_lite, release v6)",
|
|
62
|
+
kind="hf_jsonl",
|
|
63
|
+
target="livecodebench/code_generation_lite",
|
|
64
|
+
hf_split="test",
|
|
65
|
+
hf_filename="test6.jsonl",
|
|
66
|
+
prompt_column="question_content",
|
|
67
|
+
id_column="question_id",
|
|
68
|
+
system_prompt="Write a clean, correct Python solution enclosed in a markdown code block.",
|
|
69
|
+
),
|
|
70
|
+
"multimodal": SuitePreset(
|
|
71
|
+
name="multimodal",
|
|
72
|
+
description="MMMU Pro (standard 4 options) — Artificial Analysis multimodal evaluation dataset",
|
|
73
|
+
kind="hf",
|
|
74
|
+
target="MMMU/MMMU_Pro",
|
|
75
|
+
hf_config="standard (4 options)",
|
|
76
|
+
hf_split="test",
|
|
77
|
+
prompt_column="question",
|
|
78
|
+
image_columns=("image_1", "image_2", "image_3", "image_4", "image_5", "image_6", "image_7"),
|
|
79
|
+
id_column="id",
|
|
80
|
+
options_column="options",
|
|
81
|
+
system_prompt="Analyze the provided image(s) carefully, show concise reasoning, and give the final answer.",
|
|
82
|
+
),
|
|
83
|
+
"mmmu-pro": SuitePreset(
|
|
84
|
+
name="mmmu-pro",
|
|
85
|
+
description="Alias for MMMU/MMMU_Pro (standard 4 options)",
|
|
86
|
+
kind="hf",
|
|
87
|
+
target="MMMU/MMMU_Pro",
|
|
88
|
+
hf_config="standard (4 options)",
|
|
89
|
+
hf_split="test",
|
|
90
|
+
prompt_column="question",
|
|
91
|
+
image_columns=("image_1", "image_2", "image_3", "image_4", "image_5", "image_6", "image_7"),
|
|
92
|
+
id_column="id",
|
|
93
|
+
options_column="options",
|
|
94
|
+
system_prompt="Analyze the provided image(s) carefully, show concise reasoning, and give the final answer.",
|
|
95
|
+
),
|
|
96
|
+
"smoke-coding": SuitePreset(
|
|
97
|
+
name="smoke-coding",
|
|
98
|
+
description="Local offline coding smoke suite (suites/coding_smoke.jsonl)",
|
|
99
|
+
kind="local",
|
|
100
|
+
target=str(DEFAULT_SUITES_DIR / "coding_smoke.jsonl"),
|
|
101
|
+
),
|
|
102
|
+
"smoke-multimodal": SuitePreset(
|
|
103
|
+
name="smoke-multimodal",
|
|
104
|
+
description="Local offline multimodal smoke suite (suites/multimodal_smoke.jsonl)",
|
|
105
|
+
kind="local",
|
|
106
|
+
target=str(DEFAULT_SUITES_DIR / "multimodal_smoke.jsonl"),
|
|
107
|
+
),
|
|
108
|
+
"aa-briefcase-lite": SuitePreset(
|
|
109
|
+
name="aa-briefcase-lite",
|
|
110
|
+
description="Artificial Analysis AA-Briefcase-Lite (4 commercial due-diligence knowledge-work tasks)",
|
|
111
|
+
kind="aa_briefcase_lite",
|
|
112
|
+
target="ArtificialAnalysis/AA-Briefcase-Lite",
|
|
113
|
+
system_prompt=(
|
|
114
|
+
"You are a senior private-equity analyst working on a commercial due-diligence engagement. "
|
|
115
|
+
"Produce a thorough, structured, publication-grade deliverable draft directly in your response."
|
|
116
|
+
),
|
|
117
|
+
),
|
|
118
|
+
"knowledge-work": SuitePreset(
|
|
119
|
+
name="knowledge-work",
|
|
120
|
+
description="Alias for ArtificialAnalysis/AA-Briefcase-Lite",
|
|
121
|
+
kind="aa_briefcase_lite",
|
|
122
|
+
target="ArtificialAnalysis/AA-Briefcase-Lite",
|
|
123
|
+
system_prompt=(
|
|
124
|
+
"You are a senior private-equity analyst working on a commercial due-diligence engagement. "
|
|
125
|
+
"Produce a thorough, structured, publication-grade deliverable draft directly in your response."
|
|
126
|
+
),
|
|
127
|
+
),
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _format_options(raw_options: Any) -> str:
|
|
132
|
+
if raw_options is None:
|
|
133
|
+
return ""
|
|
134
|
+
options: list[Any]
|
|
135
|
+
if isinstance(raw_options, str):
|
|
136
|
+
stripped = raw_options.strip()
|
|
137
|
+
if not stripped:
|
|
138
|
+
return ""
|
|
139
|
+
try:
|
|
140
|
+
parsed = ast.literal_eval(stripped)
|
|
141
|
+
options = parsed if isinstance(parsed, list) else [stripped]
|
|
142
|
+
except Exception:
|
|
143
|
+
options = [stripped]
|
|
144
|
+
elif isinstance(raw_options, list):
|
|
145
|
+
options = raw_options
|
|
146
|
+
else:
|
|
147
|
+
return ""
|
|
148
|
+
|
|
149
|
+
if not options:
|
|
150
|
+
return ""
|
|
151
|
+
lines = ["Options:"]
|
|
152
|
+
for idx, opt in enumerate(options):
|
|
153
|
+
label = chr(ord("A") + idx)
|
|
154
|
+
lines.append(f"({label}) {opt}")
|
|
155
|
+
return "\n".join(lines)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _normalize_existing_messages(
|
|
159
|
+
raw_messages: list[dict[str, Any]],
|
|
160
|
+
base_dir: Path | None,
|
|
161
|
+
) -> tuple[list[dict[str, Any]], bool]:
|
|
162
|
+
normalized: list[dict[str, Any]] = []
|
|
163
|
+
has_images = False
|
|
164
|
+
for msg in raw_messages:
|
|
165
|
+
role = msg.get("role", "user")
|
|
166
|
+
content = msg.get("content")
|
|
167
|
+
if isinstance(content, list):
|
|
168
|
+
parts: list[dict[str, Any]] = []
|
|
169
|
+
for part in content:
|
|
170
|
+
if not isinstance(part, dict):
|
|
171
|
+
continue
|
|
172
|
+
if part.get("type") == "image_url":
|
|
173
|
+
url_obj = part.get("image_url") or {}
|
|
174
|
+
raw_url = url_obj.get("url") if isinstance(url_obj, dict) else url_obj
|
|
175
|
+
if raw_url:
|
|
176
|
+
data_url = encode_image_to_data_url(raw_url, base_dir=base_dir)
|
|
177
|
+
parts.append({"type": "image_url", "image_url": {"url": data_url}})
|
|
178
|
+
has_images = True
|
|
179
|
+
elif part.get("type") == "image":
|
|
180
|
+
raw_img = part.get("image") or part.get("path")
|
|
181
|
+
if raw_img:
|
|
182
|
+
data_url = encode_image_to_data_url(raw_img, base_dir=base_dir)
|
|
183
|
+
parts.append({"type": "image_url", "image_url": {"url": data_url}})
|
|
184
|
+
has_images = True
|
|
185
|
+
else:
|
|
186
|
+
parts.append(part)
|
|
187
|
+
normalized.append({"role": role, "content": parts})
|
|
188
|
+
else:
|
|
189
|
+
normalized.append({"role": role, "content": str(content or "")})
|
|
190
|
+
return normalized, has_images
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _load_local_file(path: Path, spec: SuiteSpec) -> list[BenchmarkSample]:
|
|
194
|
+
if not path.exists():
|
|
195
|
+
raise FileNotFoundError(f"Curated suite file not found: {path}")
|
|
196
|
+
|
|
197
|
+
if path.suffix.lower() == ".jsonl":
|
|
198
|
+
rows = [
|
|
199
|
+
json.loads(line)
|
|
200
|
+
for line in path.read_text(encoding="utf-8").splitlines()
|
|
201
|
+
if line.strip()
|
|
202
|
+
]
|
|
203
|
+
elif path.suffix.lower() == ".json":
|
|
204
|
+
loaded = json.loads(path.read_text(encoding="utf-8"))
|
|
205
|
+
if not isinstance(loaded, list):
|
|
206
|
+
raise ValueError(f"JSON suite {path} must be a top-level list of sample objects.")
|
|
207
|
+
rows = loaded
|
|
208
|
+
else:
|
|
209
|
+
raise ValueError(f"Unsupported local suite file format: {path.suffix} (use .jsonl or .json)")
|
|
210
|
+
|
|
211
|
+
samples: list[BenchmarkSample] = []
|
|
212
|
+
base_dir = path.parent
|
|
213
|
+
for idx, row in enumerate(rows):
|
|
214
|
+
if spec.limit is not None and len(samples) >= spec.limit:
|
|
215
|
+
break
|
|
216
|
+
if not isinstance(row, dict):
|
|
217
|
+
continue
|
|
218
|
+
|
|
219
|
+
sample_id = str(row.get(spec.id_column or "id") or row.get("sample_id") or f"{spec.capability}-{idx}")
|
|
220
|
+
capability = str(row.get("capability") or spec.capability)
|
|
221
|
+
sys_prompt = row.get("system_prompt") or spec.system_prompt
|
|
222
|
+
|
|
223
|
+
if "messages" in row and isinstance(row["messages"], list):
|
|
224
|
+
messages, has_images = _normalize_existing_messages(row["messages"], base_dir=base_dir)
|
|
225
|
+
if sys_prompt and (not messages or messages[0].get("role") != "system"):
|
|
226
|
+
messages = [{"role": "system", "content": sys_prompt}, *messages]
|
|
227
|
+
else:
|
|
228
|
+
prompt_text = _detect_prompt(row, spec.prompt_column) or ""
|
|
229
|
+
if not prompt_text:
|
|
230
|
+
continue
|
|
231
|
+
images_raw = row.get("images")
|
|
232
|
+
if images_raw is None and row.get("image") is not None:
|
|
233
|
+
images_raw = [row["image"]]
|
|
234
|
+
messages, has_images = build_chat_messages(
|
|
235
|
+
prompt=prompt_text,
|
|
236
|
+
images=images_raw if isinstance(images_raw, list) else None,
|
|
237
|
+
system_prompt=sys_prompt,
|
|
238
|
+
base_dir=base_dir,
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
meta = {
|
|
242
|
+
k: v
|
|
243
|
+
for k, v in row.items()
|
|
244
|
+
if k not in {"id", "sample_id", "prompt", "question", "messages", "images", "image", "system_prompt"}
|
|
245
|
+
}
|
|
246
|
+
samples.append(
|
|
247
|
+
BenchmarkSample(
|
|
248
|
+
sample_id=sample_id,
|
|
249
|
+
capability=capability,
|
|
250
|
+
source_dataset=str(path),
|
|
251
|
+
messages=messages,
|
|
252
|
+
has_images=has_images,
|
|
253
|
+
metadata=meta,
|
|
254
|
+
)
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
if not samples:
|
|
258
|
+
raise RuntimeError(f"No usable samples loaded from {path}")
|
|
259
|
+
return samples
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
_AUTO_PROMPT_COLUMNS: tuple[str, ...] = (
|
|
263
|
+
"prompt",
|
|
264
|
+
"question",
|
|
265
|
+
"question_content",
|
|
266
|
+
"instruction",
|
|
267
|
+
"problem",
|
|
268
|
+
"query",
|
|
269
|
+
"input",
|
|
270
|
+
"text",
|
|
271
|
+
"content",
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
_SPLIT_PRIORITY: tuple[str, ...] = ("test", "validation", "val", "dev", "train")
|
|
275
|
+
|
|
276
|
+
_SHAREGPT_ROLE_MAP: dict[str, str] = {
|
|
277
|
+
"human": "user",
|
|
278
|
+
"user": "user",
|
|
279
|
+
"gpt": "assistant",
|
|
280
|
+
"assistant": "assistant",
|
|
281
|
+
"model": "assistant",
|
|
282
|
+
"system": "system",
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def _detect_prompt(row: dict[str, Any], preferred_col: str | None) -> str | None:
|
|
287
|
+
candidates = [preferred_col] if preferred_col else []
|
|
288
|
+
candidates.extend(_AUTO_PROMPT_COLUMNS)
|
|
289
|
+
for key in candidates:
|
|
290
|
+
if not key:
|
|
291
|
+
continue
|
|
292
|
+
val = row.get(key)
|
|
293
|
+
if isinstance(val, str) and val.strip():
|
|
294
|
+
return val.strip()
|
|
295
|
+
turns = row.get("turns")
|
|
296
|
+
if isinstance(turns, list) and turns:
|
|
297
|
+
first = str(turns[0]).strip()
|
|
298
|
+
if first:
|
|
299
|
+
return first
|
|
300
|
+
return None
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def _extract_chat_messages(
|
|
304
|
+
row: dict[str, Any],
|
|
305
|
+
*,
|
|
306
|
+
preferred_col: str | None,
|
|
307
|
+
images: list[Any],
|
|
308
|
+
system_prompt: str | None,
|
|
309
|
+
) -> tuple[list[dict[str, Any]], bool] | None:
|
|
310
|
+
"""Normalize OpenAI `messages` or ShareGPT `conversations` columns to raw chat messages.
|
|
311
|
+
|
|
312
|
+
Trailing assistant turns are stripped so the target model generates a fresh completion,
|
|
313
|
+
while llama-server applies the target model's own GGUF chat template.
|
|
314
|
+
"""
|
|
315
|
+
chat_candidates = [preferred_col] if preferred_col else []
|
|
316
|
+
chat_candidates.extend(["messages", "conversations"])
|
|
317
|
+
raw_turns: list[Any] | None = None
|
|
318
|
+
for key in chat_candidates:
|
|
319
|
+
if not key:
|
|
320
|
+
continue
|
|
321
|
+
val = row.get(key)
|
|
322
|
+
if isinstance(val, list) and val and isinstance(val[0], dict):
|
|
323
|
+
raw_turns = val
|
|
324
|
+
break
|
|
325
|
+
if not raw_turns:
|
|
326
|
+
return None
|
|
327
|
+
|
|
328
|
+
normalized_input: list[dict[str, Any]] = []
|
|
329
|
+
for turn in raw_turns:
|
|
330
|
+
if not isinstance(turn, dict):
|
|
331
|
+
continue
|
|
332
|
+
if "role" in turn:
|
|
333
|
+
role = str(turn.get("role", "user")).strip().lower()
|
|
334
|
+
content = turn.get("content")
|
|
335
|
+
elif "from" in turn:
|
|
336
|
+
role = _SHAREGPT_ROLE_MAP.get(str(turn.get("from", "human")).strip().lower(), "user")
|
|
337
|
+
content = turn.get("value", turn.get("content"))
|
|
338
|
+
else:
|
|
339
|
+
continue
|
|
340
|
+
normalized_input.append({"role": role, "content": content})
|
|
341
|
+
|
|
342
|
+
# Drop trailing assistant turns so we prompt the model to generate the response
|
|
343
|
+
while normalized_input and normalized_input[-1].get("role") == "assistant":
|
|
344
|
+
normalized_input.pop()
|
|
345
|
+
|
|
346
|
+
if not normalized_input or not any(m.get("role") == "user" for m in normalized_input):
|
|
347
|
+
return None
|
|
348
|
+
|
|
349
|
+
messages, has_images = _normalize_existing_messages(normalized_input, base_dir=None)
|
|
350
|
+
if system_prompt and (not messages or messages[0].get("role") != "system"):
|
|
351
|
+
messages = [{"role": "system", "content": system_prompt}, *messages]
|
|
352
|
+
|
|
353
|
+
if images and not has_images:
|
|
354
|
+
# Attach row-level images to the final user turn
|
|
355
|
+
for idx in range(len(messages) - 1, -1, -1):
|
|
356
|
+
if messages[idx].get("role") == "user":
|
|
357
|
+
user_content = messages[idx].get("content")
|
|
358
|
+
parts: list[dict[str, Any]] = (
|
|
359
|
+
list(user_content)
|
|
360
|
+
if isinstance(user_content, list)
|
|
361
|
+
else [{"type": "text", "text": str(user_content or "")}]
|
|
362
|
+
)
|
|
363
|
+
for img in images:
|
|
364
|
+
data_url = encode_image_to_data_url(img)
|
|
365
|
+
parts.append({"type": "image_url", "image_url": {"url": data_url}})
|
|
366
|
+
messages[idx]["content"] = parts
|
|
367
|
+
has_images = True
|
|
368
|
+
break
|
|
369
|
+
|
|
370
|
+
return messages, has_images
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def _parse_hf_source(raw: str) -> tuple[str, dict[str, str]]:
|
|
374
|
+
"""Parse `hf:<repo_id>[?config=...&split=...&prompt_column=...&image_columns=...&id_column=...]`."""
|
|
375
|
+
body = raw.removeprefix("hf:").strip()
|
|
376
|
+
if "?" not in body:
|
|
377
|
+
return body, {}
|
|
378
|
+
repo_part, query_part = body.split("?", 1)
|
|
379
|
+
parsed = parse_qs(query_part, keep_blank_values=False)
|
|
380
|
+
params = {k.strip(): v[-1].strip() for k, v in parsed.items() if v}
|
|
381
|
+
return repo_part.strip(), params
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def _resolve_hf_config_and_split(
|
|
385
|
+
repo_id: str,
|
|
386
|
+
hf_config: str | None,
|
|
387
|
+
hf_split: str | None,
|
|
388
|
+
) -> tuple[str | None, str]:
|
|
389
|
+
"""Auto-detect dataset config (when unambiguous) and split (test -> validation -> val -> dev -> train)."""
|
|
390
|
+
from datasets import get_dataset_config_names, get_dataset_split_names
|
|
391
|
+
|
|
392
|
+
resolved_config = hf_config
|
|
393
|
+
if resolved_config is None:
|
|
394
|
+
try:
|
|
395
|
+
configs = get_dataset_config_names(repo_id)
|
|
396
|
+
except Exception:
|
|
397
|
+
configs = []
|
|
398
|
+
if len(configs) == 1:
|
|
399
|
+
resolved_config = configs[0]
|
|
400
|
+
elif "default" in configs:
|
|
401
|
+
resolved_config = "default"
|
|
402
|
+
elif len(configs) > 1:
|
|
403
|
+
preview = ", ".join(configs[:8])
|
|
404
|
+
suffix = f" (+{len(configs) - 8} more)" if len(configs) > 8 else ""
|
|
405
|
+
raise ValueError(
|
|
406
|
+
f"Dataset {repo_id!r} has multiple configs ({preview}{suffix}). "
|
|
407
|
+
f"Specify one with `hf:{repo_id}?config=<name>` or `hf_config` in YAML."
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
if hf_split:
|
|
411
|
+
return resolved_config, hf_split
|
|
412
|
+
|
|
413
|
+
try:
|
|
414
|
+
splits = list(get_dataset_split_names(repo_id, config_name=resolved_config))
|
|
415
|
+
except Exception:
|
|
416
|
+
splits = []
|
|
417
|
+
|
|
418
|
+
for preferred in _SPLIT_PRIORITY:
|
|
419
|
+
if preferred in splits:
|
|
420
|
+
return resolved_config, preferred
|
|
421
|
+
if splits:
|
|
422
|
+
return resolved_config, splits[0]
|
|
423
|
+
return resolved_config, "test"
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def _extract_images(row: dict[str, Any], image_columns: list[str] | None) -> list[Any]:
|
|
427
|
+
cols = image_columns if image_columns else [
|
|
428
|
+
"image",
|
|
429
|
+
"images",
|
|
430
|
+
"img",
|
|
431
|
+
"image_1",
|
|
432
|
+
"image_2",
|
|
433
|
+
"image_3",
|
|
434
|
+
"image_4",
|
|
435
|
+
"image_5",
|
|
436
|
+
"image_6",
|
|
437
|
+
"image_7",
|
|
438
|
+
]
|
|
439
|
+
found: list[Any] = []
|
|
440
|
+
for col in cols:
|
|
441
|
+
if col not in row:
|
|
442
|
+
continue
|
|
443
|
+
val = row[col]
|
|
444
|
+
if val is None:
|
|
445
|
+
continue
|
|
446
|
+
if isinstance(val, list):
|
|
447
|
+
found.extend(item for item in val if item is not None)
|
|
448
|
+
else:
|
|
449
|
+
found.append(val)
|
|
450
|
+
return found
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def _load_hf_dataset(
|
|
454
|
+
repo_id: str,
|
|
455
|
+
spec: SuiteSpec,
|
|
456
|
+
preset: SuitePreset | None = None,
|
|
457
|
+
query_params: dict[str, str] | None = None,
|
|
458
|
+
) -> list[BenchmarkSample]:
|
|
459
|
+
from datasets import load_dataset
|
|
460
|
+
|
|
461
|
+
qp = query_params or {}
|
|
462
|
+
raw_config = (
|
|
463
|
+
spec.hf_config
|
|
464
|
+
if spec.hf_config is not None
|
|
465
|
+
else qp.get("config", preset.hf_config if preset else None)
|
|
466
|
+
)
|
|
467
|
+
raw_split = (
|
|
468
|
+
spec.hf_split
|
|
469
|
+
if spec.hf_split is not None
|
|
470
|
+
else qp.get("split", preset.hf_split if preset else None)
|
|
471
|
+
)
|
|
472
|
+
hf_config, hf_split = _resolve_hf_config_and_split(repo_id, raw_config, raw_split)
|
|
473
|
+
|
|
474
|
+
prompt_col = spec.prompt_column or qp.get("prompt_column") or (preset.prompt_column if preset else None)
|
|
475
|
+
qp_image_cols = [c.strip() for c in qp["image_columns"].split(",") if c.strip()] if qp.get("image_columns") else None
|
|
476
|
+
image_cols = spec.image_columns or qp_image_cols or (list(preset.image_columns) if preset and preset.image_columns else None)
|
|
477
|
+
id_col = spec.id_column or qp.get("id_column") or (preset.id_column if preset else None)
|
|
478
|
+
options_col = preset.options_column if preset else "options"
|
|
479
|
+
sys_prompt = spec.system_prompt if spec.system_prompt is not None else (preset.system_prompt if preset else None)
|
|
480
|
+
|
|
481
|
+
split_expr = f"{hf_split}[:{spec.limit}]" if (spec.limit is not None and "[" not in hf_split) else hf_split
|
|
482
|
+
try:
|
|
483
|
+
ds = load_dataset(repo_id, name=hf_config, split=split_expr)
|
|
484
|
+
except Exception:
|
|
485
|
+
ds = load_dataset(repo_id, name=hf_config, split=hf_split)
|
|
486
|
+
|
|
487
|
+
samples: list[BenchmarkSample] = []
|
|
488
|
+
for idx, row_raw in enumerate(ds):
|
|
489
|
+
if spec.limit is not None and len(samples) >= spec.limit:
|
|
490
|
+
break
|
|
491
|
+
row = dict(row_raw)
|
|
492
|
+
images = _extract_images(row, image_cols)
|
|
493
|
+
|
|
494
|
+
chat_result = _extract_chat_messages(
|
|
495
|
+
row,
|
|
496
|
+
preferred_col=prompt_col,
|
|
497
|
+
images=images,
|
|
498
|
+
system_prompt=sys_prompt,
|
|
499
|
+
)
|
|
500
|
+
if chat_result is not None:
|
|
501
|
+
messages, has_images = chat_result
|
|
502
|
+
else:
|
|
503
|
+
prompt_text = _detect_prompt(row, prompt_col)
|
|
504
|
+
if not prompt_text:
|
|
505
|
+
continue
|
|
506
|
+
|
|
507
|
+
if options_col and row.get(options_col) is not None:
|
|
508
|
+
opts_text = _format_options(row[options_col])
|
|
509
|
+
if opts_text:
|
|
510
|
+
prompt_text = f"{prompt_text}\n\n{opts_text}"
|
|
511
|
+
|
|
512
|
+
messages, has_images = build_chat_messages(
|
|
513
|
+
prompt=prompt_text,
|
|
514
|
+
images=images,
|
|
515
|
+
system_prompt=sys_prompt,
|
|
516
|
+
)
|
|
517
|
+
|
|
518
|
+
sample_id = str(
|
|
519
|
+
(row.get(id_col) if id_col else None)
|
|
520
|
+
or row.get("id")
|
|
521
|
+
or row.get("task_id")
|
|
522
|
+
or row.get("question_id")
|
|
523
|
+
or f"{spec.capability}-{idx}"
|
|
524
|
+
)
|
|
525
|
+
|
|
526
|
+
source_label = f"{repo_id}" + (f"/{hf_config}" if hf_config else "") + f"[{hf_split}]"
|
|
527
|
+
samples.append(
|
|
528
|
+
BenchmarkSample(
|
|
529
|
+
sample_id=sample_id,
|
|
530
|
+
capability=spec.capability,
|
|
531
|
+
source_dataset=source_label,
|
|
532
|
+
messages=messages,
|
|
533
|
+
has_images=has_images,
|
|
534
|
+
metadata={
|
|
535
|
+
k: str(v)[:200]
|
|
536
|
+
for k, v in row.items()
|
|
537
|
+
if isinstance(v, (str, int, float, bool)) and k not in {prompt_col, "prompt", "question", "options"}
|
|
538
|
+
},
|
|
539
|
+
)
|
|
540
|
+
)
|
|
541
|
+
|
|
542
|
+
if not samples:
|
|
543
|
+
raise RuntimeError(
|
|
544
|
+
f"No usable samples loaded from HF dataset {repo_id!r} (config={hf_config!r}, split={hf_split!r}). "
|
|
545
|
+
"Pass ?prompt_column=<col> if your prompt column has a custom name."
|
|
546
|
+
)
|
|
547
|
+
return samples
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
def _load_aa_briefcase_lite(
|
|
551
|
+
repo_id: str,
|
|
552
|
+
spec: SuiteSpec,
|
|
553
|
+
preset: SuitePreset,
|
|
554
|
+
) -> list[BenchmarkSample]:
|
|
555
|
+
"""Load ArtificialAnalysis/AA-Briefcase-Lite tasks with inlined scenario, week, and task briefs."""
|
|
556
|
+
from huggingface_hub import hf_hub_download
|
|
557
|
+
|
|
558
|
+
def _read_repo_text(filename: str) -> str:
|
|
559
|
+
local_path = hf_hub_download(repo_id=repo_id, filename=filename, repo_type="dataset")
|
|
560
|
+
return Path(local_path).read_text(encoding="utf-8").strip()
|
|
561
|
+
|
|
562
|
+
tasks_text = _read_repo_text("tasks.jsonl")
|
|
563
|
+
task_rows = [json.loads(line) for line in tasks_text.splitlines() if line.strip()]
|
|
564
|
+
|
|
565
|
+
text_cache: dict[str, str] = {}
|
|
566
|
+
|
|
567
|
+
def _cached_text(filename: str) -> str:
|
|
568
|
+
if filename not in text_cache:
|
|
569
|
+
text_cache[filename] = _read_repo_text(filename)
|
|
570
|
+
return text_cache[filename]
|
|
571
|
+
|
|
572
|
+
sys_prompt = spec.system_prompt if spec.system_prompt is not None else preset.system_prompt
|
|
573
|
+
samples: list[BenchmarkSample] = []
|
|
574
|
+
|
|
575
|
+
for row in task_rows:
|
|
576
|
+
if spec.limit is not None and len(samples) >= spec.limit:
|
|
577
|
+
break
|
|
578
|
+
|
|
579
|
+
task_id = str(row["task_id"])
|
|
580
|
+
scenario_overview = _cached_text(row["scenario_overview_path"])
|
|
581
|
+
week_overview = _cached_text(row["week_overview_path"])
|
|
582
|
+
task_brief = _cached_text(row["task_md_path"])
|
|
583
|
+
deliverables = row.get("deliverable_filenames") or []
|
|
584
|
+
source_files = [*(row.get("shared_files") or []), *(row.get("week_files") or [])]
|
|
585
|
+
|
|
586
|
+
deliverables_block = "\n".join(f"- {name}" for name in deliverables)
|
|
587
|
+
sources_preview = "\n".join(f"- {path}" for path in source_files[:40])
|
|
588
|
+
if len(source_files) > 40:
|
|
589
|
+
sources_preview += f"\n- ... ({len(source_files) - 40} more source files)"
|
|
590
|
+
|
|
591
|
+
prompt = (
|
|
592
|
+
f"<scenario_overview>\n{scenario_overview}\n</scenario_overview>\n\n"
|
|
593
|
+
f"<week_overview>\n{week_overview}\n</week_overview>\n\n"
|
|
594
|
+
f"<task_description>\n{task_brief}\n</task_description>\n\n"
|
|
595
|
+
f"<deliverables>\n{deliverables_block}\n</deliverables>\n\n"
|
|
596
|
+
f"<source_pool_index count=\"{len(source_files)}\">\n{sources_preview}\n</source_pool_index>\n\n"
|
|
597
|
+
"Draft the deliverable content and analytical plan for this task in detail, noting key assumptions "
|
|
598
|
+
"and confirmatory diligence questions."
|
|
599
|
+
)
|
|
600
|
+
|
|
601
|
+
messages, has_images = build_chat_messages(
|
|
602
|
+
prompt=prompt,
|
|
603
|
+
images=None,
|
|
604
|
+
system_prompt=sys_prompt,
|
|
605
|
+
)
|
|
606
|
+
samples.append(
|
|
607
|
+
BenchmarkSample(
|
|
608
|
+
sample_id=task_id,
|
|
609
|
+
capability=spec.capability,
|
|
610
|
+
source_dataset=f"{repo_id}[tasks]",
|
|
611
|
+
messages=messages,
|
|
612
|
+
has_images=has_images,
|
|
613
|
+
metadata={
|
|
614
|
+
"week": str(row.get("week", "")),
|
|
615
|
+
"deliverables": ", ".join(deliverables),
|
|
616
|
+
"source_file_count": str(len(source_files)),
|
|
617
|
+
},
|
|
618
|
+
)
|
|
619
|
+
)
|
|
620
|
+
|
|
621
|
+
if not samples:
|
|
622
|
+
raise RuntimeError(f"No tasks loaded from {repo_id}")
|
|
623
|
+
return samples
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
def _load_hf_jsonl(
|
|
627
|
+
repo_id: str,
|
|
628
|
+
spec: SuiteSpec,
|
|
629
|
+
preset: SuitePreset,
|
|
630
|
+
) -> list[BenchmarkSample]:
|
|
631
|
+
"""Load a raw JSONL file from a HF dataset repo (avoids legacy dataset script errors on datasets>=4)."""
|
|
632
|
+
from huggingface_hub import hf_hub_download
|
|
633
|
+
|
|
634
|
+
filename = preset.hf_filename or "test.jsonl"
|
|
635
|
+
local_path = Path(hf_hub_download(repo_id=repo_id, filename=filename, repo_type="dataset"))
|
|
636
|
+
prompt_col = spec.prompt_column or preset.prompt_column
|
|
637
|
+
id_col = spec.id_column or preset.id_column
|
|
638
|
+
sys_prompt = spec.system_prompt if spec.system_prompt is not None else preset.system_prompt
|
|
639
|
+
|
|
640
|
+
samples: list[BenchmarkSample] = []
|
|
641
|
+
with local_path.open("r", encoding="utf-8") as fh:
|
|
642
|
+
for idx, line in enumerate(fh):
|
|
643
|
+
if spec.limit is not None and len(samples) >= spec.limit:
|
|
644
|
+
break
|
|
645
|
+
line = line.strip()
|
|
646
|
+
if not line:
|
|
647
|
+
continue
|
|
648
|
+
row = json.loads(line)
|
|
649
|
+
prompt_text = _detect_prompt(row, prompt_col)
|
|
650
|
+
if not prompt_text:
|
|
651
|
+
continue
|
|
652
|
+
messages, has_images = build_chat_messages(
|
|
653
|
+
prompt=prompt_text,
|
|
654
|
+
images=None,
|
|
655
|
+
system_prompt=sys_prompt,
|
|
656
|
+
)
|
|
657
|
+
sample_id = str(
|
|
658
|
+
(row.get(id_col) if id_col else None)
|
|
659
|
+
or row.get("id")
|
|
660
|
+
or row.get("task_id")
|
|
661
|
+
or row.get("question_id")
|
|
662
|
+
or f"{spec.capability}-{idx}"
|
|
663
|
+
)
|
|
664
|
+
samples.append(
|
|
665
|
+
BenchmarkSample(
|
|
666
|
+
sample_id=sample_id,
|
|
667
|
+
capability=spec.capability,
|
|
668
|
+
source_dataset=f"{repo_id}/{filename}",
|
|
669
|
+
messages=messages,
|
|
670
|
+
has_images=has_images,
|
|
671
|
+
metadata={
|
|
672
|
+
k: str(v)[:200]
|
|
673
|
+
for k, v in row.items()
|
|
674
|
+
if isinstance(v, (str, int, float, bool)) and k not in {prompt_col, "prompt", "question"}
|
|
675
|
+
},
|
|
676
|
+
)
|
|
677
|
+
)
|
|
678
|
+
if not samples:
|
|
679
|
+
raise RuntimeError(f"No usable samples loaded from {repo_id}/{filename}")
|
|
680
|
+
return samples
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
def load_suite(spec: SuiteSpec) -> list[BenchmarkSample]:
|
|
684
|
+
"""Load a BenchmarkSample list from a preset, local JSONL/JSON file, or HF dataset."""
|
|
685
|
+
source = spec.source.strip()
|
|
686
|
+
if source.startswith("preset:"):
|
|
687
|
+
preset_name = source.removeprefix("preset:").strip().replace("_", "-")
|
|
688
|
+
if preset_name not in SUITE_PRESETS:
|
|
689
|
+
available = ", ".join(sorted(SUITE_PRESETS))
|
|
690
|
+
raise ValueError(f"Unknown suite preset {preset_name!r}. Available presets: {available}")
|
|
691
|
+
preset = SUITE_PRESETS[preset_name]
|
|
692
|
+
if preset.kind == "local":
|
|
693
|
+
return _load_local_file(Path(preset.target), spec)
|
|
694
|
+
if preset.kind == "aa_briefcase_lite":
|
|
695
|
+
return _load_aa_briefcase_lite(preset.target, spec, preset)
|
|
696
|
+
if preset.kind == "hf_jsonl":
|
|
697
|
+
return _load_hf_jsonl(preset.target, spec, preset)
|
|
698
|
+
return _load_hf_dataset(preset.target, spec, preset=preset)
|
|
699
|
+
|
|
700
|
+
if source.startswith("hf:"):
|
|
701
|
+
repo_id, query_params = _parse_hf_source(source)
|
|
702
|
+
if not repo_id:
|
|
703
|
+
raise ValueError("Empty HF dataset repo ID in suite source 'hf:'.")
|
|
704
|
+
return _load_hf_dataset(repo_id, spec, query_params=query_params)
|
|
705
|
+
|
|
706
|
+
return _load_local_file(Path(source), spec)
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
def load_all_suites(specs: list[SuiteSpec]) -> dict[str, list[BenchmarkSample]]:
|
|
710
|
+
"""Load all configured capability suites keyed by capability name."""
|
|
711
|
+
grouped: dict[str, list[BenchmarkSample]] = {}
|
|
712
|
+
for spec in specs:
|
|
713
|
+
loaded = load_suite(spec)
|
|
714
|
+
grouped.setdefault(spec.capability, []).extend(loaded)
|
|
715
|
+
return grouped
|