#!/usr/bin/env python3 """按冻结题单检查全部尝试;局部状态只报覆盖,不提前用测试成绩调整实现。""" import argparse import collections import json from pathlib import Path import sys ROOT=Path(__file__).resolve().parents[1] sys.path.insert(0,str(ROOT));sys.path.insert(0,str(ROOT/'scripts')) from download_assets import atomic,sha from cgvm.benchmark_data import questions,diagnostic_scores def inspect(variant,benchmark,score=False): expected={q['id']:q for q in questions(benchmark)};latest={};attempts=collections.Counter();errors=[];files={} for path in sorted((ROOT/'results'/variant/benchmark).glob('shard*/predictions.jsonl')): files[str(path.relative_to(ROOT))]=sha(path) for line in path.open(): try:row=json.loads(line) except json.JSONDecodeError:raise ValueError('逐题输出有未完整写入行,请在写入间隙重查:'+str(path)) key=row['id'];attempts[key]+=1 if key not in expected:errors.append(dict(id=key,error='unknown_ID'));continue if key in latest and latest[key]['status']=='answered' and row['status']=='answered': errors.append(dict(id=key,error='duplicate_answered_prediction')) if key not in latest or row['status']=='answered' or latest[key]['status']!='answered':latest[key]=row for key,row in latest.items(): q=expected[key] for field in ('question','options','answer','source_video','task','benchmark','timestamp'): if row[field]!=q[field]:errors.append(dict(id=key,error='annotation_changed',field=field)) if row['status']!='answered':continue e=row['evidence'];frames=e['retrieved_frame_ids'];times=[f['timestamp'] for f in frames] if not 0q['timestamp']+1e-6 or e['max_support_time']!=max(times): errors.append(dict(id=key,error='frame_cap_or_future_support')) if times!=sorted(times) or any(f['source_video']!=q['source_video'] for f in frames):errors.append(dict(id=key,error='source_or_order')) if e['history_frames']>8 or e['current_frames']>8 or e['history_frames']+e['current_frames']!=len(frames): errors.append(dict(id=key,error='independent_8_plus_8')) if e['reader_tokens']>32768:errors.append(dict(id=key,error='reader_token_cap')) required={'gpu_seconds','storage_bytes','commit','model_revision'} if not required<=set(row['metrics']):errors.append(dict(id=key,error='cost_fields_missing')) if 'ingested_frames' not in e or 'writer_tokens' not in e or 'writer_calls' not in e:errors.append(dict(id=key,error='source_prefix_cost_missing')) if variant=='R0' and (e['writer_calls']!=0 or e['writer_tokens']!=0):errors.append(dict(id=key,error='baseline_writer_cost_nonzero')) if score: actual=diagnostic_scores(q,row['prediction']) if any(row[name]!=value for name,value in actual.items()):errors.append(dict(id=key,error='stored_scorer_disagrees_with_same_raw')) missing=sorted(set(expected)-set(latest));failed={key:row['failure_reason'] for key,row in latest.items() if row['status']!='answered'} answered=sum(row['status']=='answered' for row in latest.values()) result=dict(variant=variant,benchmark=benchmark,expected=len(expected),recorded=len(latest),answered=answered, total_attempts=sum(attempts.values()),repeated_attempt_ids={k:v for k,v in attempts.items() if v>1}, missing_ids=missing,failed=failed,errors=errors, full_coverage_passed=not(missing or failed or errors), same_raw_official_and_diagnostic_scores_rechecked=score,source_files_sha256=files) return result,latest def main(): parser=argparse.ArgumentParser();parser.add_argument('--variant',choices=['R0','R1','R2','all'],default='all') parser.add_argument('--allow-partial',action='store_true');args=parser.parse_args();reports=[] for variant in ('R0','R1','R2') if args.variant=='all' else (args.variant,): for benchmark in ('ovobench','streamingbench'): report,_=inspect(variant,benchmark,score=not args.allow_partial);reports.append(report) target=ROOT/'results/audits'/('coverage_partial.json' if args.allow_partial else 'formal_results.json') atomic(target,dict(passed=all(r['full_coverage_passed'] for r in reports),partial_monitor=args.allow_partial, manifest_sha256=sha(ROOT/'manifests/eval_questions.jsonl'),reports=reports)) print(json.dumps([dict(variant=r['variant'],benchmark=r['benchmark'],answered=r['answered'],expected=r['expected'], failed=len(r['failed']),audit_errors=len(r['errors'])) for r in reports],ensure_ascii=False)) if not args.allow_partial and not all(r['full_coverage_passed'] for r in reports):raise SystemExit(1) if __name__=='__main__':main()