"""Independently verify downloaded HellaSwag samples without rerunning inference.""" import argparse import hashlib import json import math import re import zipfile from collections import Counter from datetime import datetime, timezone from pathlib import Path import pyarrow.parquet as pq ROOT = Path(__file__).resolve().parents[1] MODEL_SHA = "0f7bdaaae88077174d371c650759b71b83fce6e917638703b72466d59a2b3c9e" TOKENIZER_SHA = "27cb97f527f7eee80c7de32e04ba9cc32f8b8c2117d8664690443d53e228433b" DATA_SHA = "899813071e1e95efafec90f856e1987d2150fa4d020fc005df6962c259f660cd" WHEEL_SHA = "5daaa1973bf874005f64f28d3834b875f6886f0d6475878e6a6c821994a5286a" def sha(path): with Path(path).open("rb") as handle: return hashlib.file_digest(handle, "sha256").hexdigest() def require(condition, message): if not condition: raise ValueError(message) def preprocess(text): # Independently reproduced from the pinned official HellaSwag task utility. text = text.strip().replace(" [title]", ". ") return re.sub(r"\[.*?\]", "", text).replace(" ", " ") def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--run", type=Path, default=ROOT / "downloads/evaluations/hellaswag-v1") args = parser.parse_args() run = args.run.resolve() data = run / "hellaswag" summary = json.loads((data / "summary.json").read_text(encoding="utf-8")) native = json.loads((data / "results.json").read_text(encoding="utf-8")) source = json.loads((run / "download_source.json").read_text(encoding="utf-8")) model = ROOT / "downloads/run-v7/think72/run/model" require(sha(model / "model.safetensors") == summary["model_sha256"] == MODEL_SHA, "Final local model identity mismatch") require(sha(model / "tokenizer.json") == summary["tokenizer_sha256"] == TOKENIZER_SHA, "Tokenizer identity mismatch") require(sha(data / "validation.parquet") == summary["dataset_file_sha256"] == DATA_SHA, "Validation dataset identity mismatch") require(sha(data / "hellaswag_worker.py") == sha(ROOT / "evaluation/hellaswag_worker.py"), "Downloaded worker differs from submitted source") wheel = ROOT / "artifacts/hellaswag/lm_eval-0.4.13-py3-none-any.whl" require(sha(wheel) == WHEEL_SHA, "Official harness wheel identity mismatch") with zipfile.ZipFile(wheel) as archive: task_sha = hashlib.sha256(archive.read("lm_eval/tasks/hellaswag/hellaswag.yaml")).hexdigest() require(task_sha == summary["task_yaml_sha256"], "Official task YAML mismatch") require(summary["model_step"] == 22889 and summary["examples"] == 10042, "Wrong checkpoint or incomplete evaluation") require(summary["num_fewshot"] == 0 and summary["apply_chat_template"] is False and summary["add_bos_token"] is False and summary["dtype"] == "float32", "Unexpected evaluation protocol") rows = pq.read_table(data / "validation.parquet").to_pylist() require(len(rows) == 10042, "Incorrect validation split length") seen = set() correct = Counter(acc=0, acc_norm=0) labels = Counter() for line in (data / "samples.jsonl").read_text(encoding="utf-8").splitlines(): sample = json.loads(line) index = sample["doc_id"] require(isinstance(index, int) and 0 <= index < len(rows) and index not in seen, f"Invalid or duplicate doc_id: {index}") seen.add(index) row, doc = rows[index], sample["doc"] require(all(doc[key] == value for key, value in row.items()), f"Source row mismatch: {index}") gold = int(row["label"]) choices = [preprocess(ending) for ending in row["endings"]] query = preprocess(row["activity_label"] + ": " + row["ctx_a"] + " " + row["ctx_b"].capitalize()) require(len(choices) == 4 and all(choices), f"Invalid choices: {index}") require(doc["choices"] == choices and doc["query"] == query and doc["gold"] == gold and int(sample["target"]) == gold, f"Preprocessing or label mismatch: {index}") require(sample["arguments"] == [[query, " " + choice] for choice in choices], f"Prompt or continuation mismatch: {index}") responses = sample["filtered_resps"] require(len(responses) == 4 and all(len(response) == 2 for response in responses), f"Missing choice scores: {index}") require(sample["resps"] == [[response] for response in responses], f"Scores modified by filtering: {index}") scores = [response[0] for response in responses] require(all(math.isfinite(score) for score in scores), f"Nonfinite score: {index}") raw_pred = max(range(4), key=lambda choice: scores[choice]) normalized_pred = max(range(4), key=lambda choice: scores[choice] / len(choices[choice])) for metric, prediction in (("acc", raw_pred), ("acc_norm", normalized_pred)): value = int(prediction == gold) require(sample[metric] == value, f"Per-question {metric} mismatch: {index}") correct[metric] += value labels[str(gold)] += 1 require(seen == set(range(10042)), "Missing validation questions") metrics = native["results"]["hellaswag"] for metric in ("acc", "acc_norm"): require(correct[metric] == summary[metric + "_correct"], f"Wrong {metric} count") require(abs(correct[metric] / len(rows) - metrics[metric + ",none"]) < 1e-12, f"Aggregate {metric} differs from independent recomputation") require(metrics[metric + ",none"] == summary["metrics"][metric + ",none"], f"Summary {metric} differs from harness result") require(dict(labels) == summary["label_counts"], "Label counts mismatch") audits = [json.loads((data / f"rank-{rank}-audit.json").read_text()) for rank in range(2)] for rank, audit in enumerate(audits): require(audit["rank"] == rank and audit["world_size"] == 2 and audit["choice_requests"] == 20084 and audit["truncated_requests"] == 0 and audit["max_pair_tokens"] <= 1024 and audit["device"] == f"cuda:{rank}", f"Incomplete GPU rank audit: {rank}") require(summary["gpu_names"] == ["Tesla T4", "Tesla T4"], "Wrong evaluation hardware") verification = { "status": "VERIFIED", "verified_utc": datetime.now(timezone.utc).isoformat(), "source": source, "model_step": 22889, "model_sha256": MODEL_SHA, "dataset_sha256": DATA_SHA, "validation_rows": len(rows), "unique_scored_rows": len(seen), "source_rows_labels_prompts_and_all_choice_scores_verified": True, "independently_recomputed_correct": dict(correct), "independently_recomputed_accuracy": {key: value / len(rows) for key, value in correct.items()}, "random_choice_baseline": 0.25, "rank_audits": audits, "files": {path.name: {"bytes": path.stat().st_size, "sha256": sha(path)} for path in sorted(data.iterdir()) if path.is_file()}, "limitations": "Recomputes metrics from recorded inference scores, not an independent second model inference. Training-data contamination has not been exhaustively audited.", } (run / "verification.json").write_text(json.dumps(verification, indent=2) + "\n", encoding="utf-8") print(json.dumps({key: verification[key] for key in ( "status", "validation_rows", "unique_scored_rows", "independently_recomputed_correct", "independently_recomputed_accuracy")}, indent=2)) if __name__ == "__main__": main()