#!/usr/bin/env bash set -euo pipefail # One-GPU ablation queue (default GPU1). # This script runs experiments sequentially and stores all artifacts under: # results/ablation_study/ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT_DIR" GPU_ID="${GPU_ID:-1}" EPOCHS_ABL="${EPOCHS_ABL:-5}" MAX_SAMPLES="${MAX_SAMPLES:-10000}" TOPK="${TOPK:-30}" ABL_ROOT="results/ablation_study" CKPT_DIR="$ABL_ROOT/checkpoints" RUN_DIR="$ABL_ROOT/runs" LOG_DIR="$ABL_ROOT/logs" mkdir -p "$CKPT_DIR" "$RUN_DIR" "$LOG_DIR" run() { local name="$1" shift echo echo "============================================================" echo "[$(date '+%F %T')] START: $name" echo "CMD: $*" echo "============================================================" "$@" echo "[$(date '+%F %T')] DONE: $name" } export PYTHONPATH=. # 0) Figure-2 continuation: resume mix_d2c to epoch20 (if possible) if [[ -f checkpoints/optical_mix_d2c/latest.pt ]]; then run "figure2_resume_to_e20" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/train_compressor.py \ --output_dir checkpoints/optical_mix_d2c \ --resume checkpoints/optical_mix_d2c/latest.pt \ --epochs 20 \ --max_samples "$MAX_SAMPLES" \ --mix_root data \ --mix_images_subdir ref_screenshots \ --mix_gt_subdir gt_html \ --max_html_tokens 8192 \ --eval_after_epoch \ --eval_output_dir results/clip_per_epoch/optical_mix_d2c \ --eval_clip_device cuda fi # 1) Remove LoRA ablation run "train_no_lora_256" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/train_compressor.py \ --output_dir "$CKPT_DIR/no_lora_256" \ --disable_lora \ --target_tokens 256 \ --epochs "$EPOCHS_ABL" \ --max_samples "$MAX_SAMPLES" \ --mix_root data \ --mix_images_subdir ref_screenshots \ --mix_gt_subdir gt_html \ --max_html_tokens 8192 run "eval_no_lora_256" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/eval_all.py \ --method uipress \ --checkpoint "$CKPT_DIR/no_lora_256/latest.pt" \ --target_tokens 256 \ --max_samples 50 \ --data_dir data \ --output_dir "$RUN_DIR/no_lora_256" run "clip_no_lora_256" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/step_clip_batch.py \ --method_dir "$RUN_DIR/no_lora_256/uipress_256" \ --ref_dir data/ref_screenshots \ --clip_device cuda # 2) Token sensitivity ablation for tok in 64 128 512; do run "train_token_${tok}" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/train_compressor.py \ --output_dir "$CKPT_DIR/token_${tok}" \ --target_tokens "$tok" \ --epochs "$EPOCHS_ABL" \ --max_samples "$MAX_SAMPLES" \ --mix_root data \ --mix_images_subdir ref_screenshots \ --mix_gt_subdir gt_html \ --max_html_tokens 8192 run "eval_token_${tok}" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/eval_all.py \ --method uipress \ --checkpoint "$CKPT_DIR/token_${tok}/latest.pt" \ --target_tokens "$tok" \ --max_samples 50 \ --data_dir data \ --output_dir "$RUN_DIR/token_${tok}" run "clip_token_${tok}" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/step_clip_batch.py \ --method_dir "$RUN_DIR/token_${tok}/uipress_${tok}" \ --ref_dir data/ref_screenshots \ --clip_device cuda done # 3) Learning-rate scan (compressor lr) for lr in 1e-4 2e-4 4e-4; do safe_lr="${lr//./p}" run "train_lr_${safe_lr}" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/train_compressor.py \ --output_dir "$CKPT_DIR/lr_${safe_lr}" \ --target_tokens 256 \ --lr_compressor "$lr" \ --epochs "$EPOCHS_ABL" \ --max_samples "$MAX_SAMPLES" \ --mix_root data \ --mix_images_subdir ref_screenshots \ --mix_gt_subdir gt_html \ --max_html_tokens 8192 run "eval_lr_${safe_lr}" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/eval_all.py \ --method uipress \ --checkpoint "$CKPT_DIR/lr_${safe_lr}/latest.pt" \ --target_tokens 256 \ --max_samples 50 \ --data_dir data \ --output_dir "$RUN_DIR/lr_${safe_lr}" run "clip_lr_${safe_lr}" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/step_clip_batch.py \ --method_dir "$RUN_DIR/lr_${safe_lr}/uipress_256" \ --ref_dir data/ref_screenshots \ --clip_device cuda done # 4) Cross-domain validation (WebSight screenshots as eval set) TMP_WEBSIGHT_DIR="$ABL_ROOT/tmp_websight_eval" mkdir -p "$TMP_WEBSIGHT_DIR" if [[ ! -e "$TMP_WEBSIGHT_DIR/ref_screenshots" ]]; then ln -s "$(realpath data/ref_screenshots_websight)" "$TMP_WEBSIGHT_DIR/ref_screenshots" fi run "cross_domain_qwen3_full" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/eval_all.py \ --method baseline \ --max_samples 50 \ --data_dir "$TMP_WEBSIGHT_DIR" \ --output_dir "$RUN_DIR/cross_domain" run "cross_domain_uipress_latest" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/eval_all.py \ --method uipress \ --checkpoint checkpoints/optical_mix_d2c/latest.pt \ --target_tokens 256 \ --max_samples 50 \ --data_dir "$TMP_WEBSIGHT_DIR" \ --output_dir "$RUN_DIR/cross_domain" run "cross_domain_clip_qwen3_full" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/step_clip_batch.py \ --method_dir "$RUN_DIR/cross_domain/qwen3_full" \ --ref_dir data/ref_screenshots_websight \ --clip_device cuda run "cross_domain_clip_uipress_256" \ env CUDA_VISIBLE_DEVICES="$GPU_ID" python scripts/step_clip_batch.py \ --method_dir "$RUN_DIR/cross_domain/uipress_256" \ --ref_dir data/ref_screenshots_websight \ --clip_device cuda # 5) Build Top-K report from current available methods run "build_topk_report" \ python scripts/ablation_topk_report.py \ --topk "$TOPK" \ --out_root "$ABL_ROOT" echo echo "All queue steps completed at $(date '+%F %T')."