Download code/transfer/upload_old256_first_shard.py from FrontRear/VideoObjectMover: direct link, hf CLI and curl.
- Browser
- Download file 2.53 kB
-
https://huggingface.co/datasets/FrontRear/VideoObjectMover/resolve/fcbc884d8411f6b8a85dc12e140c39e052d31cba/code/transfer/upload_old256_first_shard.py
- Command line
-
hf download hf://datasets/FrontRear/VideoObjectMover@fcbc884d8411f6b8a85dc12e140c39e052d31cba/code/transfer/upload_old256_first_shard.py
-
curl -L -o upload_old256_first_shard.py https://huggingface.co/datasets/FrontRear/VideoObjectMover/resolve/fcbc884d8411f6b8a85dc12e140c39e052d31cba/code/transfer/upload_old256_first_shard.py
2.53 kB
| """Upload a bounded first shard of the old 256-pair assets. | |
| Only reads the 6000D source, never modifies it or the current training run. | |
| The complete dataset must not be marked delivered until the remaining shards, | |
| bbox assets, manifests and indirect dependencies are also delivered and tested. | |
| """ | |
| import hashlib | |
| import json | |
| import os | |
| import pathlib | |
| import re | |
| import shlex | |
| import subprocess | |
| import time | |
| root = pathlib.Path(__file__).resolve().parent | |
| inv = json.loads((root/'evidence/all_old256_inventory.json').read_text()) | |
| ids = inv['data_asset_ids'][:100] | |
| assert len(ids) == 100 and all(re.fullmatch(r'[0-9a-f]{32}', x) for x in ids) | |
| stage = root/'data_staging'; stage.mkdir(exist_ok=True) | |
| partial = stage/'data-assets-00000.tar.partial' | |
| ready = stage/'data-assets-00000.tar' | |
| if partial.exists() or ready.exists(): | |
| raise SystemExit('A previous shard already exists; inspect it before retrying') | |
| paths = ['assets/'+x for x in ids] | |
| remote = ('nice -n 19 ionice -c 3 tar --dereference -C ' | |
| '/root/autodl-tmp/LampEditTraining/data_v2 -cf - -- ' | |
| + ' '.join(shlex.quote(p) for p in paths)) | |
| start=time.time() | |
| with partial.open('xb') as dst: | |
| result = subprocess.run(['ssh','-o','BatchMode=yes','6000D',remote], | |
| stdout=dst, stderr=subprocess.PIPE, timeout=3600) | |
| if result.returncode: | |
| raise RuntimeError('Source archive failed; partial file kept: '+result.stderr.decode(errors='replace')[-2000:]) | |
| partial.rename(ready) | |
| size = ready.stat().st_size | |
| h = hashlib.sha256() | |
| with ready.open('rb') as f: | |
| for chunk in iter(lambda:f.read(8*1024*1024),b''): h.update(chunk) | |
| os.environ['HF_HUB_DISABLE_PROGRESS_BARS']='1' | |
| from huggingface_hub import HfApi | |
| repo='FrontRear/VideoObjectMover'; name='releases/old256-v001/shards/data-assets-00000.tar' | |
| r=HfApi().upload_file(repo_id=repo,repo_type='dataset',path_or_fileobj=str(ready),path_in_repo=name, | |
| commit_message='Upload first bounded old 256 asset shard') | |
| info=HfApi().get_paths_info(repo_id=repo,repo_type='dataset',paths=[name]) | |
| if len(info)!=1 or info[0].size!=size: | |
| raise RuntimeError('Remote shard size verification failed; local archive retained') | |
| receipt={'asset_folder_count':len(ids),'file':name,'bytes':size,'sha256':h.hexdigest(), | |
| 'commit_url':r.commit_url,'elapsed_seconds':time.time()-start, | |
| 'dataset_complete':False,'local_archive':str(ready)} | |
| (stage/'data-assets-00000.receipt.json').write_text(json.dumps(receipt,indent=2)+'\n') | |
| print(json.dumps(receipt),flush=True) | |