SADAE / scripts /run_nf_mask_single_layer_ablation.sh
Lingmin-Ran's picture
Upload SADAE source snapshot (82ceb4d)
2cf4a54 verified
Raw History Blame Contribute Delete
2.84 kB
#!/usr/bin/env bash
set -uo pipefail
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
cat <<'USAGE'
Compare masks from one NF block at a time, without averaging across blocks.
Default: forward input states h5 through h0, each with thresholds 0.1 to 0.5.
Environment overrides (lists are space separated):
NF_MASK_SINGLE_OUTPUT_ROOT New root (default: result/nf_mask_single_layer_ablation)
NF_MASK_LAYERS Zero-based forward block indices (default: 5 4 3 2 1 0)
NF_MASK_STATES input / output (default: input)
NF_MASK_THRESHOLDS Thresholds (default: 0.1 0.2 0.3 0.4 0.5)
NF_MASK_NOISE_MODES clean / training_noise (default: training_noise)
NF_ABLATION_CATEGORY, NF_ABLATION_MAX_SAMPLES, NF_ABLATION_SEED
Defaults: 0_random_140, 4, 999
CUDA_VISIBLE_DEVICES GPU selection (default: 0)
Example: use only the h4 input-state difference and sweep all five thresholds:
NF_MASK_LAYERS=4 NF_MASK_SINGLE_OUTPUT_ROOT=result/nf_mask_single_h4 \
bash scripts/run_nf_mask_single_layer_ablation.sh
USAGE
exit 0
fi
cd "$(dirname "$0")/.."
experiment_root="${NF_MASK_SINGLE_OUTPUT_ROOT:-result/nf_mask_single_layer_ablation}"
if [[ -e "$experiment_root" ]]; then
printf 'Choose a new NF_MASK_SINGLE_OUTPUT_ROOT: %s\n' "$experiment_root" >&2
exit 1
fi
source /mnt/bn/jiangzhongtao/miniconda3/etc/profile.d/conda.sh
conda activate pvd
export HF_HUB_CACHE="$PWD/ckpts/hf_cache"
export HF_HUB_OFFLINE=1
export TRANSFORMERS_OFFLINE=1
export CUDA_VISIBLE_DEVICES="${CUDA_VISIBLE_DEVICES:-0}"
read -r -a modes <<< "${NF_MASK_NOISE_MODES:-training_noise}"
read -r -a layers <<< "${NF_MASK_LAYERS:-5 4 3 2 1 0}"
read -r -a states <<< "${NF_MASK_STATES:-input}"
read -r -a thresholds <<< "${NF_MASK_THRESHOLDS:-0.2 0.4 0.6 0.8}"
common=(--category "${NF_ABLATION_CATEGORY:-0_random_140}"
--max-samples "${NF_ABLATION_MAX_SAMPLES:-4}" --seed "${NF_ABLATION_SEED:-999}")
mkdir -p "$experiment_root"
for mode in "${modes[@]}"; do
noise_args=()
case "$mode" in
clean) ;;
training_noise) noise_args=(--training-noise) ;;
*) printf 'Unknown noise mode: %s\n' "$mode" >&2; exit 1 ;;
esac
for state in "${states[@]}"; do
for layer in "${layers[@]}"; do
group="$experiment_root/$mode/${state}_block${layer}"
mkdir -p "$group"
for threshold in "${thresholds[@]}"; do
python -u scripts/nf_local_affine_guidance_editing.py "${common[@]}" "${noise_args[@]}" \
--vae-latent mean --mask-method inverse_change --guidance 3.6 \
--mask-depth 1 --mask-layer "$layer" --mask-state "$state" --mask-threshold "$threshold" \
--output-dir "$group/threshold_$threshold" \
2>&1 | tee "$group/threshold_$threshold.log"
done
done
done
done
bash /mnt/bn/jiangzhongtao/lingmin/ml-starflow/scripts/zhanka.sh