"""Pin upstream inputs and download on Stallion only, with a disk reserve.""" import json import shutil import socket from pathlib import Path from huggingface_hub import HfApi, snapshot_download ROOT = Path('/home/rezo/drama3') SOURCES = { 'fishaudio/drama-3': 'e0a9218aa48888270f06ef1ed9ea67622c0e17d2', 'fishaudio/drama-3-int4': 'a6f588691a13b6607cb09f9800556487ab7aa0fe', 'mlx-community/fish-audio-drama-3-4bit': 'cc639e27aba7edb73429d3e3806f471dcd79d316', } def main(): assert socket.gethostname().lower() in {'redza', 'stallion'} api = HfApi() manifest = [] for repo, revision in SOURCES.items(): info = api.model_info(repo, revision=revision, files_metadata=True) files = [{'path': f.rfilename, 'size': f.size} for f in info.siblings] manifest.append({'repo': repo, 'revision': info.sha, 'files': files, 'card': info.card_data.to_dict() if info.card_data else {}}) (ROOT / 'reports/sources.json').write_text(json.dumps(manifest, indent=2)) source = manifest[0] needed = sum(f['size'] or 0 for f in source['files']) # Source + conservative 27 GB output + runtime/JIT space + 15 GB reserve. minimum = needed + 27_000_000_000 + 5_000_000_000 + 15_000_000_000 free = shutil.disk_usage(ROOT).free print(json.dumps({'source_bytes': needed, 'free_bytes': free, 'minimum_free_bytes': minimum}), flush=True) if free < minimum: raise RuntimeError('Insufficient disk reserve; no automatic deletion') path = snapshot_download(source['repo'], revision=source['revision'], local_dir=ROOT / 'source', max_workers=2) print('Source downloaded:', path, flush=True) if __name__ == '__main__': main()