Support held-out metadata val eval samples
Browse files
benchmarks/edit/build_eval_samples.py
CHANGED
|
@@ -1,13 +1,19 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
-
"""Build val_N eval sample jsonl files
|
| 3 |
|
| 4 |
The output schema matches the saved val20/val100 artifacts:
|
| 5 |
{"id", "target_video", "control_video", "prompt"}.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
from __future__ import annotations
|
| 9 |
|
| 10 |
import argparse
|
|
|
|
| 11 |
import json
|
| 12 |
import random
|
| 13 |
import re
|
|
@@ -39,6 +45,28 @@ def read_json(path: Path) -> list[dict[str, Any]]:
|
|
| 39 |
return data
|
| 40 |
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
def sanitize_flat_relpath(relpath: str) -> str:
|
| 43 |
parts = [re.sub(r"[^0-9A-Za-z._-]+", "_", piece) for piece in relpath.split("/")]
|
| 44 |
return "__".join(parts)
|
|
@@ -146,6 +174,12 @@ def main() -> None:
|
|
| 146 |
parser = argparse.ArgumentParser()
|
| 147 |
parser.add_argument("--repo-root", type=Path, default=Path.cwd())
|
| 148 |
parser.add_argument("--manifest", type=Path, action="append", default=[])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
parser.add_argument("--output", type=Path, required=True)
|
| 150 |
parser.add_argument("--count", type=int, default=1000)
|
| 151 |
parser.add_argument("--seed", type=int, default=20260511)
|
|
@@ -153,14 +187,20 @@ def main() -> None:
|
|
| 153 |
parser.add_argument("--bucket-prefix", action="append", default=[])
|
| 154 |
args = parser.parse_args()
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
write_samples(args.output, selected)
|
| 161 |
-
print(f"candidates={len(candidates)}")
|
| 162 |
print(f"selected={len(selected)} -> {args.output}")
|
| 163 |
-
print(f"path_style={args.path_style}, seed={args.seed}")
|
| 164 |
|
| 165 |
|
| 166 |
if __name__ == "__main__":
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
+
"""Build val_N eval sample jsonl files.
|
| 3 |
|
| 4 |
The output schema matches the saved val20/val100 artifacts:
|
| 5 |
{"id", "target_video", "control_video", "prompt"}.
|
| 6 |
+
|
| 7 |
+
For reproducing the original val20/val100 split, use --metadata-val-csv with
|
| 8 |
+
one of the held-out real_train/metadata.val.csv files. The manifest sampling
|
| 9 |
+
mode is only a fallback for making a generic eval-like set and is not guaranteed
|
| 10 |
+
to be held out from a specific training run.
|
| 11 |
"""
|
| 12 |
|
| 13 |
from __future__ import annotations
|
| 14 |
|
| 15 |
import argparse
|
| 16 |
+
import csv
|
| 17 |
import json
|
| 18 |
import random
|
| 19 |
import re
|
|
|
|
| 45 |
return data
|
| 46 |
|
| 47 |
|
| 48 |
+
def read_metadata_val_csv(path: Path, count: int) -> list[dict[str, str]]:
|
| 49 |
+
rows: list[dict[str, str]] = []
|
| 50 |
+
with path.open("r", encoding="utf-8", newline="") as handle:
|
| 51 |
+
reader = csv.DictReader(handle)
|
| 52 |
+
missing = {"video", "vace_video", "prompt"} - set(reader.fieldnames or [])
|
| 53 |
+
if missing:
|
| 54 |
+
raise ValueError(f"{path} missing required columns: {sorted(missing)}")
|
| 55 |
+
for row in reader:
|
| 56 |
+
rows.append(
|
| 57 |
+
{
|
| 58 |
+
"target_video": str(row["video"]),
|
| 59 |
+
"control_video": str(row["vace_video"]),
|
| 60 |
+
"prompt": str(row["prompt"]),
|
| 61 |
+
}
|
| 62 |
+
)
|
| 63 |
+
if len(rows) >= count:
|
| 64 |
+
break
|
| 65 |
+
if len(rows) < count:
|
| 66 |
+
raise RuntimeError(f"{path} only has {len(rows)} rows, requested {count}")
|
| 67 |
+
return rows
|
| 68 |
+
|
| 69 |
+
|
| 70 |
def sanitize_flat_relpath(relpath: str) -> str:
|
| 71 |
parts = [re.sub(r"[^0-9A-Za-z._-]+", "_", piece) for piece in relpath.split("/")]
|
| 72 |
return "__".join(parts)
|
|
|
|
| 174 |
parser = argparse.ArgumentParser()
|
| 175 |
parser.add_argument("--repo-root", type=Path, default=Path.cwd())
|
| 176 |
parser.add_argument("--manifest", type=Path, action="append", default=[])
|
| 177 |
+
parser.add_argument(
|
| 178 |
+
"--metadata-val-csv",
|
| 179 |
+
type=Path,
|
| 180 |
+
default=None,
|
| 181 |
+
help="Held-out real_train/metadata.val.csv. Use this to reproduce val20/val100 logic.",
|
| 182 |
+
)
|
| 183 |
parser.add_argument("--output", type=Path, required=True)
|
| 184 |
parser.add_argument("--count", type=int, default=1000)
|
| 185 |
parser.add_argument("--seed", type=int, default=20260511)
|
|
|
|
| 187 |
parser.add_argument("--bucket-prefix", action="append", default=[])
|
| 188 |
args = parser.parse_args()
|
| 189 |
|
| 190 |
+
if args.metadata_val_csv is not None:
|
| 191 |
+
metadata_path = args.metadata_val_csv if args.metadata_val_csv.is_absolute() else args.repo_root / args.metadata_val_csv
|
| 192 |
+
selected = read_metadata_val_csv(metadata_path, args.count)
|
| 193 |
+
print(f"source={metadata_path}")
|
| 194 |
+
print("mode=metadata.val.csv prefix")
|
| 195 |
+
else:
|
| 196 |
+
manifests = args.manifest or [Path(p) for p in DEFAULT_MANIFESTS]
|
| 197 |
+
bucket_prefixes = tuple(args.bucket_prefix or DEFAULT_BUCKET_PREFIXES)
|
| 198 |
+
candidates = collect_candidates(args.repo_root, manifests, bucket_prefixes, args.path_style)
|
| 199 |
+
selected = stratified_sample(candidates, args.count, args.seed)
|
| 200 |
+
print(f"candidates={len(candidates)}")
|
| 201 |
+
print(f"path_style={args.path_style}, seed={args.seed}")
|
| 202 |
write_samples(args.output, selected)
|
|
|
|
| 203 |
print(f"selected={len(selected)} -> {args.output}")
|
|
|
|
| 204 |
|
| 205 |
|
| 206 |
if __name__ == "__main__":
|