Ouzhang commited on
Commit
44c5767
·
verified ·
1 Parent(s): 2424b96

Add grouped smoke manifest sampler

Browse files
benchmarks/critic/aesthetic_rm/README.md CHANGED
@@ -31,6 +31,18 @@ python3 reference/benchmarks/critic/aesthetic_rm/filter_multi_candidate_groups.p
31
  Use `--max-candidates-per-group 4` if a few large groups dominate the manifest
32
  and you want a cheaper first pass.
33
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  ## 2. Run Traditional Metrics
35
 
36
  Use the existing traditional metric runner on the generated metrics manifest:
 
31
  Use `--max-candidates-per-group 4` if a few large groups dominate the manifest
32
  and you want a cheaper first pass.
33
 
34
+ For a tiny grouped smoke test:
35
+
36
+ ```bash
37
+ python3 reference/benchmarks/critic/aesthetic_rm/sample_smoke_manifest.py \
38
+ --input out/aesthetic_rm/ditto_candidates_multi.jsonl \
39
+ --output out/aesthetic_rm/smoke_candidates_20.jsonl \
40
+ --metrics-manifest out/aesthetic_rm/smoke_candidates_20_for_metrics.jsonl \
41
+ --groups 10 \
42
+ --candidates-per-group 2 \
43
+ --prefer-remote-paths
44
+ ```
45
+
46
  ## 2. Run Traditional Metrics
47
 
48
  Use the existing traditional metric runner on the generated metrics manifest:
benchmarks/critic/aesthetic_rm/sample_smoke_manifest.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Sample a tiny grouped manifest for smoke tests."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import json
8
+ import random
9
+ from collections import defaultdict
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+
14
+ def read_jsonl(path: Path) -> list[dict[str, Any]]:
15
+ rows: list[dict[str, Any]] = []
16
+ with path.open("r", encoding="utf-8") as handle:
17
+ for line in handle:
18
+ text = line.strip()
19
+ if text:
20
+ rows.append(json.loads(text))
21
+ return rows
22
+
23
+
24
+ def write_jsonl(path: Path, rows: list[dict[str, Any]]) -> None:
25
+ path.parent.mkdir(parents=True, exist_ok=True)
26
+ with path.open("w", encoding="utf-8") as handle:
27
+ for row in rows:
28
+ handle.write(json.dumps(row, ensure_ascii=False) + "\n")
29
+
30
+
31
+ def make_metrics_rows(rows: list[dict[str, Any]], prefer_remote: bool) -> list[dict[str, Any]]:
32
+ result = []
33
+ for row in rows:
34
+ source = row.get("source_video", "")
35
+ edited = row.get("edited_video", "")
36
+ if prefer_remote:
37
+ source = row.get("remote_source_video") or source
38
+ edited = row.get("remote_edited_video") or edited
39
+ result.append(
40
+ {
41
+ "split": row.get("dataset", ""),
42
+ "sample_id": row["candidate_id"],
43
+ "method": row.get("method", ""),
44
+ "instruction": row.get("instruction", ""),
45
+ "source_video": source,
46
+ "edited_video": edited,
47
+ }
48
+ )
49
+ return result
50
+
51
+
52
+ def main() -> None:
53
+ parser = argparse.ArgumentParser()
54
+ parser.add_argument("--input", type=Path, required=True)
55
+ parser.add_argument("--output", type=Path, required=True)
56
+ parser.add_argument("--metrics-manifest", type=Path, required=True)
57
+ parser.add_argument("--groups", type=int, default=10)
58
+ parser.add_argument("--candidates-per-group", type=int, default=2)
59
+ parser.add_argument("--seed", type=int, default=20260509)
60
+ parser.add_argument("--prefer-remote-paths", action="store_true")
61
+ args = parser.parse_args()
62
+
63
+ rows = read_jsonl(args.input)
64
+ groups: dict[str, list[dict[str, Any]]] = defaultdict(list)
65
+ for row in rows:
66
+ groups[str(row.get("group_id", ""))].append(row)
67
+
68
+ eligible = [
69
+ sorted(group, key=lambda item: (str(item.get("method", "")), str(item["candidate_id"])))
70
+ for group in groups.values()
71
+ if len(group) >= args.candidates_per_group
72
+ ]
73
+ rng = random.Random(args.seed)
74
+ rng.shuffle(eligible)
75
+
76
+ selected: list[dict[str, Any]] = []
77
+ for group in eligible[: args.groups]:
78
+ selected.extend(group[: args.candidates_per_group])
79
+
80
+ write_jsonl(args.output, selected)
81
+ write_jsonl(args.metrics_manifest, make_metrics_rows(selected, args.prefer_remote_paths))
82
+ print(f"selected {len(selected)} rows from {min(args.groups, len(eligible))} groups")
83
+ print(f"wrote candidates -> {args.output}")
84
+ print(f"wrote metrics manifest -> {args.metrics_manifest}")
85
+
86
+
87
+ if __name__ == "__main__":
88
+ main()