Dawn9705's picture
Add files using upload-large-folder tool
e90df0f verified
Raw History Blame Contribute Delete
4.23 kB
#!/usr/bin/env python3
"""Validate retained aggregate and leaf metrics for the alignment run."""
from __future__ import annotations
import argparse
import json
import math
from pathlib import Path
EXPECTED = {"base": 95, "easy": 192, "fim": 3}
REQUIRED = {
"base": (
"olmo3:base:math",
"arc_easy:mc::xlarge",
"arc_challenge:mc::xlarge",
"mmlu_stem:mc::olmes",
"medmcqa:mc::none",
"medqa_en:mc::none",
"sciq:mc::xlarge",
"olmo3:base:nonstem_qa_mc",
"olmo3:base:gen",
),
"easy": (
"olmo3:base_easy:qa_bpb",
"olmo3:base_easy:math_bpb",
"olmo3:base_easy:code_bpb",
),
"fim": (
"codex_humanevalfim_single::olmo3",
"codex_humanevalfim_multi::olmo3",
"codex_humanevalfim_random::olmo3",
),
}
# OLMES 当前不会为两个 ARC RC 子套件生成外层 aggregate,进而也不会
# 直接生成 QA BPB aggregate。叶子结果完整时按 task_suites.py 的 macro
# 层级重建;若未来 OLMES 原生输出这些 aggregate,仍优先使用原生结果。
FALLBACK_GROUPS = {
"arc:rc:bpb::olmes:full": (
"arc_easy:rc:bpb::olmes:full",
"arc_challenge:rc:bpb::olmes:full",
),
"olmo3:base_easy:qa_bpb": (
"arc:rc:bpb::olmes:full",
"mmlu:rc:bpb::olmes",
"csqa:rc:bpb::olmes:full",
"hellaswag:rc:bpb::olmes:full",
"winogrande:rc:bpb::olmes:full",
"socialiqa:rc:bpb::olmes:full",
"piqa:rc:bpb::olmes:full",
"coqa:rc:bpb::gen2mc:xlarge",
"drop:rc:bpb::gen2mc:xlarge",
"jeopardy:rc:bpb::gen2mc:xlarge",
"naturalqs:rc:bpb::gen2mc:xlarge",
"squad:rc:bpb::gen2mc:xlarge",
"sciq:rc:bpb::olmo3",
"qasper_yesno:rc:bpb::olmes",
"basic_skills:rc:bpb::olmes",
"lab_bench_dbqa:bpb",
"lab_bench_protocolqa:bpb",
"lambada:bpb",
"medmcqa:rc:bpb::none",
"medqa_en:rc:bpb::none",
"sciriff_yesno:rc:bpb::olmes",
),
}
def resolve_score(alias: str, scores: dict[str, float], stack: tuple[str, ...] = ()) -> float:
if alias in scores:
return scores[alias]
if alias in stack:
raise ValueError(f"aggregate cycle: {' -> '.join((*stack, alias))}")
children = FALLBACK_GROUPS.get(alias)
if children is None:
raise KeyError(alias)
value = sum(resolve_score(child, scores, (*stack, alias)) for child in children) / len(children)
scores[alias] = value
return value
def validate(kind: str, output: Path) -> None:
for name in ("metrics.json", "metrics-all.jsonl"):
if not (output / name).is_file():
raise FileNotFoundError(output / name)
json.loads((output / "metrics.json").read_text(encoding="utf-8"))
leaves = len(list(output.glob("task-*-metrics.json")))
if leaves != EXPECTED[kind]:
raise ValueError(f"{kind} 叶子任务应为 {EXPECTED[kind]},实际 {leaves}")
scores: dict[str, float] = {}
with (output / "metrics-all.jsonl").open(encoding="utf-8") as handle:
for number, line in enumerate(handle, start=1):
if not line.strip():
continue
row = json.loads(line)
config = row.get("task_config") or {}
alias = (config.get("metadata") or {}).get("alias") or row.get("task_name")
score = (row.get("metrics") or {}).get("primary_score")
if alias is None or not isinstance(score, (int, float)) or not math.isfinite(score):
raise ValueError(f"第 {number} 行无效:{alias=} {score=}")
scores[str(alias)] = float(score)
missing = []
for alias in REQUIRED[kind]:
try:
resolve_score(alias, scores)
except KeyError:
missing.append(alias)
if missing:
raise ValueError(f"{kind} 缺少必要结果:{missing}")
print(f"{kind} 结果完整:{output}")
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("kind", choices=tuple(EXPECTED))
parser.add_argument("output", type=Path)
args = parser.parse_args()
validate(args.kind, args.output)
if __name__ == "__main__":
main()