"""Load a program without extracting its split archive. python load_example.py USER/breakout-ram4-1024 --split train --program 0 Set HF_TOKEN only if accessing a private copy. Public downloads need no token. """ import argparse,hashlib,io,zipfile import numpy as np from huggingface_hub import hf_hub_download def load_program(repo_id,split='train',program=0,revision='main',token=None): allowed=('train','random_matched','random_long','policy_matched','policy_long') if split not in allowed:raise ValueError(f'split must be one of {allowed}') path=hf_hub_download(repo_id,split+'.zip',repo_type='dataset',revision=revision,token=token) checks=hf_hub_download(repo_id,'SHA256SUMS',repo_type='dataset',revision=revision,token=token) expected=dict(line.strip().split(' ',1)[::-1] for line in open(checks)) with open(path,'rb') as f:actual=hashlib.file_digest(f,'sha256').hexdigest() if actual!=expected[split+'.zip']:raise ValueError('Archive checksum mismatch') with zipfile.ZipFile(path) as z: with np.load(io.BytesIO(z.read(f'{split}/program_{program:04d}.npz')),allow_pickle=False) as data: return {key:data[key] for key in data.files} if __name__=='__main__': ap=argparse.ArgumentParser(description=__doc__);ap.add_argument('repo_id');ap.add_argument('--split',default='train');ap.add_argument('--program',type=int,default=0);ap.add_argument('--revision',default='main');a=ap.parse_args() d=load_program(a.repo_id,a.split,a.program,a.revision) print({key:(value.shape,str(value.dtype)) for key,value in d.items()}) # A substring of 32 actions beginning at offset 10 in replay 0. start,length=10,32 actions=d['actions'][start:start+length] observations=d['states'][0,start:start+length+1] assert len(actions)==32 and observations.shape==(33,4,128) print('32-action substring:',actions.shape,'observations:',observations.shape)