Add old 256 transfer and inventory scripts
Browse files
code/transfer/collect_all_old256_inventory.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Remote read-only inventory for the old 256-pair release.
|
| 2 |
+
|
| 3 |
+
Run via `ssh 6000D ... python -B - < this_script > evidence/file.json`.
|
| 4 |
+
It does not edit the training machine, and does not claim an index is usable data.
|
| 5 |
+
"""
|
| 6 |
+
import json
|
| 7 |
+
import pathlib
|
| 8 |
+
import re
|
| 9 |
+
import sys
|
| 10 |
+
|
| 11 |
+
base = pathlib.Path('/root/autodl-tmp/LampEditTraining/data_v2')
|
| 12 |
+
bbox = base/'bbox_conditions_v003_20261021'
|
| 13 |
+
index = json.loads((bbox/'INDEX.json').read_text())
|
| 14 |
+
sources = [base/'train_manifest.mixed256.json', base/'train_manifest.new118.json']
|
| 15 |
+
groups = index['groups']
|
| 16 |
+
sources.extend(pathlib.Path(g['manifest']) for g in groups)
|
| 17 |
+
pat_data = re.compile(rb'data_v2/assets/([0-9a-f]{32})')
|
| 18 |
+
pat_bbox = re.compile(rb'bbox_v3/assets/([0-9a-f]{32})')
|
| 19 |
+
data_ids, bbox_ids = set(), set()
|
| 20 |
+
missing = []
|
| 21 |
+
for p in sources:
|
| 22 |
+
if not p.is_file():
|
| 23 |
+
missing.append(str(p))
|
| 24 |
+
continue
|
| 25 |
+
with p.open('rb') as f:
|
| 26 |
+
for line in f:
|
| 27 |
+
data_ids.update(x.decode('ascii') for x in pat_data.findall(line))
|
| 28 |
+
bbox_ids.update(x.decode('ascii') for x in pat_bbox.findall(line))
|
| 29 |
+
|
| 30 |
+
# Each factored render can itself point to base data assets and bbox assets.
|
| 31 |
+
recipes = 0
|
| 32 |
+
for asset in sorted(bbox_ids):
|
| 33 |
+
path = bbox/'assets'/asset
|
| 34 |
+
if not path.is_dir():
|
| 35 |
+
missing.append(str(path))
|
| 36 |
+
continue
|
| 37 |
+
for recipe in path.rglob('RENDER.json'):
|
| 38 |
+
b = recipe.read_bytes()
|
| 39 |
+
data_ids.update(x.decode('ascii') for x in pat_data.findall(b))
|
| 40 |
+
bbox_ids.update(x.decode('ascii') for x in pat_bbox.findall(b))
|
| 41 |
+
recipes += 1
|
| 42 |
+
|
| 43 |
+
output = {
|
| 44 |
+
'scope': 'old 256 manifest and indexed bbox resources; additional dependencies may exist',
|
| 45 |
+
'index_groups': len(groups), 'pair_count_in_bbox_index': index.get('pairs'),
|
| 46 |
+
'mixed_and_new118_manifests': [str(p) for p in sources[:2]],
|
| 47 |
+
'data_asset_ids': sorted(data_ids), 'bbox_asset_ids': sorted(bbox_ids),
|
| 48 |
+
'bbox_group_paths': sorted(str(pathlib.Path(g['manifest']).parent.relative_to(base)) for g in groups),
|
| 49 |
+
'factored_render_recipes_scanned': recipes, 'missing_source_paths': missing,
|
| 50 |
+
'no_512_data_included_by_design': True, 'remote_mutations': False,
|
| 51 |
+
}
|
| 52 |
+
json.dump(output, sys.stdout, ensure_ascii=False)
|
| 53 |
+
sys.stdout.write('\n')
|
code/transfer/upload_old256_bounded_queue.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Bounded, resumable upload of the inventoried old-256 data.
|
| 2 |
+
|
| 3 |
+
Only reads the source training machine; each object is archived locally and
|
| 4 |
+
deleted locally only after an HF commit with matching size and SHA-256. Never
|
| 5 |
+
marks the dataset fully ready: indirect dependencies and complete groups still
|
| 6 |
+
need independent validation. Stops at first error or the 24-hour boundary.
|
| 7 |
+
"""
|
| 8 |
+
import hashlib
|
| 9 |
+
import json
|
| 10 |
+
import os
|
| 11 |
+
import pathlib
|
| 12 |
+
import re
|
| 13 |
+
import shlex
|
| 14 |
+
import subprocess
|
| 15 |
+
import time
|
| 16 |
+
|
| 17 |
+
ROOT = pathlib.Path(__file__).resolve().parent
|
| 18 |
+
INV = json.loads((ROOT/'evidence/all_old256_inventory.json').read_text())
|
| 19 |
+
STAGE = ROOT/'data_staging'; STAGE.mkdir(exist_ok=True)
|
| 20 |
+
EVENTS = STAGE/'upload_queue_events.jsonl'
|
| 21 |
+
STATUS = STAGE/'upload_queue_status.json'
|
| 22 |
+
REPO = 'FrontRear/VideoObjectMover'
|
| 23 |
+
REMOTE_ROOT = '/root/autodl-tmp/LampEditTraining/data_v2'
|
| 24 |
+
PREFIX = 'releases/old256-v001/shards/'
|
| 25 |
+
DEADLINE = time.time()+24*3600
|
| 26 |
+
os.environ['HF_HUB_DISABLE_PROGRESS_BARS'] = '1'
|
| 27 |
+
os.environ['HF_XET_CACHE'] = str(STAGE/'xet_cache')
|
| 28 |
+
os.environ['HF_XET_CHUNK_CACHE_SIZE_BYTES'] = '0'
|
| 29 |
+
|
| 30 |
+
def state(stage, **values):
|
| 31 |
+
p = STATUS.with_suffix('.tmp')
|
| 32 |
+
p.write_text(json.dumps({'time':time.time(),'stage':stage,**values},ensure_ascii=False,indent=2)+'\n')
|
| 33 |
+
os.replace(p,STATUS)
|
| 34 |
+
|
| 35 |
+
def chunks(items, size):
|
| 36 |
+
for n in range(0,len(items),size):
|
| 37 |
+
yield n//size, items[n:n+size]
|
| 38 |
+
|
| 39 |
+
def valid(path):
|
| 40 |
+
p = pathlib.PurePosixPath(path)
|
| 41 |
+
return not p.is_absolute() and all(x not in ('','..') for x in p.parts)
|
| 42 |
+
|
| 43 |
+
def sha(path):
|
| 44 |
+
h = hashlib.sha256()
|
| 45 |
+
with path.open('rb') as f:
|
| 46 |
+
for block in iter(lambda:f.read(8*1024*1024),b''): h.update(block)
|
| 47 |
+
return h.hexdigest()
|
| 48 |
+
|
| 49 |
+
def tasks():
|
| 50 |
+
meta = ['train_manifest.mixed256.json','train_manifest.new118.json','READINESS.json',
|
| 51 |
+
'bbox_conditions_v003_20261021/INDEX.json',
|
| 52 |
+
'bbox_conditions_v003_20261021/CURRENT_LOADER.json',
|
| 53 |
+
'bbox_conditions_v003_20261021/code']
|
| 54 |
+
yield 'metadata-00000',meta
|
| 55 |
+
for n, xs in chunks(INV['bbox_group_paths'],20):
|
| 56 |
+
yield 'bbox-groups-%05d'%n, xs
|
| 57 |
+
for n, xs in chunks(INV['bbox_asset_ids'],4):
|
| 58 |
+
assert all(re.fullmatch(r'[0-9a-f]{32}',x) for x in xs)
|
| 59 |
+
yield 'bbox-assets-%05d'%n, ['bbox_conditions_v003_20261021/assets/'+x for x in xs]
|
| 60 |
+
# The preceding separate first-shard job owns data-assets-00000.
|
| 61 |
+
for n, xs in chunks(INV['data_asset_ids'],100):
|
| 62 |
+
if n==0: continue
|
| 63 |
+
assert all(re.fullmatch(r'[0-9a-f]{32}',x) for x in xs)
|
| 64 |
+
yield 'data-assets-%05d'%n, ['assets/'+x for x in xs]
|
| 65 |
+
|
| 66 |
+
def run():
|
| 67 |
+
state('waiting_for_first_shard')
|
| 68 |
+
first = STAGE/'data-assets-00000.receipt.json'
|
| 69 |
+
limit = min(DEADLINE,time.time()+3600)
|
| 70 |
+
while not first.exists() and time.time()<limit:
|
| 71 |
+
time.sleep(30)
|
| 72 |
+
if not first.exists():
|
| 73 |
+
raise RuntimeError('First shard did not finish within one hour; no following shards admitted')
|
| 74 |
+
from huggingface_hub import HfApi
|
| 75 |
+
api = HfApi()
|
| 76 |
+
done = set()
|
| 77 |
+
if EVENTS.exists():
|
| 78 |
+
with EVENTS.open() as f:
|
| 79 |
+
done = {json.loads(line)['shard'] for line in f if line.strip()}
|
| 80 |
+
queue = list(tasks())
|
| 81 |
+
completed = len(done)
|
| 82 |
+
for shard, paths in queue:
|
| 83 |
+
if shard in done: continue
|
| 84 |
+
if time.time()>=DEADLINE:
|
| 85 |
+
state('time_limit',completed=completed,total=len(queue)); return
|
| 86 |
+
assert paths and all(valid(p) for p in paths)
|
| 87 |
+
part = STAGE/(shard+'.tar.partial'); archive = STAGE/(shard+'.tar')
|
| 88 |
+
if part.exists() or archive.exists():
|
| 89 |
+
raise RuntimeError('Existing local partial/archive requires inspection: '+shard)
|
| 90 |
+
cmd = ('nice -n 19 ionice -c 3 tar --dereference -C '+shlex.quote(REMOTE_ROOT)
|
| 91 |
+
+' -cf - -- '+' '.join(shlex.quote(p) for p in paths))
|
| 92 |
+
state('archiving',shard=shard,completed=completed,total=len(queue))
|
| 93 |
+
with part.open('xb') as f:
|
| 94 |
+
p=subprocess.run(['ssh','-o','BatchMode=yes','6000D',cmd],stdout=f,
|
| 95 |
+
stderr=subprocess.PIPE,timeout=3600)
|
| 96 |
+
if p.returncode:
|
| 97 |
+
raise RuntimeError('Archive failed; retained partial: '+p.stderr.decode(errors='replace')[-2000:])
|
| 98 |
+
part.rename(archive); size=archive.stat().st_size; checksum=sha(archive)
|
| 99 |
+
name=PREFIX+shard+'.tar'
|
| 100 |
+
state('uploading',shard=shard,bytes=size,completed=completed,total=len(queue))
|
| 101 |
+
commit=api.upload_file(repo_id=REPO,repo_type='dataset',path_or_fileobj=str(archive),
|
| 102 |
+
path_in_repo=name,commit_message='Upload old 256 data shard '+shard)
|
| 103 |
+
info=api.get_paths_info(repo_id=REPO,repo_type='dataset',paths=[name])
|
| 104 |
+
if len(info)!=1 or info[0].size!=size or not info[0].lfs or info[0].lfs.sha256!=checksum:
|
| 105 |
+
raise RuntimeError('HF object validation failed; retained local archive: '+shard)
|
| 106 |
+
record={'shard':shard,'path':name,'bytes':size,'sha256':checksum,'commit':commit.commit_url,
|
| 107 |
+
'source_path_count':len(paths),'time':time.time()}
|
| 108 |
+
with EVENTS.open('a',buffering=1) as f:f.write(json.dumps(record,ensure_ascii=False)+'\n')
|
| 109 |
+
archive.unlink() # Only the copy made by this script, after verified upload.
|
| 110 |
+
completed+=1
|
| 111 |
+
state('uploaded',shard=shard,completed=completed,total=len(queue))
|
| 112 |
+
state('all_inventoried_shards_uploaded_pending_full_data_validation',completed=completed,total=len(queue))
|
| 113 |
+
|
| 114 |
+
if __name__=='__main__':
|
| 115 |
+
try:run()
|
| 116 |
+
except Exception as error:
|
| 117 |
+
state('failed',error=repr(error))
|
| 118 |
+
raise
|
code/transfer/upload_old256_first_shard.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Upload a bounded first shard of the old 256-pair assets.
|
| 2 |
+
|
| 3 |
+
Only reads the 6000D source, never modifies it or the current training run.
|
| 4 |
+
The complete dataset must not be marked delivered until the remaining shards,
|
| 5 |
+
bbox assets, manifests and indirect dependencies are also delivered and tested.
|
| 6 |
+
"""
|
| 7 |
+
import hashlib
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
import pathlib
|
| 11 |
+
import re
|
| 12 |
+
import shlex
|
| 13 |
+
import subprocess
|
| 14 |
+
import time
|
| 15 |
+
|
| 16 |
+
root = pathlib.Path(__file__).resolve().parent
|
| 17 |
+
inv = json.loads((root/'evidence/all_old256_inventory.json').read_text())
|
| 18 |
+
ids = inv['data_asset_ids'][:100]
|
| 19 |
+
assert len(ids) == 100 and all(re.fullmatch(r'[0-9a-f]{32}', x) for x in ids)
|
| 20 |
+
stage = root/'data_staging'; stage.mkdir(exist_ok=True)
|
| 21 |
+
partial = stage/'data-assets-00000.tar.partial'
|
| 22 |
+
ready = stage/'data-assets-00000.tar'
|
| 23 |
+
if partial.exists() or ready.exists():
|
| 24 |
+
raise SystemExit('A previous shard already exists; inspect it before retrying')
|
| 25 |
+
paths = ['assets/'+x for x in ids]
|
| 26 |
+
remote = ('nice -n 19 ionice -c 3 tar --dereference -C '
|
| 27 |
+
'/root/autodl-tmp/LampEditTraining/data_v2 -cf - -- '
|
| 28 |
+
+ ' '.join(shlex.quote(p) for p in paths))
|
| 29 |
+
start=time.time()
|
| 30 |
+
with partial.open('xb') as dst:
|
| 31 |
+
result = subprocess.run(['ssh','-o','BatchMode=yes','6000D',remote],
|
| 32 |
+
stdout=dst, stderr=subprocess.PIPE, timeout=3600)
|
| 33 |
+
if result.returncode:
|
| 34 |
+
raise RuntimeError('Source archive failed; partial file kept: '+result.stderr.decode(errors='replace')[-2000:])
|
| 35 |
+
partial.rename(ready)
|
| 36 |
+
size = ready.stat().st_size
|
| 37 |
+
h = hashlib.sha256()
|
| 38 |
+
with ready.open('rb') as f:
|
| 39 |
+
for chunk in iter(lambda:f.read(8*1024*1024),b''): h.update(chunk)
|
| 40 |
+
os.environ['HF_HUB_DISABLE_PROGRESS_BARS']='1'
|
| 41 |
+
from huggingface_hub import HfApi
|
| 42 |
+
repo='FrontRear/VideoObjectMover'; name='releases/old256-v001/shards/data-assets-00000.tar'
|
| 43 |
+
r=HfApi().upload_file(repo_id=repo,repo_type='dataset',path_or_fileobj=str(ready),path_in_repo=name,
|
| 44 |
+
commit_message='Upload first bounded old 256 asset shard')
|
| 45 |
+
info=HfApi().get_paths_info(repo_id=repo,repo_type='dataset',paths=[name])
|
| 46 |
+
if len(info)!=1 or info[0].size!=size:
|
| 47 |
+
raise RuntimeError('Remote shard size verification failed; local archive retained')
|
| 48 |
+
receipt={'asset_folder_count':len(ids),'file':name,'bytes':size,'sha256':h.hexdigest(),
|
| 49 |
+
'commit_url':r.commit_url,'elapsed_seconds':time.time()-start,
|
| 50 |
+
'dataset_complete':False,'local_archive':str(ready)}
|
| 51 |
+
(stage/'data-assets-00000.receipt.json').write_text(json.dumps(receipt,indent=2)+'\n')
|
| 52 |
+
print(json.dumps(receipt),flush=True)
|