xuan-luo's picture
download
raw
2.16 kB
#!/usr/bin/env python3
"""Verify private bucket, complete path/size inventory, manifest and sample hashes."""
import hashlib,json,tempfile
from datetime import datetime,timezone
from pathlib import Path
from huggingface_hub import HfApi
root=Path(__file__).resolve().parents[1]
api=HfApi(); bucket='xuan-luo/kvpath-optimization'; prefix='KDA-optimization/'
info=api.bucket_info(bucket); assert info.private is True
manifest_bytes=(root/'MANIFEST.json').read_bytes()
manifest=json.loads(manifest_bytes)
expected={prefix+x['path']:x['size'] for x in manifest['files']}
expected[prefix+'MANIFEST.json']=len(manifest_bytes)
remote={x.path:x for x in api.list_bucket_tree(bucket,prefix=prefix.rstrip('/'),recursive=True) if x.type=='file'}
missing=set(expected)-set(remote)
wrong=[p for p,size in expected.items() if p in remote and remote[p].size!=size]
assert not missing and not wrong, {'missing':sorted(missing),'wrong_size':wrong}
samples=['MANIFEST.json','README.md','run.py','inference/kda_rolling16_local128/relative_mma.py','inference/kda_rolling16_local128/benchmark.py','.agents/skills/kvpath-kda/SKILL.md','env/source-environment.json']
lookup={x['path']:x['sha256'] for x in manifest['files']}
lookup['MANIFEST.json']=hashlib.sha256(manifest_bytes).hexdigest()
with tempfile.TemporaryDirectory(prefix='kvpath-hf-verify-') as tmp:
api.download_bucket_files(bucket,[(prefix+p,Path(tmp)/str(i)) for i,p in enumerate(samples)],raise_on_missing_files=True)
for i,p in enumerate(samples):
actual=hashlib.sha256((Path(tmp)/str(i)).read_bytes()).hexdigest()
assert actual==lookup[p],p
receipt={'verified_utc':datetime.now(timezone.utc).isoformat(),'bucket':bucket,'private':api.bucket_info(bucket).private,'prefix':prefix,'expected_files':len(expected),'verified_path_sizes':len(expected),'total_bytes':sum(expected.values()),'extra_remote_files':sorted(set(remote)-set(expected)),'downloaded_sha256_samples':samples,'manifest_sha256':lookup['MANIFEST.json']}
assert receipt['private'] is True
out=root.parent/'KDA-optimization-upload-receipt.json'
out.write_text(json.dumps(receipt,indent=2)+'\n')
print(json.dumps(receipt,indent=2))
print('Receipt:',out)

Xet Storage Details

Size:
2.16 kB
·
Xet hash:
49208f37b00db84d8e29e506a4c6bcd7ee36a4b124353e85e5eb6167c920120b

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.