#!/bin/bash
# t_e8df0ba946df — fp16_accumulation 단독 측정 (2점)
# 고정 = 현행 프로덕션 ref2va 구성 그대로: int8_convrot DiT · turbo LoRA ckpt850@1.0 · 4스텝 ·
#        sage+EasyCache · 512×896(축 ⑦ 전환 후) · length 124 · seed 230688 · 같은 레퍼런스·프롬프트.
# 변수 = `ModelPatchTorchSettings(enable_fp16_accumulation=true)` **하나만**.
# ★순서 = base(cold) → fp16(warm) → base(warm). 판정 2점은 run2·run3 (둘 다 warm).
#   같은 그래프 연속 제출 금지(노드 출력 재사용으로 15s 에 끝나는 함정) → 번갈아 짠다.
set -u
OUT=$HOME/ai/experiments/h3-fp16accum-axis
TSV=$OUT/runs.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
        --turbo-lora minimax_h3_turbo_4step_ema_ckpt850.safetensors --lora-strength 1.0
        --length 124 --seed 230688 --steps 4 --width 512 --height 896
        --sage-patch --easycache
        --cast "$OUT/ref-j023688.png" --prompt-file "$OUT/prompt.txt")

python3 "$BUILD" --tag base  "${COMMON[@]}" || exit 1
python3 "$BUILD" --tag fp16  "${COMMON[@]}" --fp16-accum || exit 1

printf 'tag\tfp16_accum\tthermal\tstart_epoch\tend_epoch\twall_s\n' > "$TSV"
run () {  # tag fp16 thermal
  local tag=$1 fp=$2 th=$3 s e rc
  s=$(date +%s)
  echo "=== RUN $tag (fp16_accum=$fp thermal=$th) start=$s ==="
  DOCKAIQ_BYPASS=1 python3 "$SUBMIT" --workflow /tmp/h3-r2v-$tag.json
  rc=$?; e=$(date +%s)
  printf '%s\t%s\t%s\t%s\t%s\t%s\n' "$tag" "$fp" "$th" "$s" "$e" "$((e-s))" >> "$TSV"
  echo "=== END $tag rc=$rc wall=$((e-s))s ==="
  return 0
}
run base off cold
run fp16 on  warm
run base off warm
echo "=== ALL DONE ==="
cat "$TSV"
