Download video_gen_14d/scripts/launch_baseline_8gpu.py from jamie33/waitlist: direct link, hf CLI and curl.
- Browser
- Download file 8.84 kB
-
https://huggingface.co/datasets/jamie33/waitlist/resolve/main/video_gen_14d/scripts/launch_baseline_8gpu.py
- Command line
-
hf download hf://datasets/jamie33/waitlist/video_gen_14d/scripts/launch_baseline_8gpu.py
-
curl -L -o launch_baseline_8gpu.py https://huggingface.co/datasets/jamie33/waitlist/resolve/main/video_gen_14d/scripts/launch_baseline_8gpu.py
8.84 kB
| #!/usr/bin/env python3 | |
| """Launch one independent VACE baseline sample per H200 GPU.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import os | |
| import subprocess | |
| import sys | |
| import time | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| PYTHON = ROOT / ".venv" / "bin" / "python" | |
| VACE_ROOT = ROOT / "third_party" / "VACE" | |
| INFERENCE = VACE_ROOT / "vace" / "vace_wan_inference.py" | |
| MODEL = ROOT / "models" / "Wan2.1-VACE-1.3B" | |
| BENCHMARK = ROOT / "data" / "VACE-Benchmark" / "assets" / "examples" | |
| TASKS = [ | |
| { | |
| "name": "depth", | |
| "src_video": "depth/src_video.mp4", | |
| "prompt": ( | |
| "一群年轻人在天空之城拍摄集体照。一对年轻情侣手牵手、相视而笑," | |
| "周围是彩色热气球和闪烁的星星。镜头从近景缓缓拉远,写实摄影风格。" | |
| ), | |
| }, | |
| { | |
| "name": "flow", | |
| "src_video": "flow/src_video.mp4", | |
| "prompt": ( | |
| "纪实摄影风格,一颗鲜红的小番茄缓缓落入盛着牛奶的玻璃杯中," | |
| "慢镜头捕捉水花在空中形成弧线,近景特写,垂直俯视。" | |
| ), | |
| }, | |
| { | |
| "name": "pose", | |
| "src_video": "pose/src_video.mp4", | |
| "prompt": ( | |
| "热带庆祝派对上,一家人围坐在椰子树下的长桌旁,年轻人举杯," | |
| "孩子在沙滩奔跑。动态中景捕捉自然的人体动作,写实风格。" | |
| ), | |
| }, | |
| { | |
| "name": "scribble", | |
| "src_video": "scribble/src_video.mp4", | |
| "prompt": ( | |
| "荧光色无人机从极低空高速掠过超现实主义风格的西安古城墙," | |
| "尘埃反射阳光,镜头流畅切换至砖石特写,画质清晰华丽。" | |
| ), | |
| }, | |
| { | |
| "name": "layout", | |
| "src_video": "layout/src_video.mp4", | |
| "prompt": ( | |
| "一只成鸟在树枝上的巢中喂养幼鸟,随后飞走并再次带回食物。" | |
| "固定机位,背景是模糊绿色植被,强调鸟类自然行为。" | |
| ), | |
| }, | |
| { | |
| "name": "gray", | |
| "src_video": "gray/src_video.mp4", | |
| "prompt": ( | |
| "镜头缓缓向右平移,身穿淡黄色长裙的长发女孩面对镜头微笑," | |
| "长发随风轻扬,背景是秋日红黄树叶,清新写实风格。" | |
| ), | |
| }, | |
| { | |
| "name": "firstframe", | |
| "src_video": "firstframe/src_video.mp4", | |
| "src_mask": "firstframe/src_mask.mp4", | |
| "prompt": ( | |
| "纪实摄影风格,一位中国越野爱好者坐在越野车上手持车载电台," | |
| "表情专注。镜头从车外缓缓拉近并定格在人物面部。" | |
| ), | |
| }, | |
| { | |
| "name": "inpainting", | |
| "src_video": "inpainting/src_video.mp4", | |
| "src_mask": "inpainting/src_mask.mp4", | |
| "prompt": ( | |
| "一只巨大的金色凤凰从繁华城市上空展翅飞过,羽毛像火焰般发光," | |
| "下方人群惊叹、霓虹闪烁,镜头俯视城市街道。" | |
| ), | |
| }, | |
| ] | |
| def parse_gpu_status() -> dict[int, dict[str, int]]: | |
| output = subprocess.check_output( | |
| [ | |
| "nvidia-smi", | |
| "--query-gpu=index,memory.free,utilization.gpu", | |
| "--format=csv,noheader,nounits", | |
| ], | |
| text=True, | |
| ) | |
| status: dict[int, dict[str, int]] = {} | |
| for line in output.strip().splitlines(): | |
| index, free_mib, utilization = (int(value.strip()) for value in line.split(",")) | |
| status[index] = {"free_mib": free_mib, "utilization": utilization} | |
| return status | |
| def build_command( | |
| task: dict[str, str], | |
| output_dir: Path, | |
| seed: int, | |
| frames: int, | |
| steps: int, | |
| ) -> list[str]: | |
| command = [ | |
| str(PYTHON), | |
| str(INFERENCE), | |
| "--model_name", | |
| "vace-1.3B", | |
| "--size", | |
| "480p", | |
| "--frame_num", | |
| str(frames), | |
| "--ckpt_dir", | |
| str(MODEL), | |
| "--offload_model", | |
| "False", | |
| "--sample_steps", | |
| str(steps), | |
| "--base_seed", | |
| str(seed), | |
| "--use_prompt_extend", | |
| "plain", | |
| "--save_dir", | |
| str(output_dir), | |
| "--prompt", | |
| task["prompt"], | |
| "--src_video", | |
| str(BENCHMARK / task["src_video"]), | |
| ] | |
| if task.get("src_mask"): | |
| command.extend(["--src_mask", str(BENCHMARK / task["src_mask"])]) | |
| return command | |
| def validate_assets() -> None: | |
| required = [PYTHON, INFERENCE, MODEL / "diffusion_pytorch_model.safetensors"] | |
| missing = [str(path) for path in required if not path.exists()] | |
| for task in TASKS: | |
| source = BENCHMARK / task["src_video"] | |
| if not source.exists(): | |
| missing.append(str(source)) | |
| if task.get("src_mask"): | |
| mask = BENCHMARK / task["src_mask"] | |
| if not mask.exists(): | |
| missing.append(str(mask)) | |
| if missing: | |
| raise FileNotFoundError("Missing required assets:\n" + "\n".join(missing)) | |
| def main() -> int: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--gpus", default="0,1,2,3,4,5,6,7") | |
| parser.add_argument("--run-id", default=time.strftime("%Y%m%d_%H%M%S")) | |
| parser.add_argument("--frames", type=int, default=49) | |
| parser.add_argument("--steps", type=int, default=20) | |
| parser.add_argument("--seed", type=int, default=2026) | |
| parser.add_argument("--min-free-mib", type=int, default=60_000) | |
| parser.add_argument( | |
| "--force", | |
| action="store_true", | |
| help="Launch even when the selected GPUs do not meet the free-memory guard.", | |
| ) | |
| args = parser.parse_args() | |
| gpu_ids = [int(value) for value in args.gpus.split(",") if value.strip()] | |
| if not gpu_ids or len(gpu_ids) > len(TASKS): | |
| parser.error(f"Choose between 1 and {len(TASKS)} GPUs") | |
| if args.frames < 1 or (args.frames - 1) % 4 != 0: | |
| parser.error("--frames must have the form 4n+1") | |
| validate_assets() | |
| status = parse_gpu_status() | |
| blocked = { | |
| gpu: status.get(gpu) | |
| for gpu in gpu_ids | |
| if gpu not in status or status[gpu]["free_mib"] < args.min_free_mib | |
| } | |
| if blocked and not args.force: | |
| print(json.dumps({"status": "blocked", "gpus": blocked}, indent=2)) | |
| return 2 | |
| run_root = ROOT / "outputs" / "baseline" / args.run_id | |
| run_root.mkdir(parents=True, exist_ok=False) | |
| processes: list[tuple[int, str, subprocess.Popen[bytes], object]] = [] | |
| manifest: list[dict[str, object]] = [] | |
| for offset, gpu in enumerate(gpu_ids): | |
| task = TASKS[offset] | |
| task_dir = run_root / f"gpu{gpu}_{task['name']}" | |
| task_dir.mkdir(parents=True) | |
| log_path = task_dir / "run.log" | |
| command = build_command( | |
| task, | |
| task_dir, | |
| seed=args.seed + offset, | |
| frames=args.frames, | |
| steps=args.steps, | |
| ) | |
| env = os.environ.copy() | |
| env["CUDA_VISIBLE_DEVICES"] = str(gpu) | |
| env["TOKENIZERS_PARALLELISM"] = "false" | |
| env["PYTHONUNBUFFERED"] = "1" | |
| log_handle = log_path.open("wb") | |
| process = subprocess.Popen( | |
| command, | |
| cwd=VACE_ROOT, | |
| env=env, | |
| stdout=log_handle, | |
| stderr=subprocess.STDOUT, | |
| ) | |
| processes.append((gpu, task["name"], process, log_handle)) | |
| manifest.append( | |
| { | |
| "gpu": gpu, | |
| "task": task["name"], | |
| "pid": process.pid, | |
| "seed": args.seed + offset, | |
| "frames": args.frames, | |
| "steps": args.steps, | |
| "output_dir": str(task_dir), | |
| "command": command, | |
| } | |
| ) | |
| print(f"STARTED gpu={gpu} task={task['name']} pid={process.pid}") | |
| (run_root / "manifest.json").write_text( | |
| json.dumps(manifest, ensure_ascii=False, indent=2), | |
| encoding="utf-8", | |
| ) | |
| failed = False | |
| for gpu, task_name, process, log_handle in processes: | |
| return_code = process.wait() | |
| log_handle.close() | |
| print(f"FINISHED gpu={gpu} task={task_name} exit={return_code}") | |
| failed = failed or return_code != 0 | |
| summary = { | |
| "run_id": args.run_id, | |
| "failed": failed, | |
| "results": [ | |
| { | |
| "gpu": gpu, | |
| "task": task_name, | |
| "exit_code": process.returncode, | |
| } | |
| for gpu, task_name, process, _ in processes | |
| ], | |
| } | |
| (run_root / "summary.json").write_text( | |
| json.dumps(summary, ensure_ascii=False, indent=2), | |
| encoding="utf-8", | |
| ) | |
| print("VACE_BASELINE_COMPLETE" if not failed else "VACE_BASELINE_FAILED") | |
| return 1 if failed else 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |