File size: 3,969 Bytes
b70c436 8fe6752 b70c436 8fe6752 b70c436 8fe6752 b70c436 8fe6752 b70c436 | 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | """Upload one audited strict640x480-v2 task atomically to the public Hub repo."""
from __future__ import annotations
import argparse
import json
import os
from io import BytesIO
from pathlib import Path
from huggingface_hub import CommitOperationAdd, HfApi
from huggingface_hub._commit_api import _fetch_upload_modes
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--task", required=True)
parser.add_argument("--source", required=True)
args = parser.parse_args()
source = Path(args.source)
audit = source / "strict_audit.json"
report = json.loads(audit.read_text(encoding="utf-8"))
if report.get("status") != "PASS_STRICT640X480_V2" or report.get("episodes") != 100:
raise ValueError(f"refusing upload of non-formal task audit: {report}")
token = os.environ.get("HF_TOKEN")
if not token:
raise RuntimeError("HF_TOKEN is required for formal-data upload")
# Upload each immutable LFS shard independently, then atomically publish a
# completion marker containing the strict audit. This avoids an upstream
# huggingface_hub batch-preupload failure observed only for several 4+ GB
# HDF5 additions in one request. Consumers must require the final marker,
# so a partial transfer can never be mistaken for a formal dataset.
files = sorted(
p for p in source.rglob("*")
if p.is_file() and ".cache" not in p.parts and p.name != "hf_upload_receipt.json"
)
prefix = f"strict640x480-v2/data/{args.task}"
api = HfApi(token=token)
headers = api._build_hf_headers(token=token)
repo_id = "B111ue/RoboFactory-5Task-RGBD-Decentralized"
remote_files = set(api.list_repo_files(repo_id=repo_id, repo_type="dataset", token=token))
for file in files:
remote_path = f"{prefix}/{file.relative_to(source).as_posix()}"
if remote_path in remote_files:
print(f"HF_FILE_ALREADY_PRESENT {remote_path}")
continue
operation = CommitOperationAdd(path_in_repo=remote_path, path_or_fileobj=str(file))
# Explicitly set the upload mode with the verified authenticated
# headers. hub 1.25's normal multi-GB commit path can repeat this
# preflight without the token; once an LFS operation is preuploaded,
# create_commit correctly skips that duplicate request.
_fetch_upload_modes(
additions=[operation],
repo_type="dataset",
repo_id=repo_id,
headers=headers,
revision="main",
endpoint=api.endpoint,
)
if operation._upload_mode == "lfs":
api.preupload_lfs_files(
repo_id=repo_id,
additions=[operation],
token=token,
repo_type="dataset",
revision="main",
num_threads=1,
free_memory=False,
)
api.create_commit(
repo_id=repo_id,
repo_type="dataset",
operations=[operation],
commit_message=f"strict640x480-v2: stage {args.task}/{file.name}",
token=token,
num_threads=1,
)
print(f"HF_FILE_COMMITTED {remote_path}")
receipt = {"task": args.task, "audit": report, "status": "COMPLETE_STRICT640X480_V2"}
result = api.create_commit(
repo_id=repo_id,
repo_type="dataset",
operations=[CommitOperationAdd(
path_in_repo=f"{prefix}/hf_upload_receipt.json",
path_or_fileobj=BytesIO(json.dumps(receipt, indent=2).encode("utf-8")),
)],
commit_message=f"strict640x480-v2: publish audited {args.task} (100 demos)",
token=token,
num_threads=1,
)
(source / "hf_upload_receipt.json").write_text(json.dumps({**receipt, "revision": str(result)}, indent=2), encoding="utf-8")
print(f"HF_UPLOAD_VERIFIED {args.task} {result}")
if __name__ == "__main__":
main()
|