hamishivi's picture
Update verified Apptainer pool manifest and download instructions
99c649a verified
Raw History Blame Contribute Delete
1.74 kB
"""Download a dataset's published SIF pool using tmax-compatible filenames."""
import argparse,hashlib,json,os
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from huggingface_hub import hf_hub_download
def main():
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--repo',required=True);p.add_argument('--output',type=Path,required=True);p.add_argument('--allow-partial',action='store_true');p.add_argument('--workers',type=int,default=4);args=p.parse_args()
manifest=Path(hf_hub_download(args.repo,'apptainer/manifest.jsonl',repo_type='dataset'))
rows=[json.loads(line) for line in manifest.read_text().splitlines()]
missing=[r for r in rows if r['status']!='published']
if missing and not args.allow_partial:raise SystemExit(f'{len(missing)} images are not yet published. Use --allow-partial to download the available subset.')
args.output.mkdir(parents=True,exist_ok=True)
def sha(p):
with p.open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest()
def download(row):
target=args.output/row['sif_name']
if target.is_file() and sha(target)==row['sif_sha256']:return
staged=Path(hf_hub_download(args.repo,row['hf_path'],repo_type='dataset',revision=row['commit'],local_dir=args.output/'.downloads'))
if sha(staged)!=row['sif_sha256']:raise RuntimeError('Checksum mismatch: '+row['hf_path'])
os.replace(staged,target)
print(target.name,flush=True)
with ThreadPoolExecutor(args.workers) as pool:list(pool.map(download,[r for r in rows if r['status']=='published']))
print(f'Pool: {args.output.resolve()} ({len(rows)-len(missing)} images available; {len(missing)} pending)')
print('Set SWERL_APPTAINER_SIF_DIR to this directory.')
if __name__=='__main__':main()