fairtalking-second-work / scripts /run_all_ablations_diffusion.sh
huahua123313's picture
Add files using upload-large-folder tool
a17b394 verified
Raw
History Blame Contribute Delete
4.9 kB
#!/usr/bin/env bash
# Run ALL 31 CTA ablation variants on the diffusion-only training split.
#
# Mirrors scripts/run_all_ablations.sh but invokes
# scripts/train_cta_ablation_diffusion.sh under the hood, so:
# * train + val are restricted to 5 diffusion generators + Real;
# * each variant's output goes to outputs/cta_ablation_diffusion_<V>_<TS>/
# (does NOT overwrite the original cta_ablation_<V>_<TS>/ directories).
#
# Usage:
# # Sequential (safe, one GPU job at a time):
# bash scripts/run_all_ablations_diffusion.sh
#
# # Parallel (if you have spare GPUs, e.g. 4 variants concurrently):
# bash scripts/run_all_ablations_diffusion.sh --parallel
#
# # Run only a specific group (A / B / C / D / E / F / G / M):
# bash scripts/run_all_ablations_diffusion.sh --group A
# bash scripts/run_all_ablations_diffusion.sh --group M
#
# After all runs finish, evaluate held-out families with:
# bash scripts/batch_test_cta_ablation_diffusion.sh
set -euo pipefail
cd "$(dirname "$0")/.."
[ -f .env ] && set -a && . ./.env && set +a
# ---- parse args ------------------------------------------------------------
# Recognized flags: --parallel --group <X>
# Anything else is treated as an extra hydra override and forwarded to
# scripts/train_cta_ablation_diffusion.sh -> python3 src/train.py.
# Examples:
# bash scripts/run_all_ablations_diffusion.sh trainer.max_epochs=3
# bash scripts/run_all_ablations_diffusion.sh --group A method.classifier.dropout=0.5
PARALLEL=false
GROUP=""
EXTRA_HYDRA=()
while [[ $# -gt 0 ]]; do
case "$1" in
--parallel) PARALLEL=true; shift ;;
--group) GROUP="$2"; shift 2 ;;
# Anything that looks like a hydra override (has '=') -> forward
*=*) EXTRA_HYDRA+=("$1"); shift ;;
*) echo "Unknown arg: $1"; exit 1 ;;
esac
done
# ---- define all variants (mirror of run_all_ablations.sh) ------------------
declare -A GROUP_VARIANTS
GROUP_VARIANTS[A]="A1_full A2_no_asym A3_no_ltotal A4_asym_only A5_pooled_only"
GROUP_VARIANTS[B]="B1_real_only B2_all_samples B3_no_predictor"
GROUP_VARIANTS[C]="C1_no_loss_asym C2_no_loss_aux C3_no_loss_av C4_no_loss_va C5_no_detach"
GROUP_VARIANTS[D]="D1_depth_1 D2_depth_4 D3_depth_8 D4_mlp_predictor D5_shared_predictor"
GROUP_VARIANTS[E]="E1_video_freeze_0 E2_video_freeze_07 E3_video_freeze_10"
GROUP_VARIANTS[F]="F1_audio_freeze_0 F2_audio_freeze_08"
GROUP_VARIANTS[G]="G2_random_crop"
GROUP_VARIANTS[M]="M1_video_only M2_audio_only M3_intra_modal M4_noise_target M5_shuffle_pair M6_drop_audio_infer M7_drop_video_infer"
if [[ -n "$GROUP" ]]; then
if [[ -z "${GROUP_VARIANTS[$GROUP]+_}" ]]; then
echo "[ablation-diffusion] Unknown group: $GROUP. Valid groups: A B C D E F G M"
exit 1
fi
VARIANTS="${GROUP_VARIANTS[$GROUP]}"
else
VARIANTS=""
for g in A B C D E F G M; do
VARIANTS="$VARIANTS ${GROUP_VARIANTS[$g]}"
done
fi
echo "============================================================"
echo "[ablation-diffusion] Variants to run:"
for v in $VARIANTS; do echo " - $v"; done
echo "[ablation-diffusion] Output dirs: outputs/cta_ablation_diffusion_<V>_<TS>/"
if [[ ${#EXTRA_HYDRA[@]} -gt 0 ]]; then
echo "[ablation-diffusion] Extra hydra overrides forwarded to each variant:"
for o in "${EXTRA_HYDRA[@]}"; do echo " $o"; done
fi
echo "============================================================"
# Serialize EXTRA_HYDRA into a single string we can pass to the function
# (exported bash functions cannot reference outer arrays directly).
EXTRA_HYDRA_STR="${EXTRA_HYDRA[*]}"
export EXTRA_HYDRA_STR
run_variant() {
local variant="$1"
echo ""
echo "============================================================"
echo "[ablation-diffusion] START: $variant ($(date '+%Y-%m-%d %H:%M:%S'))"
echo "============================================================"
# Re-split EXTRA_HYDRA_STR on whitespace so each override stays a separate
# arg to the train script.
local extra_args=()
if [[ -n "$EXTRA_HYDRA_STR" ]]; then
# shellcheck disable=SC2206
extra_args=( $EXTRA_HYDRA_STR )
fi
bash scripts/train_cta_ablation_diffusion.sh "$variant" "${extra_args[@]}"
echo "[ablation-diffusion] DONE: $variant ($(date '+%Y-%m-%d %H:%M:%S'))"
}
export -f run_variant
if $PARALLEL; then
echo "[ablation-diffusion] Running in PARALLEL mode (requires GNU parallel)"
echo "$VARIANTS" | tr ' ' '\n' | grep -v '^$' | \
parallel --jobs 4 --line-buffer run_variant {}
else
for variant in $VARIANTS; do
run_variant "$variant"
done
fi
echo ""
echo "============================================================"
echo "[ablation-diffusion] All variants finished."
echo "[ablation-diffusion] Next: bash scripts/batch_test_cta_ablation_diffusion.sh"
echo "============================================================"