File size: 2,526 Bytes
bb34dc3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""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)