File size: 2,433 Bytes
a64600b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | """Package the method-v2 overlay; reuse the original image and model weights."""
import hashlib
import json
import zipfile
from pathlib import Path
def main():
root = Path(__file__).resolve().parents[1]
destination = root / 'artifacts/snf-method-v2-addon.zip'
paths = list((root / 'suite').rglob('*'))
paths += list((root / 'packaging').glob('*'))
paths += [root / 'AGENT_RUNBOOK_METHOD_V2.md',
root / 'docs/METHOD_V2_补方法与实验说明.md',
root / 'experiments/replay_calibration_v2.py',
root / 'artifacts/method_v2_local/validation.json']
for folder in ('null', 'retrospective'):
paths += list((root / 'artifacts/method_v2_local' / folder).rglob('*'))
paths = sorted({p for p in paths if p.is_file()
and '__pycache__' not in p.parts and p.suffix != '.pyc'})
manifest = {}
destination.parent.mkdir(parents=True, exist_ok=True)
with zipfile.ZipFile(destination, 'w', zipfile.ZIP_DEFLATED, compresslevel=6) as archive:
for path in paths:
name = 'snf-method-v2/' + path.relative_to(root).as_posix()
payload = path.read_bytes()
manifest[name] = hashlib.sha256(payload).hexdigest()
archive.writestr(name, payload)
archive.writestr('snf-method-v2/MANIFEST.json', json.dumps({
'type': 'overlay_for_existing_snf_cuda128_image',
'includes_weights': False,
'includes_vendor_or_runtime': False,
'new_gpu_method_validation': 'pending',
'files_sha256': manifest,
}, ensure_ascii=False, indent=2))
with zipfile.ZipFile(destination) as archive:
bad = archive.testzip()
if bad:
raise RuntimeError(f'Archive integrity failure: {bad}')
for name, digest in manifest.items():
if hashlib.sha256(archive.read(name)).hexdigest() != digest:
raise RuntimeError(f'Content hash mismatch: {name}')
digest = hashlib.sha256(destination.read_bytes()).hexdigest()
destination.with_suffix('.zip.sha256').write_text(
digest + ' ' + destination.name + '\n', encoding='utf8')
print(json.dumps({'archive': str(destination), 'files': len(manifest),
'size_mib': destination.stat().st_size / 2**20,
'sha256': digest}, ensure_ascii=False, indent=2))
if __name__ == '__main__':
main()
|