#!/bin/bash
# ⓐ 발주(t_65259bce4000) 2차 런 — ① 의상 정체성 소견의 seed 재현성 ② VAE 축(C)
# ★왜 seed 2점째인가: 1차(seed 230688)에서 **A 가 레퍼런스 의상을 바꾸고 B 는 유지**하는 차이가 나왔다.
#   A 는 cold/warm 이 md5 동일이라 그 seed 에선 결정적이지만, **seed 1점은 판본 일반화 근거가 못 된다**.
#   판정(교체 권고 여부)이 이 축에 걸리므로 다른 seed 1쌍으로 재현을 본다.
# ★C 는 발주가 "B 가 유의미할 때만" 이라 건 조건부인데, ①에서 B 가 품질축에서 유의미해져 발동한다.
#   C 는 B(seed 230688)와 **VAE 만** 다르다 ⇒ 축이 하나.
set -u
OUT=$HOME/ai/experiments/h3-fast-wf-repro
TSV=$OUT/runs-v3.tsv
BUILD=$HOME/work/dock/scripts/h3-r2v-build.py
SUBMIT=$HOME/work/dock/scripts/h3-r2v-submit.py
S2=770101   # 2차 seed (하네스 기본값 · 1차 230688 과 다른 점이면 충분)

COMMON=(--unet minimax_h3_ref2va_pruned_int8_convrot.safetensors
        --length 124 --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-s2 "${COMMON[@]}" --seed $S2 \
  --turbo-lora minimax_h3_turbo_4step_ema_ckpt850.safetensors || exit 1
python3 "$BUILD" --tag b600-s2 "${COMMON[@]}" --seed $S2 \
  --turbo-lora minimax_h3_turbo_v4_step600.safetensors || exit 1
python3 "$BUILD" --tag c600vae "${COMMON[@]}" --seed 230688 \
  --turbo-lora minimax_h3_turbo_v4_step600.safetensors \
  --video-vae minimax_h3_video_vae_int8_convrot.safetensors || exit 1

printf 'tag\tlora\tvideo_vae\tseed\tthermal\tstart_epoch\tend_epoch\twall_s\n' > "$TSV"
run () {  # tag lora video_vae seed thermal
  local tag=$1 lora=$2 vae=$3 seed=$4 thermal=$5
  local s; s=$(date +%s)
  echo "=== RUN $tag (lora=$lora vae=$vae seed=$seed 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\t%s\n' "$tag" "$lora" "$vae" "$seed" "$thermal" "$s" "$e" "$((e-s))" >> "$TSV"
  echo "=== END $tag rc=$rc wall=$((e-s))s ==="
  [ $rc -ne 0 ] && echo "❌ $tag 실패 — 표에서 제외 판정"
  return 0
}
run a850-s2 ckpt850    fp16          $S2    warm
run b600-s2 v4_step600 fp16          $S2    warm
run c600vae v4_step600 int8_convrot  230688 warm
echo "=== ALL DONE ==="
cat "$TSV"
