Buckets:
| """Verify a bucket copy before moving experiment artifacts out of the dataset HEAD.""" | |
| from __future__ import annotations | |
| import hashlib | |
| import json | |
| import re | |
| import shutil | |
| from concurrent.futures import ThreadPoolExecutor | |
| from pathlib import Path | |
| from urllib.parse import quote | |
| from huggingface_hub import CommitOperationAdd, CommitOperationDelete, HfApi, hf_hub_download | |
| ROOT = Path(__file__).resolve().parent | |
| REPO = "tomaarsen/encoder-comparison-20261014" | |
| BUCKET_URL = f"https://huggingface.co/buckets/{REPO}" | |
| DATA_REVISION = "0d882e8af96100b875a30b78de98ea8efe99e4db" | |
| KEEP = {".gitattributes", "README.md", "manifest.json", "train.json.gz", "validation.json.gz", "tests.json.gz"} | |
| def digest(path): | |
| return hashlib.sha256(path.read_bytes()).hexdigest() | |
| def main(): | |
| api = HfApi() | |
| source = json.loads((ROOT / "migration_source.json").read_text()) | |
| revision = source["revision"] | |
| staging = ROOT / "bucket_artifacts" | |
| staging.mkdir(exist_ok=True) | |
| names = [f["path"] for f in source["files"] if f["path"] not in KEEP] | |
| def download(name): | |
| cached = hf_hub_download(REPO, name, repo_type="dataset", revision=revision) | |
| destination = staging / name | |
| destination.parent.mkdir(parents=True, exist_ok=True) | |
| shutil.copyfile(cached, destination) | |
| with ThreadPoolExecutor(max_workers=8) as pool: | |
| list(pool.map(download, names)) | |
| for path in (ROOT / "plots").glob("*"): | |
| if path.is_file(): | |
| target = staging / "plots" / path.name | |
| target.parent.mkdir(exist_ok=True) | |
| shutil.copyfile(path, target) | |
| for name in ("plot_results.py", "plot_lines.py", "plot_sizes.py", "migrate_artifacts.py"): | |
| shutil.copyfile(ROOT / name, staging / "scripts" / name) | |
| original_card = Path(hf_hub_download(REPO, "README.md", repo_type="dataset", revision=revision)).read_text() | |
| def rewrite_link(match): | |
| label, target = match.groups() | |
| if "://" in target or target.startswith("#"): | |
| return match.group(0) | |
| return f"[{label}]({BUCKET_URL}/resolve/{quote(target, safe='')})" | |
| card = re.sub(r"\[([^\]]+)\]\(([^)]+)\)", rewrite_link, original_card) | |
| card += ( | |
| "\n## Artifact storage\n\n" | |
| "This public bucket contains the completed experiment results, job records, logs, source scripts and plots.\n\n" | |
| f"\n\n" | |
| f"[Frozen training and evaluation data](https://huggingface.co/datasets/{REPO}/tree/{DATA_REVISION}) " | |
| f"remain in the versioned dataset repository. [Data manifest](https://huggingface.co/datasets/{REPO}/resolve/{DATA_REVISION}/manifest.json). " | |
| "Finished models remain in their linked model repositories.\n\n" | |
| "The bucket is mutable. migration_manifest.json records SHA-256 hashes and the archived source revision. " | |
| "Training and reporting scripts preserve the original run configuration and original storage paths. " | |
| "The plotting scripts read frozen results and can reproduce the figures.\n" | |
| ) | |
| (staging / "README.md").write_text(card, encoding="utf-8") | |
| (staging / "report" / "README.md").write_text(card, encoding="utf-8") | |
| payloads = sorted(p for p in staging.rglob("*") if p.is_file() and p.name != "migration_manifest.json") | |
| records = [ | |
| {"path": p.relative_to(staging).as_posix(), "bytes": p.stat().st_size, "sha256": digest(p)} for p in payloads | |
| ] | |
| manifest = { | |
| "source_repository": REPO, | |
| "source_revision": revision, | |
| "frozen_data_revision": DATA_REVISION, | |
| "bucket": REPO, | |
| "files": records, | |
| } | |
| manifest_path = staging / "migration_manifest.json" | |
| manifest_path.write_text(json.dumps(manifest, indent=2), encoding="utf-8") | |
| payloads.append(manifest_path) | |
| assert api.bucket_info(REPO).private is False | |
| api.batch_bucket_files(REPO, add=[(p, p.relative_to(staging).as_posix()) for p in payloads]) | |
| print(f"Uploaded {len(payloads)} artifact files", flush=True) | |
| remote = {f.path: f for f in api.list_bucket_tree(REPO, recursive=True) if hasattr(f, "size")} | |
| verification = ROOT / "bucket_verification" | |
| pairs = [] | |
| for path in payloads: | |
| name = path.relative_to(staging).as_posix() | |
| assert remote[name].size == path.stat().st_size, name | |
| target = verification / name | |
| target.parent.mkdir(parents=True, exist_ok=True) | |
| pairs.append((remote[name], target)) | |
| api.download_bucket_files(REPO, pairs, raise_on_missing_files=True, token=False) | |
| for path in payloads: | |
| name = path.relative_to(staging) | |
| assert digest(path) == digest(verification / name), name | |
| print(f"Verified public download and SHA-256 for all {len(payloads)} files", flush=True) | |
| dataset_card = ( | |
| "---\npretty_name: Encoder comparison frozen retrieval data\n---\n\n" | |
| "# Encoder comparison: frozen retrieval data\n\n" | |
| f"**[Results, plots, logs and experiment artifacts have moved to the public bucket]({BUCKET_URL}).**\n\n" | |
| "This repository retains the fixed inputs used to compare ModernBERT, Ettin and UltraBERT " | |
| "after dense, multi-vector and reranker fine-tuning.\n\n" | |
| "- train.json.gz: 32,768 MS MARCO hard-negative triplets.\n" | |
| "- validation.json.gz: 1,024 disjoint queries with fixed candidates.\n" | |
| "- tests.json.gz: NanoNQ, NanoFiQA2018 and NanoSciFact inputs, qrels and BM25 candidates.\n" | |
| "- manifest.json: source revisions, sampling details and content hashes.\n\n" | |
| f"The experiment uses frozen data revision `{DATA_REVISION}`. Original dataset terms apply.\n\n" | |
| f"[Archived experiment snapshot](https://huggingface.co/datasets/{REPO}/tree/{revision}) " | |
| "preserves the original scripts and artifact history. Finished models remain in their model repositories.\n" | |
| ) | |
| card_path = ROOT / "dataset_README.md" | |
| card_path.write_text(dataset_card, encoding="utf-8") | |
| operations = [CommitOperationDelete(path_in_repo=name) for name in names] | |
| operations.append(CommitOperationAdd(path_in_repo="README.md", path_or_fileobj=str(card_path))) | |
| commit = api.create_commit( | |
| repo_id=REPO, | |
| repo_type="dataset", | |
| parent_commit=revision, | |
| operations=operations, | |
| commit_message="Move verified experiment artifacts to public bucket, retain frozen data", | |
| ) | |
| remaining = set(api.list_repo_files(REPO, repo_type="dataset", revision=commit.oid)) | |
| assert remaining == KEEP, remaining | |
| print(f"Migration complete: {BUCKET_URL}. Dataset commit: {commit.oid}", flush=True) | |
| if __name__ == "__main__": | |
| main() | |
Xet Storage Details
- Size:
- 6.7 kB
- Xet hash:
- e77f8a01a0947da03123395126aaad70db9164c11f87395b13295ac7c69ea7a3
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.