gemma4-interpretability / verify_release.py
mjbuehler's picture
Add files using upload-large-folder tool
0079e69 verified
Raw History Blame Contribute Delete
1.29 kB
#!/usr/bin/env python3
"""Verify original records against the release manifest; no model inference."""
import argparse,hashlib,json
from pathlib import Path
def digest(path):
h=hashlib.sha256()
with path.open('rb') as f:
for b in iter(lambda:f.read(1024*1024),b''):h.update(b)
return h.hexdigest()
def main():
ap=argparse.ArgumentParser();ap.add_argument('--root',type=Path,default=Path(__file__).resolve().parent);args=ap.parse_args()
root=args.root.resolve();manifest=json.loads((root/'MANIFEST.json').read_text());failures=[];total=0
for row in manifest['files']:
p=root/row['path']
if not p.resolve().is_relative_to(root):failures.append({'path':row['path'],'error':'unsafe path'});continue
if not p.is_file():failures.append({'path':row['path'],'error':'missing'});continue
total+=p.stat().st_size
if p.stat().st_size!=row['bytes'] or digest(p)!=row['sha256']:failures.append({'path':row['path'],'error':'size or SHA-256 mismatch'})
report={'release_id':manifest['release_id'],'checked_files':len(manifest['files']),'bytes':total,'status':'passed' if not failures else 'failed','failures':failures}
print(json.dumps(report,indent=2))
raise SystemExit(bool(failures))
if __name__=='__main__':main()