| #!/usr/bin/env bash |
| |
| set -eo pipefail |
|
|
| GPU_ID="${CUDA_VISIBLE_DEVICES:-1}" |
| BASELINE="/home/dyvm6xra/dyvm6xrauser11/workspace/cz/FlowCache/FlowCache4MAGI-1/outputs/a_woman_dancing_2026-05-19_09-49-14/output_2026-05-19_09-49-14.mp4" |
| DEV3="/home/dyvm6xra/dyvm6xrauser11/workspace/cz/FlowCache/FlowCache4MAGI-1-dev3-motion" |
| DEV4="/home/dyvm6xra/dyvm6xrauser11/workspace/cz/FlowCache/FlowCache4MAGI-1-dev4-detail" |
| DEV5="/home/dyvm6xra/dyvm6xrauser11/workspace/cz/FlowCache/FlowCache4MAGI-1-dev5-history" |
| PROMPT="${PROMPT:-a woman dancing.}" |
| OUT="${OUT:-$DEV5/outputs/compare_v345_$(date +%Y%m%d_%H%M%S)}" |
| mkdir -p "$DEV5/outputs" |
| mkdir -p "$OUT/report" |
|
|
| export MASTER_ADDR=localhost |
| export CUDA_VISIBLE_DEVICES="$GPU_ID" |
| export PAD_HQ=1 PAD_DURATION=1 |
| export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True |
| export OFFLOAD_T5_CACHE=true OFFLOAD_VAE_CACHE=true |
|
|
| set +u |
| source "${HOME}/miniforge3/etc/profile.d/conda.sh" 2>/dev/null || source "${HOME}/anaconda3/etc/profile.d/conda.sh" |
| conda activate magi |
| python3 -c "import numpy as np; exit(0 if int(np.__version__.split('.')[0])<2 else 1)" || pip install -q "numpy>=1.24,<2.0" |
|
|
| make_runtime() { |
| python3 - "$1" "$2" <<'PY' |
| import json, sys |
| with open("/home/dyvm6xra/dyvm6xrauser11/workspace/cz/FlowCache/FlowCache4MAGI-1-dev3-motion/config/single_run/flowcache_t2v.json") as f: |
| cfg = json.load(f) |
| cfg["runtime_config"]["num_frames"] = int(sys.argv[2]) |
| with open(sys.argv[1], "w") as f: |
| json.dump(cfg, f, indent=4) |
| PY |
| } |
|
|
| RESULTS="$OUT/report/results.csv" |
| echo "variant,version,frames,psnr_db,ssim,black_ratio,reuse_rate_pct,wall_sec,peak_gb,video_path,log_path,config" > "$RESULTS" |
|
|
| run_one() { |
| local version="$1" root="$2" yaml="$3" tag="$4" frames="$5" |
| local runtime="$OUT/runtime_${frames}f.json" |
| make_runtime "$runtime" "$frames" |
| local edir="$OUT/${version}_${tag}_${frames}f" |
| mkdir -p "$edir" |
| local out="$edir/output.mp4" log="$edir/infer.log" metric="$edir/metrics.json" |
| export MASTER_PORT=$((6300 + RANDOM % 300)) |
| if [ "$root" = "$DEV4" ]; then export PYTHONPATH="${DEV4}:${DEV3}" |
| elif [ "$root" = "$DEV5" ]; then export PYTHONPATH="${DEV5}:${DEV4}:${DEV3}" |
| else export PYTHONPATH="${DEV3}:${DEV4}"; fi |
| echo "========== $version / $tag @ ${frames}f ==========" |
| local t0=$(date +%s) |
| set +e |
| ( cd "$root" && python3 inference/pipeline/motioncache.py \ |
| --config_file "$runtime" --mode t2v --prompt "$PROMPT" \ |
| --output_path "$out" --additional_config "$yaml" \ |
| --motioncache_metric_stats_path "$metric" 2>&1 | tee "$log" ) |
| local rc=${PIPESTATUS[0]}; set -e |
| local t1=$(date +%s) |
| [ -f "$out" ] && [ "$rc" -eq 0 ] || { echo "FAILED $tag"; return 1; } |
| eval_out=$(python3 "$DEV3/tools/eval_run.py" --baseline "$BASELINE" --generated "$out" --log "$log" --metric "$metric") |
| PSNR=NA; SSIM=NA; BLACK=NA; REUSE=NA; PEAK=NA |
| while IFS='=' read -r k v; do |
| case "$k" in PSNR) PSNR="$v" ;; SSIM) SSIM="$v" ;; BLACK) BLACK="$v" ;; REUSE) REUSE="$v" ;; PEAK) PEAK="$v" ;; esac |
| done <<< "$eval_out" |
| echo "$tag,$version,$frames,$PSNR,$SSIM,$BLACK,$REUSE,$((t1-t0)),$PEAK,$out,$log,$yaml" >> "$RESULTS" |
| echo " PSNR=${PSNR}dB reuse=${REUSE}% time=$((t1-t0))s" |
| } |
|
|
| |
| for spec in \ |
| "default|$DEV5/yaml_config/single_run/historycache_config.yaml" \ |
| "decay0.5|$DEV5/yaml_config/single_run/history_decay0.5.yaml" \ |
| "decay0.85|$DEV5/yaml_config/single_run/history_decay0.85.yaml" \ |
| "anchor0.5|$DEV5/yaml_config/single_run/history_anchor0.5.yaml" \ |
| "streak0.35|$DEV5/yaml_config/single_run/history_streak0.35.yaml"; do |
| IFS='|' read -r tag ypath <<< "$spec" |
| run_one dev5 "$DEV5" "$ypath" "$tag" 120 || true |
| done |
|
|
| BEST_DEV5_YAML=$(python3 - "$RESULTS" "$DEV5/yaml_config/single_run/historycache_config.yaml" <<'PY' |
| import csv, sys |
| rows = [r for r in csv.DictReader(open(sys.argv[1])) if r["version"]=="dev5" and r["frames"]=="120" and r["psnr_db"] not in ("NA","")] |
| if not rows: |
| print(sys.argv[2]) |
| else: |
| def score(r): |
| p=float(r["psnr_db"]) if r["psnr_db"]!="inf" else 100 |
| return p+0.02*float(r["reuse_rate_pct"] or 0) |
| print(max(rows,key=score)["config"]) |
| PY |
| ) |
| BEST_DEV5_TAG=$(python3 - "$RESULTS" <<'PY' |
| import csv, sys |
| rows = [r for r in csv.DictReader(open(sys.argv[1])) if r["version"]=="dev5" and r["frames"]=="120" and r["psnr_db"] not in ("NA","")] |
| if not rows: |
| print("default") |
| else: |
| def score(r): |
| p=float(r["psnr_db"]) if r["psnr_db"]!="inf" else 100 |
| return p+0.02*float(r["reuse_rate_pct"] or 0) |
| print(max(rows,key=score)["variant"]) |
| PY |
| ) |
| echo "Best dev5 @120f: $BEST_DEV5_TAG -> $BEST_DEV5_YAML" |
| cp "$BEST_DEV5_YAML" "$DEV5/yaml_config/single_run/historycache_config_best.yaml" |
|
|
| |
| run_one dev3 "$DEV3" "$DEV3/yaml_config/single_run/motioncache_config_best.yaml" best 240 || true |
| run_one dev4 "$DEV4" "$DEV4/yaml_config/single_run/motiondetail_config_best.yaml" best 240 || true |
| run_one dev5 "$DEV5" "$BEST_DEV5_YAML" "$BEST_DEV5_TAG" 240 || true |
|
|
| python3 - "$RESULTS" "$OUT/report/comparison_v345.md" <<'PY' |
| import csv, sys |
| from datetime import datetime |
| csv_path, md_path = sys.argv[1:3] |
| rows = [r for r in csv.DictReader(open(csv_path)) if r["psnr_db"] not in ("NA", "")] |
| def score(r): |
| p = float(r["psnr_db"]) if r["psnr_db"] != "inf" else 100 |
| return p + 0.02 * float(r["reuse_rate_pct"] or 0) |
| lines = [ |
| "# dev3 vs dev4 vs dev5 对比报告", |
| f"\n生成时间: {datetime.now():%Y-%m-%d %H:%M:%S}\n", |
| "## 全部结果", |
| "| version | variant | frames | PSNR | reuse% | time(s) | score |", |
| "|---------|---------|--------|------|--------|---------|-------|", |
| ] |
| for r in sorted(rows, key=score, reverse=True): |
| lines.append( |
| f"| {r['version']} | {r['variant']} | {r['frames']} | {r['psnr_db']} | {r['reuse_rate_pct']} | {r['wall_sec']} | {score(r):.3f} |" |
| ) |
| full = [r for r in rows if r["frames"] == "240"] |
| lines += ["\n## 240f 全分辨率对比(最终)\n", "| version | variant | PSNR | reuse% | time(s) |", "|---------|---------|------|--------|---------|"] |
| for r in full: |
| lines.append(f"| {r['version']} | {r['variant']} | {r['psnr_db']} dB | {r['reuse_rate_pct']} | {r['wall_sec']} |") |
| if len(full) >= 2: |
| d3 = next((r for r in full if r["version"]=="dev3"), None) |
| d4 = next((r for r in full if r["version"]=="dev4"), None) |
| d5 = next((r for r in full if r["version"]=="dev5"), None) |
| lines.append("\n## 结论\n") |
| for name, r in [("dev3", d3), ("dev4", d4), ("dev5", d5)]: |
| if r: lines.append(f"- **{name}** `{r['variant']}`: PSNR={r['psnr_db']}dB reuse={r['reuse_rate_pct']}%") |
| if d3 and d5: |
| lines.append(f"- dev5 vs dev3 PSNR: {float(d5['psnr_db'])-float(d3['psnr_db']):+.2f} dB") |
| if d4 and d5: |
| lines.append(f"- dev5 vs dev4 PSNR: {float(d5['psnr_db'])-float(d4['psnr_db']):+.2f} dB") |
| open(md_path, "w").write("\n".join(lines) + "\n") |
| print(f"Report: {md_path}") |
| PY |
|
|
| echo "Done: $OUT/report/comparison_v345.md" |
|
|