CGVM-R2.6-Qwen3VL-8B-step600 / src /scripts /audit_eval_cache_against_r0.py
XiangnanW's picture
Upload CGVM R2.6 step-000600 checkpoint, R2.6 source bundle (cgvm-r26-src-v1.tar.gz), and 4-round audit report
4ad9219 verified
Raw History Blame Contribute Delete
3.78 kB
#!/usr/bin/env python3
"""实际原版R0与共享缓存逐视频/逐帧核对;不拿推断写成位级键等价证明。"""
import argparse
import hashlib
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
def main():
import torch
parser=argparse.ArgumentParser();parser.add_argument('--benchmark',choices=['ovobench','streamingbench'],required=True)
parser.add_argument('--allow-partial',action='store_true');args=parser.parse_args()
sources=json.loads((ROOT/'manifests'/('eval_sources.'+args.benchmark+'.json')).read_text())['sources']
byvideo={};audit_files={}
for path in (ROOT/'results/R0'/args.benchmark).glob('shard*/predictions.jsonl'):
for line in path.open():
row=json.loads(line)
if row['status']=='answered':byvideo.setdefault(row['source_video'],{})[row['id']]=row
for path in (ROOT/'results/R0'/args.benchmark).glob('shard*/*.video.json'):
value=json.loads(path.read_text());audit_files[value['source_video']]=value
reports=[];missing=[];errors=[]
for video in sources:
token=hashlib.sha256(video.encode()).hexdigest()[:24];path=ROOT/'data/frozen_eval_cache'/args.benchmark/(token+'.pt')
if not path.exists() or video not in audit_files or video not in byvideo:missing.append(video);continue
cache=torch.load(path,map_location='cpu',weights_only=False);audit=audit_files[video]
frames={f['native_index']:f for f in cache['frames']}
if len(frames)!=audit['processed_frames']:errors.append(dict(source_video=video,error='ingested_frame_count'))
chunks=[c for c in cache['chunks'] if not c['terminal_flush']];original=audit['chunk_closures']
if len(chunks)!=len(original):errors.append(dict(source_video=video,error='closed_chunk_count'))
for new,old in zip(chunks,original):
if any(new[key]!=old[key] for key in ('chunk_id','frame_ids','committed_at')):
errors.append(dict(source_video=video,error='closure_time_or_support_changed',chunk=new['chunk_id']))
checked=0
for row in byvideo[video].values():
evidence=row['evidence'];qt=row['timestamp']
if evidence['ingested_frames']!=sum(f['timestamp']<=qt+1e-6 for f in frames.values()):
errors.append(dict(source_video=video,id=row['id'],error='query_prefix_count'))
for ref in evidence['retrieved_frame_ids']:
frame=frames[int(ref['frame_id'])]
if any(frame[key]!=ref[key] for key in ('timestamp','source_video','rgb_sha256','width','height')):
errors.append(dict(source_video=video,id=row['id'],error='actual_reader_RGB_reference_changed'))
checked+=1
reports.append(dict(source_video=video,queries=len(byvideo[video]),Reader_frame_references_checked=checked,closed_chunks=len(chunks)))
value=dict(passed=not(missing or errors),scope='actual_R0_native_frame_RGB_and_causal_chunk_closures',
benchmark=args.benchmark,videos_checked=len(reports),expected_videos=len(sources),missing=missing,errors=errors,reports=reports,
limitation='R0没有导出全局/实体键tensor,不能声称已逐bit比较它们;共享缓存使用同一锁定聚合/感知源码,闭窗和实际RGB在此逐项核对。')
atomic(ROOT/'provenance'/('eval_cache_vs_R0.'+args.benchmark+('.partial' if args.allow_partial else '')+'.json'),value)
print(json.dumps(dict(passed=value['passed'],videos=len(reports),missing=len(missing),errors=len(errors))))
if not args.allow_partial and not value['passed']:raise SystemExit(1)
if __name__=='__main__':main()