#!/bin/bash
# ⓐ 발주(t_65259bce4000) 런 드라이버 — 터보 LoRA 판본 A/B (ckpt850 vs v4_step600)
# 고정 = on4 구성(4스텝 · sage+EasyCache · 512×896 · int8_convrot DiT · seed 230688 · strength 1.0)
# 변수 = turbo LoRA 판본 **하나만** (+ 선택 C 에서 video VAE)
# ★프롬프트는 v2(걷기·상반신) — 구 프롬프트(힙합)와 화질 비교 불가라 A 도 새로 잰다(note 31896).
# ★서로 다른 그래프로 번갈아 제출 — 같은 그래프 연속 제출은 노드 출력 재사용으로 15s 에 끝난다.
# ★판정 2점 = run2(b600 warm) · run3(a850 warm). 둘 다 직전 런에서 LoRA 를 갈아끼운 대칭 조건.
set -u
OUT=$HOME/ai/experiments/h3-fast-wf-repro
TSV=$OUT/runs-v2.tsv
BUILD=$HOME/work/dock/scripts/h3-r2v-build.py
SUBMIT=$HOME/work/dock/scripts/h3-r2v-submit.py

COMMON=(--unet minimax_h3_ref2va_pruned_int8_convrot.safetensors
        --length 124 --seed 230688 --steps 4 --width 512 --height 896
        --sage-patch --easycache --lora-strength 1.0
        --cast "$OUT/ref-j023688.png" --prompt-file "$OUT/prompt-v2-walk.txt")

python3 "$BUILD" --tag a850 "${COMMON[@]}" \
  --turbo-lora minimax_h3_turbo_4step_ema_ckpt850.safetensors || exit 1
python3 "$BUILD" --tag b600 "${COMMON[@]}" \
  --turbo-lora minimax_h3_turbo_v4_step600.safetensors || exit 1

printf 'tag\tlora\tvideo_vae\tthermal\tstart_epoch\tend_epoch\twall_s\n' > "$TSV"
run () {  # tag lora video_vae thermal
  local tag=$1 lora=$2 vae=$3 thermal=$4
  local s; s=$(date +%s)
  echo "=== RUN $tag (lora=$lora vae=$vae thermal=$thermal) start=$s ==="
  DOCKAIQ_BYPASS=1 python3 "$SUBMIT" --workflow /tmp/h3-r2v-$tag.json
  local rc=$? e; e=$(date +%s)
  printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$tag" "$lora" "$vae" "$thermal" "$s" "$e" "$((e-s))" >> "$TSV"
  echo "=== END $tag rc=$rc wall=$((e-s))s ==="
  [ $rc -ne 0 ] && echo "❌ $tag 실패 — 표에서 제외 판정"
  return 0
}
run a850 ckpt850    fp16 cold
run b600 v4_step600 fp16 warm
run a850 ckpt850    fp16 warm
echo "=== ALL DONE ==="
cat "$TSV"
