File size: 5,915 Bytes
fbc94ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/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')."