File size: 6,093 Bytes
bc29ee3 | 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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | #!/usr/bin/env python3
"""Score generated naive baselines with VBench-8 and build final summaries.
This script does not generate videos. Run
``generate_vbench8_extended_naive_baselines.py`` first, then use this entry
point to score FFFF plus any selected naive strategies. Strategies are scored
sequentially on the requested GPU; separate processes may be used on different
GPUs by passing disjoint ``--strategy`` sets and ``--no-summarize``.
"""
from __future__ import annotations
import argparse
import os
import subprocess
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
if str(REPO_ROOT) not in sys.path:
sys.path.insert(0, str(REPO_ROOT))
from scripts.naive_vbench_policies import (
ALL_STRATEGY_NAMES,
EVALUATION_STRATEGY_NAMES,
)
OUTPUT_DEFAULT = REPO_ROOT / "evaluation_runs/vbench8_extended_naive_baselines"
MAPPING_DEFAULT = REPO_ROOT / "assets/vbench8_extended_subset_mapping.json"
EXTENDED_PROMPTS_DEFAULT = REPO_ROOT / "prompts/vbench/all_dimension_extended.txt"
VBENCH_SITE_DEFAULT = REPO_ROOT / ".evaluation_env/vbench_site2"
VBENCH_INFO_DEFAULT = VBENCH_SITE_DEFAULT / "vbench/VBench_full_info.json"
VBENCH_CACHE_DEFAULT = Path("/data3/chenzhuo/.cache/vbench")
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--gpu", default="0")
parser.add_argument("--output-root", type=Path, default=OUTPUT_DEFAULT)
parser.add_argument("--mapping", type=Path, default=MAPPING_DEFAULT)
parser.add_argument(
"--extended-prompts", type=Path, default=EXTENDED_PROMPTS_DEFAULT
)
parser.add_argument("--vbench-site", type=Path, default=VBENCH_SITE_DEFAULT)
parser.add_argument("--vbench-info", type=Path, default=VBENCH_INFO_DEFAULT)
parser.add_argument("--vbench-cache", type=Path, default=VBENCH_CACHE_DEFAULT)
parser.add_argument(
"--strategy",
action="append",
choices=EVALUATION_STRATEGY_NAMES,
default=None,
help="Naive strategy to score; repeat as needed. Default: all six.",
)
parser.add_argument(
"--score-ffff",
action=argparse.BooleanOptionalAction,
default=True,
help="Also score the matched FFFF videos.",
)
parser.add_argument(
"--skip-existing", action=argparse.BooleanOptionalAction, default=True
)
parser.add_argument(
"--summarize",
action=argparse.BooleanOptionalAction,
default=True,
help="Build pixel and final summaries for this exact strategy set.",
)
return parser.parse_args()
def checked_file(path: Path, label: str) -> Path:
resolved = path.resolve()
if not resolved.is_file():
raise FileNotFoundError(f"Missing {label}: {resolved}")
return resolved
def run(command: list[str], env: dict[str, str]) -> None:
print("[run] " + " ".join(command), flush=True)
subprocess.run(command, cwd=REPO_ROOT, env=env, check=True)
def main() -> None:
args = parse_args()
selected = args.strategy or list(EVALUATION_STRATEGY_NAMES)
if len(set(selected)) != len(selected):
raise ValueError("--strategy values must be unique")
strategies = (["ffff"] if args.score_ffff else []) + selected
if args.summarize and "ffff" not in strategies:
raise ValueError("Final summaries require --score-ffff")
unknown = set(strategies) - set(ALL_STRATEGY_NAMES)
if unknown:
raise ValueError(f"Unknown strategies: {sorted(unknown)}")
output_root = args.output_root.resolve()
mapping = checked_file(args.mapping, "mapping")
extended_prompts = checked_file(args.extended_prompts, "extended prompts")
vbench_site = args.vbench_site.resolve()
if not vbench_site.is_dir():
raise FileNotFoundError(f"Missing VBench site directory: {vbench_site}")
vbench_info = checked_file(args.vbench_info, "VBench full info")
videos_root = output_root / "generated_videos"
if not videos_root.is_dir():
raise FileNotFoundError(f"Missing generated videos: {videos_root}")
env = os.environ.copy()
existing_pythonpath = env.get("PYTHONPATH")
pythonpath_parts = [str(vbench_site), str(REPO_ROOT)]
if existing_pythonpath:
pythonpath_parts.append(existing_pythonpath)
env["PYTHONPATH"] = os.pathsep.join(pythonpath_parts)
env["VBENCH_CACHE_DIR"] = str(args.vbench_cache.resolve())
env["VBENCH_BERT_MODEL_DIR"] = str(
(args.vbench_cache / "bert-base-uncased").resolve()
)
if args.summarize:
run(
[
sys.executable,
str(REPO_ROOT / "scripts/summarize_vbench8_generation.py"),
"--output-root",
str(output_root),
"--strategies",
*strategies,
],
env,
)
for strategy in strategies:
command = [
sys.executable,
str(REPO_ROOT / "scripts/eval_vbench8_extended_subset.py"),
"--gpu",
str(args.gpu),
"--strategy",
strategy,
"--mapping",
str(mapping),
"--videos-root",
str(videos_root),
"--output-root",
str(output_root),
"--vbench-info",
str(vbench_info),
]
if args.skip_existing:
command.append("--skip-existing")
run(command, env)
if args.summarize:
run(
[
sys.executable,
str(REPO_ROOT / "scripts/summarize_vbench8_extended.py"),
"--output-root",
str(output_root),
"--mapping",
str(mapping),
"--extended-prompts",
str(extended_prompts),
"--vbench-info",
str(vbench_info),
"--strategies",
*strategies,
],
env,
)
print(f"[complete] strategies={','.join(strategies)}", flush=True)
if __name__ == "__main__":
main()
|