Heiheihaha17's picture
Add files using upload-large-folder tool
347d9a3 verified
Raw History Blame Contribute Delete
4.45 kB
"""Freeze a fully accepted release and a small portable reproduction input ZIP."""
from __future__ import annotations
import argparse,hashlib,platform,shutil,sys,zipfile
from pathlib import Path
import numpy,scipy,soundfile
from .common import read,rows,sha,write,now,VERSION
def freeze(root,repo,bundle):
root=root.resolve();repo=repo.resolve();bundle=bundle.resolve();accepted=read(root/'reports/acceptance.json')
if not accepted['passed'] or accepted['pilot'] or accepted['physical_scenes']!=2000:raise ValueError('A fully accepted 2,000-scene release is required')
if not (root/'private/reproduction_code').exists():
code=root/'private/reproduction_code';code.mkdir(parents=True)
for name in ['dynamic_dataset','dynamic_demo','generation']:
shutil.copytree(repo/name,code/name,ignore=shutil.ignore_patterns('__pycache__','*.pyc'))
for name in ['LICENSE','README.md']:
if (repo/name).exists():shutil.copyfile(repo/name,code/name)
if (repo/'licenses').exists():shutil.copytree(repo/'licenses',code/'licenses')
# Actual runtime module versions, independent of inconsistent package metadata.
write(root/'environment.json',dict(python=sys.version,numpy=numpy.__version__,scipy=scipy.__version__,soundfile=soundfile.__version__,
platform=platform.platform(),native_environment=read(repo/'generation/configs/native_environment.json'),
native_rir_bitwise_identity_promised=False))
references={e['audio_asset'] for g in rows(root/'private/recipes.jsonl') for s in g['scenes'][:1] for h in s['humans']+s['playback_sources'] for e in h['events']}
# Unselected candidate copies are not part of the distribution or lock.
files=[]
for f in sorted(root.rglob('*')):
if not f.is_file():continue
rel=str(f.relative_to(root))
if rel.startswith('private/assets/sources/') and rel not in references:continue
if rel.startswith('reports/acceptance/oracle_'):continue
if rel.startswith('reports/failures/'):continue
if f.name.endswith('.tmp') or rel in ['dataset.lock.json','release.complete.json']:continue
files.append(dict(path=rel,bytes=f.stat().st_size,sha256=sha(f)))
lock=dict(schema_version=VERSION,files=files,physical_scenes=2000,task_requests=accepted['task_requests'],
model_input_roots=['public/test','public/audio'],binaural_previews=False,private_is_not_model_input=True)
write(root/'dataset.lock.json',lock)
bundle.parent.mkdir(parents=True,exist_ok=True)
if bundle.exists():raise ValueError('Reproduction bundle already exists; use a new output path')
include=[r for r in files if r['path']=='config.json' or r['path']=='environment.json' or r['path']=='summary.json' or r['path']=='private/recipes.jsonl'
or r['path'].startswith(('private/assets/sources/','public/assets/','private/reproduction_code/'))]
with zipfile.ZipFile(bundle,'w',compression=zipfile.ZIP_DEFLATED,compresslevel=6) as z:
for r in include:
name=r['path'].replace('private/reproduction_code/','code/',1) if r['path'].startswith('private/reproduction_code/') else r['path']
z.write(root/r['path'],name)
z.writestr('REPRODUCE.txt','Unzip this input bundle. From code/, build dynamic_demo/Dockerfile. Mount the bundle at /bundle and a NEW output folder at /output. Set DISH_ALLOW_LOCAL_RENDER=1. Run python -m dynamic_dataset.reproduce --bundle /bundle --root /output. Read dynamic_dataset/README.zh.md for stages, resource sizing, inference and scoring. No original static dataset or alignment model is needed. Native ray simulation is not promised bitwise identical.\n')
write(root/'release.complete.json',dict(schema_version=VERSION,completed_at=now(),passed=True,physical_scenes=2000,
task_requests=accepted['task_requests'],lock_sha256=sha(root/'dataset.lock.json'),
reproduction_bundle=dict(path=str(bundle),bytes=bundle.stat().st_size,sha256=sha(bundle)),
published_foa_byte_verification=True,native_rir_bitwise_identity_promised=False))
print('FROZEN',len(files),'files; bundle',bundle.stat().st_size,'bytes',flush=True)
if __name__=='__main__':
p=argparse.ArgumentParser();p.add_argument('--root',type=Path,required=True);p.add_argument('--repo',type=Path,required=True);p.add_argument('--bundle',type=Path,required=True)
a=p.parse_args();freeze(a.root,a.repo,a.bundle)