Add files using upload-large-folder tool
Browse files- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/eval_attnbias_sam.py +0 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_ablation_grid.sh +77 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_ablation_grid_layer.sh +120 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_ablation_grid_layer_worker.sh +144 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_ablation_grid_worker.sh +116 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_all_attnbias_sam.sh +36 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval.sh +19 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_both.sh +45 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_both_amplify_only.sh +52 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_both_noauction.sh +42 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_both_random.sh +51 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_both_suppress_only.sh +53 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_none.sh +40 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_text.sh +38 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_vis.sh +42 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis3.0/HuatuoGPT-Vision-7B_medical_multimodel_evaluation_data_both_Lt17_kt3.0_nt0.0_Lv17_kv3.0_nv0.0.json +0 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis3.0/HuatuoGPT-Vision-7B_medical_multimodel_evaluation_data_both_Lt17_kt3.0_nt0.0_Lv17_kv3.0_nv0.0_result.json +22 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis3.0/_snapshot/run_ablation_grid_layer_worker.sh +144 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis3.0/_snapshot/run_ablation_grid_pick.sh +68 -0
- HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis3.0/_snapshot/run_eval_attnbias_sam_both.sh +45 -0
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/eval_attnbias_sam.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_ablation_grid.sh
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
# Full grid search over (strength_text, strength_vis) for the "both"
|
| 5 |
+
# intervention mode WITH Budgeted Token Auction enabled, split across GPU 0
|
| 6 |
+
# and GPU 2 and run concurrently via run_ablation_grid_worker.sh (GPU 1/3 are
|
| 7 |
+
# occupied by other people's jobs on this workstation, so 0/2 are used
|
| 8 |
+
# instead of the usual 0/1 -- see run_eval.sh for the same reasoning). The bias
|
| 9 |
+
# layer is fixed at 17 for both modalities; text and vis each get their own
|
| 10 |
+
# strength sweep and every (strength_text, strength_vis) combination is run --
|
| 11 |
+
# kbt=nbt=-s_text, kbv=nbv=-s_vis for s_text in STRENGTHS_TEXT, s_vis in
|
| 12 |
+
# STRENGTHS_VIS. Stage1/SAM results are cached in eval_attnbias_sam.py (keyed
|
| 13 |
+
# on data_path/model_path/seed, see HuatuoGPT-Vision/cache/sam_stage1_cache/)
|
| 14 |
+
# and are independent of the bias layer/strength/auction args, so re-running
|
| 15 |
+
# a combo only re-pays the much cheaper bias-intervention generation pass.
|
| 16 |
+
# Auction budgets/alpha/beta are fixed at their defaults here -- this script
|
| 17 |
+
# only sweeps bias strength, not the auction hyperparameters themselves.
|
| 18 |
+
# Each combo writes to its own output dir under results_attnbias_ablation/, so
|
| 19 |
+
# this never touches results_attnbias/HuatuoGPT-Vision-7B/sam_both or any other
|
| 20 |
+
# previously saved result.
|
| 21 |
+
#
|
| 22 |
+
# NOTE: picking the best (s_text, s_vis) and syncing it into every
|
| 23 |
+
# run_eval_attnbias_sam_*.sh needs the WHOLE grid scored first, so it is
|
| 24 |
+
# NOT done here -- run ./run_ablation_grid_pick.sh by hand once this script
|
| 25 |
+
# (both GPU workers) finishes. STRENGTHS_TEXT/STRENGTHS_VIS/LAYER are defined
|
| 26 |
+
# independently in run_ablation_grid_worker.sh and run_ablation_grid_pick.sh;
|
| 27 |
+
# keep all three in sync if you change the grid.
|
| 28 |
+
#
|
| 29 |
+
# Pass 0 (keyword/Stage1/SAM extraction) in eval_attnbias_sam.py caches its
|
| 30 |
+
# output keyed only on (data_path, model_path, seed) -- every combo in this
|
| 31 |
+
# grid shares the exact same key, so both GPU workers would hit the *same*
|
| 32 |
+
# cache file. accelerator.wait_for_everyone() only synchronizes ranks within
|
| 33 |
+
# one `accelerate launch` process group; GPU0's and GPU2's workers are two
|
| 34 |
+
# fully independent processes with no cross-process coordination, so if both
|
| 35 |
+
# ran Pass 0 concurrently on a cold cache they'd race to read-modify-write the
|
| 36 |
+
# same JSON file (worst case: interleaved writes corrupt it; typical case:
|
| 37 |
+
# whichever finishes last silently clobbers the other's freshly-computed
|
| 38 |
+
# entries with the stale snapshot it read at startup) and both would
|
| 39 |
+
# redundantly re-run the expensive Stage1+SAM pass over the whole dataset.
|
| 40 |
+
# Fix: run ONE combo alone first (GPU 0, combo index 0) to fully populate the
|
| 41 |
+
# cache -- Pass 0 always covers the whole dataset regardless of which combo is
|
| 42 |
+
# running, so after this single warmup run every subsequent Pass 0 (on either
|
| 43 |
+
# GPU) is a pure cache hit and never writes to the file, making the parallel
|
| 44 |
+
# phase below race-free.
|
| 45 |
+
set -e
|
| 46 |
+
|
| 47 |
+
echo "[ablation-grid] warmup: running combo 0 alone on GPU 0 to populate the Pass0 cache before parallelizing"
|
| 48 |
+
./run_ablation_grid_worker.sh 0 0 1 > ablation_grid_warmup.log 2>&1
|
| 49 |
+
echo "[ablation-grid] warmup done (log: ablation_grid_warmup.log)"
|
| 50 |
+
|
| 51 |
+
TOTAL=25 # len(STRENGTHS_TEXT) * len(STRENGTHS_VIS), see run_ablation_grid_worker.sh
|
| 52 |
+
SPLIT=13 # combos [1, SPLIT) -> GPU 0, combos [SPLIT, TOTAL) -> GPU 2
|
| 53 |
+
# combo 0 already ran during warmup above -- GPU0's parallel slice starts at
|
| 54 |
+
# index 1 (not 0) so it isn't touched again at all, not even via the
|
| 55 |
+
# OUTPUT_PATH-exists skip check.
|
| 56 |
+
|
| 57 |
+
echo "[ablation-grid] launching GPU 0 on combos [1, $SPLIT) and GPU 2 on combos [$SPLIT, $TOTAL) in parallel"
|
| 58 |
+
|
| 59 |
+
./run_ablation_grid_worker.sh 0 1 $((SPLIT - 1)) > ablation_grid_gpu0.log 2>&1 &
|
| 60 |
+
PID0=$!
|
| 61 |
+
./run_ablation_grid_worker.sh 2 "$SPLIT" $((TOTAL - SPLIT)) > ablation_grid_gpu2.log 2>&1 &
|
| 62 |
+
PID1=$!
|
| 63 |
+
|
| 64 |
+
echo "[ablation-grid] gpu0 worker pid=$PID0 (log: ablation_grid_gpu0.log), gpu2 worker pid=$PID1 (log: ablation_grid_gpu2.log)"
|
| 65 |
+
|
| 66 |
+
wait "$PID0"
|
| 67 |
+
STATUS0=$?
|
| 68 |
+
wait "$PID1"
|
| 69 |
+
STATUS1=$?
|
| 70 |
+
|
| 71 |
+
if [ "$STATUS0" -ne 0 ] || [ "$STATUS1" -ne 0 ]; then
|
| 72 |
+
echo "[ablation-grid] a worker failed (gpu0 exit=$STATUS0, gpu2 exit=$STATUS1) -- check ablation_grid_gpu{0,2}.log before running run_ablation_grid_pick.sh" >&2
|
| 73 |
+
exit 1
|
| 74 |
+
fi
|
| 75 |
+
|
| 76 |
+
echo "[ablation-grid] both workers finished, all $TOTAL combinations done"
|
| 77 |
+
echo "[ablation-grid] now run: ./run_ablation_grid_pick.sh"
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_ablation_grid_layer.sh
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
# Stage 2 of the two-stage greedy ablation search: run_ablation_grid.sh (+
|
| 5 |
+
# optionally run_ablation_grid_pick.sh) already found the best (s_text, s_vis)
|
| 6 |
+
# with the bias layer fixed at 17, and a first pass already tested
|
| 7 |
+
# LAYERS=(3 10 17 24 27) serially. This script covers the remaining 23 layers
|
| 8 |
+
# (the model has 28 total, indices 0-27, confirmed via
|
| 9 |
+
# PretrainedConfig.get_config_dict(...)['num_hidden_layers'] == 28) by
|
| 10 |
+
# splitting them across GPU 0 and GPU 2 via run_ablation_grid_layer_worker.sh
|
| 11 |
+
# (GPU 1/3 are occupied by other people's jobs on this workstation, so 0/2 are
|
| 12 |
+
# used instead of the usual 0/1), running concurrently -- no cache-warmup step first (see
|
| 13 |
+
# run_ablation_grid_layer_worker.sh's header for why that's safe here: the
|
| 14 |
+
# Pass0 cache should already be fully warm from every prior run in this repo
|
| 15 |
+
# sharing the same data_path/model_path/seed).
|
| 16 |
+
#
|
| 17 |
+
# After both workers finish, this script picks the best layer across ALL 28
|
| 18 |
+
# (the original 5 + these 23), fixed at the same winning (s_text, s_vis), and
|
| 19 |
+
# syncs the final (layer, s_text, s_vis) into every run_eval_attnbias_sam_*.sh.
|
| 20 |
+
#
|
| 21 |
+
# FINAL METHOD = run_eval_attnbias_sam_both.sh: nonkey_bias is
|
| 22 |
+
# pinned at 0 (amplify_only) and the auction mechanism is OFF for this whole
|
| 23 |
+
# search, matching run_ablation_grid_worker.sh/run_ablation_grid_layer_worker.sh.
|
| 24 |
+
set -e
|
| 25 |
+
|
| 26 |
+
TOTAL=23 # len(LAYERS_REMAINING), see run_ablation_grid_layer_worker.sh
|
| 27 |
+
SPLIT=12 # indices [0, SPLIT) -> GPU 0, indices [SPLIT, TOTAL) -> GPU 2
|
| 28 |
+
|
| 29 |
+
echo "[ablation-grid-layer] launching GPU 0 on layer-indices [0, $SPLIT) and GPU 2 on [$SPLIT, $TOTAL) in parallel (no warmup)"
|
| 30 |
+
|
| 31 |
+
./run_ablation_grid_layer_worker.sh 0 0 "$SPLIT" > ablation_grid_layer_gpu0.log 2>&1 &
|
| 32 |
+
PID0=$!
|
| 33 |
+
./run_ablation_grid_layer_worker.sh 2 "$SPLIT" $((TOTAL - SPLIT)) > ablation_grid_layer_gpu2.log 2>&1 &
|
| 34 |
+
PID1=$!
|
| 35 |
+
|
| 36 |
+
echo "[ablation-grid-layer] gpu0 worker pid=$PID0 (log: ablation_grid_layer_gpu0.log), gpu2 worker pid=$PID1 (log: ablation_grid_layer_gpu2.log)"
|
| 37 |
+
|
| 38 |
+
wait "$PID0"
|
| 39 |
+
STATUS0=$?
|
| 40 |
+
wait "$PID1"
|
| 41 |
+
STATUS1=$?
|
| 42 |
+
|
| 43 |
+
if [ "$STATUS0" -ne 0 ] || [ "$STATUS1" -ne 0 ]; then
|
| 44 |
+
echo "[ablation-grid-layer] a worker failed (gpu0 exit=$STATUS0, gpu2 exit=$STATUS1) -- check ablation_grid_layer_gpu{0,2}.log" >&2
|
| 45 |
+
exit 1
|
| 46 |
+
fi
|
| 47 |
+
|
| 48 |
+
echo "[ablation-grid-layer] both workers finished, all $TOTAL remaining layers done"
|
| 49 |
+
|
| 50 |
+
source /home/jinhua/miniconda3/etc/profile.d/conda.sh
|
| 51 |
+
conda activate huatuovision
|
| 52 |
+
|
| 53 |
+
STAGE1_LAYER=17
|
| 54 |
+
STRENGTHS_TEXT=(1.0 2.0 3.0 4.0 5.0)
|
| 55 |
+
STRENGTHS_VIS=(1.0 2.0 3.0 4.0 5.0)
|
| 56 |
+
# every layer the model has been tested at: the original 5-point sweep plus
|
| 57 |
+
# the 23 "remaining" layers this script just ran.
|
| 58 |
+
LAYERS_ALL=(0 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)
|
| 59 |
+
|
| 60 |
+
# ── re-derive the winning (s_text, s_vis) directly from the strength grid's
|
| 61 |
+
# result files, same scan-and-compare as run_ablation_grid_pick.sh.
|
| 62 |
+
echo "[ablation-grid-layer] re-scanning the strength grid's results to find the winning (s_text, s_vis)..."
|
| 63 |
+
S_TEXT=""
|
| 64 |
+
S_VIS=""
|
| 65 |
+
STAGE1_BEST_SCORE=""
|
| 66 |
+
for ST in "${STRENGTHS_TEXT[@]}"; do
|
| 67 |
+
for SV in "${STRENGTHS_VIS[@]}"; do
|
| 68 |
+
STAGE1_OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${STAGE1_LAYER}_stext${ST}_svis${SV}"
|
| 69 |
+
STAGE1_RESULT_F=$(ls "$STAGE1_OUTPUT_PATH"/*_result.json 2>/dev/null | head -n1)
|
| 70 |
+
if [ -z "$STAGE1_RESULT_F" ]; then
|
| 71 |
+
echo "[ablation-grid-layer] missing *_result.json under $STAGE1_OUTPUT_PATH -- has the strength grid finished?" >&2
|
| 72 |
+
exit 1
|
| 73 |
+
fi
|
| 74 |
+
STAGE1_SCORE=$(python -c "
|
| 75 |
+
import json
|
| 76 |
+
with open('$STAGE1_RESULT_F') as f:
|
| 77 |
+
d = json.load(f)
|
| 78 |
+
print(d['The total score for multiple-choice questions'])
|
| 79 |
+
")
|
| 80 |
+
if [ -z "$STAGE1_BEST_SCORE" ] || python -c "exit(0 if $STAGE1_SCORE > $STAGE1_BEST_SCORE else 1)"; then
|
| 81 |
+
STAGE1_BEST_SCORE="$STAGE1_SCORE"
|
| 82 |
+
S_TEXT="$ST"
|
| 83 |
+
S_VIS="$SV"
|
| 84 |
+
fi
|
| 85 |
+
done
|
| 86 |
+
done
|
| 87 |
+
echo "[ablation-grid-layer] strength winner: s_text=$S_TEXT s_vis=$S_VIS (score=$STAGE1_BEST_SCORE)"
|
| 88 |
+
|
| 89 |
+
# ── pick the best layer across all 28, strength fixed at (S_TEXT, S_VIS).
|
| 90 |
+
BEST_LAYER=""
|
| 91 |
+
BEST_SCORE=""
|
| 92 |
+
for LAYER in "${LAYERS_ALL[@]}"; do
|
| 93 |
+
OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${LAYER}_stext${S_TEXT}_svis${S_VIS}"
|
| 94 |
+
RESULT_F=$(ls "$OUTPUT_PATH"/*_result.json 2>/dev/null | head -n1)
|
| 95 |
+
if [ -z "$RESULT_F" ]; then
|
| 96 |
+
echo "[ablation-grid-layer] missing *_result.json under $OUTPUT_PATH -- cannot pick best layer (layer=$LAYER not yet run)" >&2
|
| 97 |
+
exit 1
|
| 98 |
+
fi
|
| 99 |
+
SCORE=$(python -c "
|
| 100 |
+
import json
|
| 101 |
+
with open('$RESULT_F') as f:
|
| 102 |
+
d = json.load(f)
|
| 103 |
+
print(d['The total score for multiple-choice questions'])
|
| 104 |
+
")
|
| 105 |
+
echo "[ablation-grid-layer] layer=$LAYER score=$SCORE"
|
| 106 |
+
if [ -z "$BEST_SCORE" ] || python -c "exit(0 if $SCORE > $BEST_SCORE else 1)"; then
|
| 107 |
+
BEST_SCORE="$SCORE"
|
| 108 |
+
BEST_LAYER="$LAYER"
|
| 109 |
+
fi
|
| 110 |
+
done
|
| 111 |
+
|
| 112 |
+
echo "[ablation-grid-layer] best overall across all 28 layers: layer=$BEST_LAYER s_text=$S_TEXT s_vis=$S_VIS (score=$BEST_SCORE)"
|
| 113 |
+
echo "[ablation-grid-layer] syncing into every run_eval_attnbias_sam_*.sh via sync_attn_params.py"
|
| 114 |
+
|
| 115 |
+
python sync_attn_params.py \
|
| 116 |
+
--layers_text "$BEST_LAYER" --key_bias_text "$S_TEXT" --nonkey_bias_text "0" \
|
| 117 |
+
--layers_vis "$BEST_LAYER" --key_bias_vis "$S_VIS" --nonkey_bias_vis "0"
|
| 118 |
+
|
| 119 |
+
echo "[ablation-grid-layer] done. All run_eval_attnbias_sam_*.sh now use the ablation-selected layer/strength (nonkey_bias=0, amplify_only style)"
|
| 120 |
+
echo "[ablation-grid-layer] (amplify_only keeps its pinned-zero side; text.sh/vis.sh keep their single-modality side -- see sync_attn_params.py)."
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_ablation_grid_layer_worker.sh
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
# Runs a contiguous slice of the "remaining layers" sweep (the 23 layers NOT
|
| 5 |
+
# already covered by the original LAYERS=(3 10 17 24 27) test) on a single
|
| 6 |
+
# GPU, so the full sweep can be split across GPU 0 and GPU 2 and run
|
| 7 |
+
# concurrently (GPU 1/3 are occupied by other jobs on this workstation) --
|
| 8 |
+
# same pattern as run_ablation_grid_worker.sh for the strength grid, but for
|
| 9 |
+
# layers.
|
| 10 |
+
#
|
| 11 |
+
# NO cache-warmup step here (unlike run_ablation_grid.sh's stage 1): by the
|
| 12 |
+
# time this runs, the Pass0 cache (keyed on data_path/model_path/seed, shared
|
| 13 |
+
# across every combo/script in this repo) has already been fully populated by
|
| 14 |
+
# the earlier strength grid + original 5-layer sweep + run_all_attnbias_sam.sh
|
| 15 |
+
# runs, so both GPU workers should hit pure cache reads with nothing new to
|
| 16 |
+
# write -- eliminating the write-race risk without needing a serialized
|
| 17 |
+
# warmup run first. This assumption only breaks if the cache is somehow still
|
| 18 |
+
# incomplete (e.g. an earlier run was interrupted before finishing Pass 0);
|
| 19 |
+
# if you're not confident the cache is fully warm, warm it manually first
|
| 20 |
+
# (run any single combo alone) before launching this in parallel.
|
| 21 |
+
#
|
| 22 |
+
# S_TEXT/S_VIS are re-derived from the strength grid's results (same as
|
| 23 |
+
# run_ablation_grid_layer.sh), not hand-filled.
|
| 24 |
+
#
|
| 25 |
+
# FINAL METHOD = run_eval_attnbias_sam_both.sh: nonkey_bias_text/vis
|
| 26 |
+
# are pinned at 0 (amplify_only) AND the auction mechanism is OFF, matching
|
| 27 |
+
# run_ablation_grid_worker.sh's strength grid exactly. Output dirs use the
|
| 28 |
+
# "sam_both_amplify_noauction_..." tag to match.
|
| 29 |
+
#
|
| 30 |
+
# Usage:
|
| 31 |
+
# ./run_ablation_grid_layer_worker.sh <gpu_id> <start_index> <count>
|
| 32 |
+
# Example (23 combos split 12/11 across 2 GPUs):
|
| 33 |
+
# ./run_ablation_grid_layer_worker.sh 0 0 12 &
|
| 34 |
+
# ./run_ablation_grid_layer_worker.sh 2 12 11 &
|
| 35 |
+
# wait
|
| 36 |
+
set -e
|
| 37 |
+
|
| 38 |
+
GPU_ID="$1"
|
| 39 |
+
START="$2"
|
| 40 |
+
COUNT="$3"
|
| 41 |
+
if [ -z "$GPU_ID" ] || [ -z "$START" ] || [ -z "$COUNT" ]; then
|
| 42 |
+
echo "usage: $0 <gpu_id> <start_index> <count>" >&2
|
| 43 |
+
exit 1
|
| 44 |
+
fi
|
| 45 |
+
export CUDA_VISIBLE_DEVICES="$GPU_ID"
|
| 46 |
+
|
| 47 |
+
source /home/jinhua/miniconda3/etc/profile.d/conda.sh
|
| 48 |
+
conda activate huatuovision
|
| 49 |
+
|
| 50 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 51 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 52 |
+
|
| 53 |
+
SEED=42
|
| 54 |
+
MAX_NEW_TOKENS=256
|
| 55 |
+
|
| 56 |
+
MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
|
| 57 |
+
MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
|
| 58 |
+
|
| 59 |
+
INTERVENTION="both"
|
| 60 |
+
# the 23 layers NOT in the original LAYERS=(3 10 17 24 27) test -- model has
|
| 61 |
+
# 28 layers total (indices 0-27), confirmed via
|
| 62 |
+
# PretrainedConfig.get_config_dict('FreedomIntelligence/HuatuoGPT-Vision-7B')['num_hidden_layers'] == 28.
|
| 63 |
+
# run_ablation_grid_layer.sh (the driver) does NOT keep its own copy of this
|
| 64 |
+
# array -- it only needs the total count (TOTAL=23) to split indices across
|
| 65 |
+
# GPU 0/1, plus a separate LAYERS_ALL (all 28) for the final "pick best
|
| 66 |
+
# layer" scan. If you change this array's length, update TOTAL/SPLIT in
|
| 67 |
+
# run_ablation_grid_layer.sh to match.
|
| 68 |
+
LAYERS_REMAINING=(0 1 2 4 5 6 7 8 9 11 12 13 14 15 16 18 19 20 21 22 23 25 26)
|
| 69 |
+
STAGE1_LAYER=17
|
| 70 |
+
STRENGTHS_TEXT=(1.0 2.0 3.0 4.0 5.0)
|
| 71 |
+
STRENGTHS_VIS=(1.0 2.0 3.0 4.0 5.0)
|
| 72 |
+
|
| 73 |
+
MAX_SAMPLES=""
|
| 74 |
+
|
| 75 |
+
# ── re-derive stage 1's winning (s_text, s_vis) directly from the strength
|
| 76 |
+
# grid's result files -- same scan-and-compare as run_ablation_grid_pick.sh.
|
| 77 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] re-scanning stage 1's results to find the winning (s_text, s_vis)..."
|
| 78 |
+
S_TEXT=""
|
| 79 |
+
S_VIS=""
|
| 80 |
+
STAGE1_BEST_SCORE=""
|
| 81 |
+
for ST in "${STRENGTHS_TEXT[@]}"; do
|
| 82 |
+
for SV in "${STRENGTHS_VIS[@]}"; do
|
| 83 |
+
STAGE1_OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${STAGE1_LAYER}_stext${ST}_svis${SV}"
|
| 84 |
+
STAGE1_RESULT_F=$(ls "$STAGE1_OUTPUT_PATH"/*_result.json 2>/dev/null | head -n1)
|
| 85 |
+
if [ -z "$STAGE1_RESULT_F" ]; then
|
| 86 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] missing *_result.json under $STAGE1_OUTPUT_PATH -- has the strength grid finished?" >&2
|
| 87 |
+
exit 1
|
| 88 |
+
fi
|
| 89 |
+
STAGE1_SCORE=$(python -c "
|
| 90 |
+
import json
|
| 91 |
+
with open('$STAGE1_RESULT_F') as f:
|
| 92 |
+
d = json.load(f)
|
| 93 |
+
print(d['The total score for multiple-choice questions'])
|
| 94 |
+
")
|
| 95 |
+
if [ -z "$STAGE1_BEST_SCORE" ] || python -c "exit(0 if $STAGE1_SCORE > $STAGE1_BEST_SCORE else 1)"; then
|
| 96 |
+
STAGE1_BEST_SCORE="$STAGE1_SCORE"
|
| 97 |
+
S_TEXT="$ST"
|
| 98 |
+
S_VIS="$SV"
|
| 99 |
+
fi
|
| 100 |
+
done
|
| 101 |
+
done
|
| 102 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] strength winner: s_text=$S_TEXT s_vis=$S_VIS (score=$STAGE1_BEST_SCORE) -- fixing strength at this combo for the layer sweep"
|
| 103 |
+
|
| 104 |
+
TOTAL=${#LAYERS_REMAINING[@]}
|
| 105 |
+
END=$((START + COUNT))
|
| 106 |
+
if [ "$END" -gt "$TOTAL" ]; then
|
| 107 |
+
END="$TOTAL"
|
| 108 |
+
fi
|
| 109 |
+
|
| 110 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] running layers [$START, $END) of $TOTAL total"
|
| 111 |
+
|
| 112 |
+
for ((i = START; i < END; i++)); do
|
| 113 |
+
LAYER="${LAYERS_REMAINING[$i]}"
|
| 114 |
+
OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${LAYER}_stext${S_TEXT}_svis${S_VIS}"
|
| 115 |
+
if [ -d "$OUTPUT_PATH" ]; then
|
| 116 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] $OUTPUT_PATH already exists, skipping layer=$LAYER (delete the dir manually to re-run)"
|
| 117 |
+
continue
|
| 118 |
+
fi
|
| 119 |
+
|
| 120 |
+
echo "=================================================="
|
| 121 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] idx=$i layer=$LAYER s_text=$S_TEXT s_vis=$S_VIS -> $OUTPUT_PATH"
|
| 122 |
+
echo "=================================================="
|
| 123 |
+
|
| 124 |
+
accelerate launch --num_processes=1 eval_attnbias_sam.py \
|
| 125 |
+
--data_path "$DATA_PATH" \
|
| 126 |
+
--model_path "$MODEL_PATH" \
|
| 127 |
+
--seed "$SEED" \
|
| 128 |
+
--max_new_tokens "$MAX_NEW_TOKENS" \
|
| 129 |
+
--output_path "$OUTPUT_PATH" \
|
| 130 |
+
--intervention "$INTERVENTION" \
|
| 131 |
+
--attn_layers_text "$LAYER" \
|
| 132 |
+
--attn_key_bias_text "$S_TEXT" \
|
| 133 |
+
--attn_nonkey_bias_text "0" \
|
| 134 |
+
--attn_layers_vis "$LAYER" \
|
| 135 |
+
--attn_key_bias_vis "$S_VIS" \
|
| 136 |
+
--attn_nonkey_bias_vis "0" \
|
| 137 |
+
--medsam3_config "$MEDSAM3_CONFIG" \
|
| 138 |
+
--medsam3_dir "$MEDSAM3_DIR" \
|
| 139 |
+
${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
|
| 140 |
+
|
| 141 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] idx=$i layer=$LAYER finished"
|
| 142 |
+
done
|
| 143 |
+
|
| 144 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] done with layers [$START, $END)"
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_ablation_grid_worker.sh
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
# Runs a contiguous slice of the (strength_text, strength_vis) grid on a single
|
| 5 |
+
# GPU, so the full 25-combo sweep can be split across e.g. GPU 0 and GPU 1 and
|
| 6 |
+
# run concurrently. The full pair list is built in the same fixed order
|
| 7 |
+
# (outer S_TEXT, inner S_VIS) as run_ablation_grid_pick.sh expects, so slicing
|
| 8 |
+
# it by [START, START+COUNT) here and picking over the *union* of all slices'
|
| 9 |
+
# output dirs later stays consistent -- this script does NOT do the final
|
| 10 |
+
# "pick best + sync" step, that only makes sense once every slice (on every
|
| 11 |
+
# GPU) has finished; run run_ablation_grid_pick.sh once by hand after all
|
| 12 |
+
# workers exit.
|
| 13 |
+
#
|
| 14 |
+
# FINAL METHOD = run_eval_attnbias_sam_both.sh: nonkey_bias_text/vis
|
| 15 |
+
# are pinned at 0 (amplify_only -- ablation found boosting key regions without
|
| 16 |
+
# suppressing anything else beats full boost+suppress), AND the auction
|
| 17 |
+
# mechanism is OFF (--auction_enable is not passed) -- every Stage1/SAM-detected
|
| 18 |
+
# key position gets boosted, not just an auction-selected subset. This grid
|
| 19 |
+
# searches under the SAME conditions as the final method (no auction), so the
|
| 20 |
+
# winning strength is actually calibrated for what gets used, not for a
|
| 21 |
+
# different (with-auction) config. Output dirs are tagged
|
| 22 |
+
# "sam_both_amplify_noauction_..." so they don't collide with the earlier
|
| 23 |
+
# auction-enabled grid searches' results.
|
| 24 |
+
#
|
| 25 |
+
# Usage:
|
| 26 |
+
# ./run_ablation_grid_worker.sh <gpu_id> <start_index> <count>
|
| 27 |
+
# Example (25 combos split 13/12 across 2 GPUs -- 0/2 here because GPU 1/3 are
|
| 28 |
+
# occupied by other jobs on this workstation, not the usual 0/1):
|
| 29 |
+
# CUDA_VISIBLE_DEVICES managed internally from <gpu_id> -- don't set it yourself.
|
| 30 |
+
# ./run_ablation_grid_worker.sh 0 0 13 & # combos [0, 13) on GPU 0
|
| 31 |
+
# ./run_ablation_grid_worker.sh 2 13 12 & # combos [13, 25) on GPU 2
|
| 32 |
+
# wait
|
| 33 |
+
# ./run_ablation_grid_pick.sh
|
| 34 |
+
set -e
|
| 35 |
+
|
| 36 |
+
GPU_ID="$1"
|
| 37 |
+
START="$2"
|
| 38 |
+
COUNT="$3"
|
| 39 |
+
if [ -z "$GPU_ID" ] || [ -z "$START" ] || [ -z "$COUNT" ]; then
|
| 40 |
+
echo "usage: $0 <gpu_id> <start_index> <count>" >&2
|
| 41 |
+
exit 1
|
| 42 |
+
fi
|
| 43 |
+
export CUDA_VISIBLE_DEVICES="$GPU_ID"
|
| 44 |
+
|
| 45 |
+
source /home/jinhua/miniconda3/etc/profile.d/conda.sh
|
| 46 |
+
conda activate huatuovision
|
| 47 |
+
|
| 48 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 49 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 50 |
+
|
| 51 |
+
SEED=42
|
| 52 |
+
MAX_NEW_TOKENS=256
|
| 53 |
+
|
| 54 |
+
MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
|
| 55 |
+
MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
|
| 56 |
+
|
| 57 |
+
INTERVENTION="both"
|
| 58 |
+
LAYER=17
|
| 59 |
+
# must stay identical to run_ablation_grid_pick.sh -- these define the pair
|
| 60 |
+
# ordering/indices that <start_index>/<count> slice into.
|
| 61 |
+
STRENGTHS_TEXT=(1.0 2.0 3.0 4.0 5.0)
|
| 62 |
+
STRENGTHS_VIS=(1.0 2.0 3.0 4.0 5.0)
|
| 63 |
+
|
| 64 |
+
MAX_SAMPLES=""
|
| 65 |
+
|
| 66 |
+
# flatten into "s_text s_vis" pairs, outer S_TEXT / inner S_VIS -- same order
|
| 67 |
+
# run_ablation_grid_pick.sh iterates in, so index N here means the same combo
|
| 68 |
+
# there.
|
| 69 |
+
PAIRS=()
|
| 70 |
+
for S_TEXT in "${STRENGTHS_TEXT[@]}"; do
|
| 71 |
+
for S_VIS in "${STRENGTHS_VIS[@]}"; do
|
| 72 |
+
PAIRS+=("$S_TEXT $S_VIS")
|
| 73 |
+
done
|
| 74 |
+
done
|
| 75 |
+
|
| 76 |
+
TOTAL=${#PAIRS[@]}
|
| 77 |
+
END=$((START + COUNT))
|
| 78 |
+
if [ "$END" -gt "$TOTAL" ]; then
|
| 79 |
+
END="$TOTAL"
|
| 80 |
+
fi
|
| 81 |
+
|
| 82 |
+
echo "[ablation-grid-worker gpu=$GPU_ID] running combos [$START, $END) of $TOTAL total"
|
| 83 |
+
|
| 84 |
+
for ((i = START; i < END; i++)); do
|
| 85 |
+
read -r S_TEXT S_VIS <<< "${PAIRS[$i]}"
|
| 86 |
+
OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${LAYER}_stext${S_TEXT}_svis${S_VIS}"
|
| 87 |
+
if [ -d "$OUTPUT_PATH" ]; then
|
| 88 |
+
echo "[ablation-grid-worker gpu=$GPU_ID] $OUTPUT_PATH already exists, skipping s_text=$S_TEXT s_vis=$S_VIS (delete the dir manually to re-run)"
|
| 89 |
+
continue
|
| 90 |
+
fi
|
| 91 |
+
|
| 92 |
+
echo "=================================================="
|
| 93 |
+
echo "[ablation-grid-worker gpu=$GPU_ID] idx=$i layer=$LAYER s_text=$S_TEXT s_vis=$S_VIS -> $OUTPUT_PATH"
|
| 94 |
+
echo "=================================================="
|
| 95 |
+
|
| 96 |
+
accelerate launch --num_processes=1 eval_attnbias_sam.py \
|
| 97 |
+
--data_path "$DATA_PATH" \
|
| 98 |
+
--model_path "$MODEL_PATH" \
|
| 99 |
+
--seed "$SEED" \
|
| 100 |
+
--max_new_tokens "$MAX_NEW_TOKENS" \
|
| 101 |
+
--output_path "$OUTPUT_PATH" \
|
| 102 |
+
--intervention "$INTERVENTION" \
|
| 103 |
+
--attn_layers_text "$LAYER" \
|
| 104 |
+
--attn_key_bias_text "$S_TEXT" \
|
| 105 |
+
--attn_nonkey_bias_text "0" \
|
| 106 |
+
--attn_layers_vis "$LAYER" \
|
| 107 |
+
--attn_key_bias_vis "$S_VIS" \
|
| 108 |
+
--attn_nonkey_bias_vis "0" \
|
| 109 |
+
--medsam3_config "$MEDSAM3_CONFIG" \
|
| 110 |
+
--medsam3_dir "$MEDSAM3_DIR" \
|
| 111 |
+
${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
|
| 112 |
+
|
| 113 |
+
echo "[ablation-grid-worker gpu=$GPU_ID] idx=$i s_text=$S_TEXT s_vis=$S_VIS finished"
|
| 114 |
+
done
|
| 115 |
+
|
| 116 |
+
echo "[ablation-grid-worker gpu=$GPU_ID] done with combos [$START, $END)"
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_all_attnbias_sam.sh
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
# 先跑 baseline(无干预的 eval.py),再依次跑完对比组:
|
| 5 |
+
# none(无attention干预)/ both(正式配置:全量放大关键区域,不开拍卖)/
|
| 6 |
+
# text / vis(单模态消融)/ both_random(真实位置 vs 随机位置消融)
|
| 7 |
+
# run_eval_attnbias_sam_both_noauction.sh 内容跟正式配置both.sh完全一样(both.sh
|
| 8 |
+
# 本身已经改成不开拍卖了),文件保留但不再放进这个清单,避免重复跑同一件事。
|
| 9 |
+
# 任意一个失败就停止,避免在错误的环境下继续浪费时间
|
| 10 |
+
set -e
|
| 11 |
+
|
| 12 |
+
# 默认使用 huatuovision conda 环境,不依赖调用者当前激活的环境。
|
| 13 |
+
# source profile.d/conda.sh是必须的:非交互式shell(setsid/nohup这类后台
|
| 14 |
+
# 启动方式)不会自动加载~/.bashrc,conda activate这个shell函数不会被定义,
|
| 15 |
+
# 必须显式source这个脚本才能在当前shell里用conda activate。
|
| 16 |
+
source /home/jinhua/miniconda3/etc/profile.d/conda.sh
|
| 17 |
+
conda activate huatuovision
|
| 18 |
+
|
| 19 |
+
SCRIPTS=(
|
| 20 |
+
"run_eval.sh"
|
| 21 |
+
"run_eval_attnbias_sam_none.sh"
|
| 22 |
+
"run_eval_attnbias_sam_both.sh"
|
| 23 |
+
"run_eval_attnbias_sam_text.sh"
|
| 24 |
+
"run_eval_attnbias_sam_vis.sh"
|
| 25 |
+
"run_eval_attnbias_sam_both_random.sh"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
for script in "${SCRIPTS[@]}"; do
|
| 29 |
+
echo "=================================================="
|
| 30 |
+
echo "[run_all] 开始运行 $script"
|
| 31 |
+
echo "=================================================="
|
| 32 |
+
bash "$script"
|
| 33 |
+
echo "[run_all] $script 运行完成"
|
| 34 |
+
done
|
| 35 |
+
|
| 36 |
+
echo "[run_all] 全部干预模式运行完成"
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
|
| 7 |
+
SEED=42
|
| 8 |
+
MAX_NEW_TOKENS=256
|
| 9 |
+
|
| 10 |
+
# 单卡跑,卡1/卡3被其他任务占用(其他人的进程),显式锁定卡0(确认空闲的卡)。
|
| 11 |
+
# Single GPU -- pin to GPU 0 explicitly (confirmed free; GPU 1/3 are occupied
|
| 12 |
+
# by other jobs on this workstation).
|
| 13 |
+
export CUDA_VISIBLE_DEVICES=0
|
| 14 |
+
|
| 15 |
+
accelerate launch --num_processes=1 eval.py \
|
| 16 |
+
--data_path "$DATA_PATH" \
|
| 17 |
+
--model_path "$MODEL_PATH" \
|
| 18 |
+
--seed "$SEED" \
|
| 19 |
+
--max_new_tokens "$MAX_NEW_TOKENS"
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_both.sh
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_both"
|
| 7 |
+
|
| 8 |
+
SEED=42
|
| 9 |
+
MAX_NEW_TOKENS=256
|
| 10 |
+
|
| 11 |
+
MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
|
| 12 |
+
MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
|
| 13 |
+
|
| 14 |
+
# FINAL METHOD: both mode, amplify-only (nonkey_bias pinned at 0 -- boost key
|
| 15 |
+
# regions, don't suppress anything else) and auction OFF -- every Stage1/SAM-
|
| 16 |
+
# detected key position gets boosted directly, not just an auction-selected
|
| 17 |
+
# subset (ablation found the auction mechanism doesn't help over this simpler
|
| 18 |
+
# design; see run_eval_attnbias_sam_both_noauction.sh, kept around for
|
| 19 |
+
# reference but no longer part of the active comparison set).
|
| 20 |
+
INTERVENTION="both"
|
| 21 |
+
ATTN_LAYERS_TEXT=17
|
| 22 |
+
ATTN_KEY_BIAS_TEXT=5.0
|
| 23 |
+
ATTN_NONKEY_BIAS_TEXT=0.0
|
| 24 |
+
ATTN_LAYERS_VIS=17
|
| 25 |
+
ATTN_KEY_BIAS_VIS=1.0
|
| 26 |
+
ATTN_NONKEY_BIAS_VIS=0.0
|
| 27 |
+
|
| 28 |
+
MAX_SAMPLES=""
|
| 29 |
+
|
| 30 |
+
accelerate launch --num_processes=1 eval_attnbias_sam.py \
|
| 31 |
+
--data_path "$DATA_PATH" \
|
| 32 |
+
--model_path "$MODEL_PATH" \
|
| 33 |
+
--seed "$SEED" \
|
| 34 |
+
--max_new_tokens "$MAX_NEW_TOKENS" \
|
| 35 |
+
--output_path "$OUTPUT_PATH" \
|
| 36 |
+
--intervention "$INTERVENTION" \
|
| 37 |
+
--attn_layers_text "$ATTN_LAYERS_TEXT" \
|
| 38 |
+
--attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
|
| 39 |
+
--attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
|
| 40 |
+
--attn_layers_vis "$ATTN_LAYERS_VIS" \
|
| 41 |
+
--attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
|
| 42 |
+
--attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
|
| 43 |
+
--medsam3_config "$MEDSAM3_CONFIG" \
|
| 44 |
+
--medsam3_dir "$MEDSAM3_DIR" \
|
| 45 |
+
${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_both_amplify_only.sh
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_both_amplify_only"
|
| 7 |
+
|
| 8 |
+
SEED=42
|
| 9 |
+
MAX_NEW_TOKENS=256
|
| 10 |
+
|
| 11 |
+
MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
|
| 12 |
+
MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
|
| 13 |
+
|
| 14 |
+
# Ablation: amplify-only. Key positions still get the positive bias, but
|
| 15 |
+
# nonkey_bias_* is 0 instead of negative -- isolates how much of the "both"
|
| 16 |
+
# result comes from amplifying keyword text / SAM patches, with no suppression
|
| 17 |
+
# of distractors. Auction stays ON with the same ratio/alpha/beta as
|
| 18 |
+
# run_eval_attnbias_sam_both.sh, so this differs from "both" by exactly one
|
| 19 |
+
# factor (nonkey_bias_*); compare against run_eval_attnbias_sam_both_suppress_only.sh
|
| 20 |
+
# (same setup, opposite side zeroed) and run_eval_attnbias_sam_both.sh.
|
| 21 |
+
INTERVENTION="both"
|
| 22 |
+
ATTN_LAYERS_TEXT=17
|
| 23 |
+
ATTN_KEY_BIAS_TEXT=5.0
|
| 24 |
+
ATTN_NONKEY_BIAS_TEXT=0.0
|
| 25 |
+
ATTN_LAYERS_VIS=17
|
| 26 |
+
ATTN_KEY_BIAS_VIS=1.0
|
| 27 |
+
ATTN_NONKEY_BIAS_VIS=0.0
|
| 28 |
+
|
| 29 |
+
AUCTION_TOTAL_RATIO=0.8
|
| 30 |
+
AUCTION_NEG_RATIO=0.8
|
| 31 |
+
|
| 32 |
+
MAX_SAMPLES=""
|
| 33 |
+
|
| 34 |
+
accelerate launch --num_processes=1 eval_attnbias_sam.py \
|
| 35 |
+
--data_path "$DATA_PATH" \
|
| 36 |
+
--model_path "$MODEL_PATH" \
|
| 37 |
+
--seed "$SEED" \
|
| 38 |
+
--max_new_tokens "$MAX_NEW_TOKENS" \
|
| 39 |
+
--output_path "$OUTPUT_PATH" \
|
| 40 |
+
--intervention "$INTERVENTION" \
|
| 41 |
+
--attn_layers_text "$ATTN_LAYERS_TEXT" \
|
| 42 |
+
--attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
|
| 43 |
+
--attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
|
| 44 |
+
--attn_layers_vis "$ATTN_LAYERS_VIS" \
|
| 45 |
+
--attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
|
| 46 |
+
--attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
|
| 47 |
+
--medsam3_config "$MEDSAM3_CONFIG" \
|
| 48 |
+
--medsam3_dir "$MEDSAM3_DIR" \
|
| 49 |
+
--auction_enable \
|
| 50 |
+
--auction_total_ratio "$AUCTION_TOTAL_RATIO" \
|
| 51 |
+
--auction_neg_ratio "$AUCTION_NEG_RATIO" \
|
| 52 |
+
${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_both_noauction.sh
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_both_noauction"
|
| 7 |
+
|
| 8 |
+
SEED=42
|
| 9 |
+
MAX_NEW_TOKENS=256
|
| 10 |
+
|
| 11 |
+
MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
|
| 12 |
+
MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
|
| 13 |
+
|
| 14 |
+
# both mode, auction OFF (legacy behavior): every SAM patch / scispaCy keyword
|
| 15 |
+
# gets amplified, everything else gets suppressed -- no scoring, no budget. This
|
| 16 |
+
# is the "before" half of the main ablation: none vs both-noauction vs both+auction.
|
| 17 |
+
INTERVENTION="both"
|
| 18 |
+
ATTN_LAYERS_TEXT=17
|
| 19 |
+
ATTN_KEY_BIAS_TEXT=5.0
|
| 20 |
+
ATTN_NONKEY_BIAS_TEXT=0.0
|
| 21 |
+
ATTN_LAYERS_VIS=17
|
| 22 |
+
ATTN_KEY_BIAS_VIS=1.0
|
| 23 |
+
ATTN_NONKEY_BIAS_VIS=0.0
|
| 24 |
+
|
| 25 |
+
MAX_SAMPLES=""
|
| 26 |
+
|
| 27 |
+
accelerate launch --num_processes=1 eval_attnbias_sam.py \
|
| 28 |
+
--data_path "$DATA_PATH" \
|
| 29 |
+
--model_path "$MODEL_PATH" \
|
| 30 |
+
--seed "$SEED" \
|
| 31 |
+
--max_new_tokens "$MAX_NEW_TOKENS" \
|
| 32 |
+
--output_path "$OUTPUT_PATH" \
|
| 33 |
+
--intervention "$INTERVENTION" \
|
| 34 |
+
--attn_layers_text "$ATTN_LAYERS_TEXT" \
|
| 35 |
+
--attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
|
| 36 |
+
--attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
|
| 37 |
+
--attn_layers_vis "$ATTN_LAYERS_VIS" \
|
| 38 |
+
--attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
|
| 39 |
+
--attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
|
| 40 |
+
--medsam3_config "$MEDSAM3_CONFIG" \
|
| 41 |
+
--medsam3_dir "$MEDSAM3_DIR" \
|
| 42 |
+
${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_both_random.sh
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_both_random"
|
| 7 |
+
|
| 8 |
+
SEED=42
|
| 9 |
+
MAX_NEW_TOKENS=256
|
| 10 |
+
|
| 11 |
+
MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
|
| 12 |
+
MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
|
| 13 |
+
|
| 14 |
+
# Ablation control: same "both" bias strengths/layers as
|
| 15 |
+
# run_eval_attnbias_sam_both.sh (amplify-only, auction OFF), but the scispaCy
|
| 16 |
+
# keyword positions and SAM bbox patches are each replaced
|
| 17 |
+
# (--ablation_random_text/--ablation_random_vis) with an equal-count RANDOM
|
| 18 |
+
# sample from the same candidate pool (all question text tokens / full 24x24
|
| 19 |
+
# visual grid, excluding the true key positions), seeded by $SEED for
|
| 20 |
+
# reproducibility. This differs from the final method by exactly one factor
|
| 21 |
+
# (random vs real key positions) -- tests whether gains come from biasing the
|
| 22 |
+
# *semantically correct* tokens, or merely from biasing *some* tokens of the
|
| 23 |
+
# same count. Compare this run's accuracy against run_eval_attnbias_sam_both.sh.
|
| 24 |
+
INTERVENTION="both"
|
| 25 |
+
ATTN_LAYERS_TEXT=17
|
| 26 |
+
ATTN_KEY_BIAS_TEXT=5.0
|
| 27 |
+
ATTN_NONKEY_BIAS_TEXT=0.0
|
| 28 |
+
ATTN_LAYERS_VIS=17
|
| 29 |
+
ATTN_KEY_BIAS_VIS=1.0
|
| 30 |
+
ATTN_NONKEY_BIAS_VIS=0.0
|
| 31 |
+
|
| 32 |
+
MAX_SAMPLES=""
|
| 33 |
+
|
| 34 |
+
accelerate launch --num_processes=1 eval_attnbias_sam.py \
|
| 35 |
+
--data_path "$DATA_PATH" \
|
| 36 |
+
--model_path "$MODEL_PATH" \
|
| 37 |
+
--seed "$SEED" \
|
| 38 |
+
--max_new_tokens "$MAX_NEW_TOKENS" \
|
| 39 |
+
--output_path "$OUTPUT_PATH" \
|
| 40 |
+
--intervention "$INTERVENTION" \
|
| 41 |
+
--attn_layers_text "$ATTN_LAYERS_TEXT" \
|
| 42 |
+
--attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
|
| 43 |
+
--attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
|
| 44 |
+
--attn_layers_vis "$ATTN_LAYERS_VIS" \
|
| 45 |
+
--attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
|
| 46 |
+
--attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
|
| 47 |
+
--medsam3_config "$MEDSAM3_CONFIG" \
|
| 48 |
+
--medsam3_dir "$MEDSAM3_DIR" \
|
| 49 |
+
--ablation_random_text \
|
| 50 |
+
--ablation_random_vis \
|
| 51 |
+
${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_both_suppress_only.sh
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_both_suppress_only"
|
| 7 |
+
|
| 8 |
+
SEED=42
|
| 9 |
+
MAX_NEW_TOKENS=256
|
| 10 |
+
|
| 11 |
+
MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
|
| 12 |
+
MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
|
| 13 |
+
|
| 14 |
+
# Ablation: suppress-only. nonkey_bias_* keeps the negative bias (distractors
|
| 15 |
+
# suppressed), but key_bias_* is 0 instead of positive -- isolates how much of
|
| 16 |
+
# the "both" result comes from suppressing non-keyword text / non-SAM visual
|
| 17 |
+
# patches, with no amplification of the key set. Auction stays ON with the
|
| 18 |
+
# same ratio/alpha/beta as run_eval_attnbias_sam_both.sh, so this differs from
|
| 19 |
+
# "both" by exactly one factor (key_bias_*); compare against
|
| 20 |
+
# run_eval_attnbias_sam_both_amplify_only.sh (same setup, opposite side
|
| 21 |
+
# zeroed) and run_eval_attnbias_sam_both.sh.
|
| 22 |
+
INTERVENTION="both"
|
| 23 |
+
ATTN_LAYERS_TEXT=17
|
| 24 |
+
ATTN_KEY_BIAS_TEXT=0.0
|
| 25 |
+
ATTN_NONKEY_BIAS_TEXT=-3.0
|
| 26 |
+
ATTN_LAYERS_VIS=17
|
| 27 |
+
ATTN_KEY_BIAS_VIS=0.0
|
| 28 |
+
ATTN_NONKEY_BIAS_VIS=-3.0
|
| 29 |
+
|
| 30 |
+
AUCTION_TOTAL_RATIO=0.8
|
| 31 |
+
AUCTION_NEG_RATIO=0.8
|
| 32 |
+
|
| 33 |
+
MAX_SAMPLES=""
|
| 34 |
+
|
| 35 |
+
accelerate launch --num_processes=1 eval_attnbias_sam.py \
|
| 36 |
+
--data_path "$DATA_PATH" \
|
| 37 |
+
--model_path "$MODEL_PATH" \
|
| 38 |
+
--seed "$SEED" \
|
| 39 |
+
--max_new_tokens "$MAX_NEW_TOKENS" \
|
| 40 |
+
--output_path "$OUTPUT_PATH" \
|
| 41 |
+
--intervention "$INTERVENTION" \
|
| 42 |
+
--attn_layers_text "$ATTN_LAYERS_TEXT" \
|
| 43 |
+
--attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
|
| 44 |
+
--attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
|
| 45 |
+
--attn_layers_vis "$ATTN_LAYERS_VIS" \
|
| 46 |
+
--attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
|
| 47 |
+
--attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
|
| 48 |
+
--medsam3_config "$MEDSAM3_CONFIG" \
|
| 49 |
+
--medsam3_dir "$MEDSAM3_DIR" \
|
| 50 |
+
--auction_enable \
|
| 51 |
+
--auction_total_ratio "$AUCTION_TOTAL_RATIO" \
|
| 52 |
+
--auction_neg_ratio "$AUCTION_NEG_RATIO" \
|
| 53 |
+
${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_none.sh
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_none"
|
| 7 |
+
|
| 8 |
+
SEED=42
|
| 9 |
+
MAX_NEW_TOKENS=256
|
| 10 |
+
|
| 11 |
+
MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
|
| 12 |
+
MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
|
| 13 |
+
|
| 14 |
+
# none: no attention intervention (model_output reuses plain inference result)
|
| 15 |
+
INTERVENTION="none"
|
| 16 |
+
ATTN_LAYERS_TEXT="17"
|
| 17 |
+
ATTN_KEY_BIAS_TEXT=3.0
|
| 18 |
+
ATTN_NONKEY_BIAS_TEXT=-3.0
|
| 19 |
+
ATTN_LAYERS_VIS="17"
|
| 20 |
+
ATTN_KEY_BIAS_VIS=3.0
|
| 21 |
+
ATTN_NONKEY_BIAS_VIS=-3.0
|
| 22 |
+
|
| 23 |
+
MAX_SAMPLES=""
|
| 24 |
+
|
| 25 |
+
accelerate launch --num_processes=1 eval_attnbias_sam.py \
|
| 26 |
+
--data_path "$DATA_PATH" \
|
| 27 |
+
--model_path "$MODEL_PATH" \
|
| 28 |
+
--seed "$SEED" \
|
| 29 |
+
--max_new_tokens "$MAX_NEW_TOKENS" \
|
| 30 |
+
--output_path "$OUTPUT_PATH" \
|
| 31 |
+
--intervention "$INTERVENTION" \
|
| 32 |
+
--attn_layers_text "$ATTN_LAYERS_TEXT" \
|
| 33 |
+
--attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
|
| 34 |
+
--attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
|
| 35 |
+
--attn_layers_vis "$ATTN_LAYERS_VIS" \
|
| 36 |
+
--attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
|
| 37 |
+
--attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
|
| 38 |
+
--medsam3_config "$MEDSAM3_CONFIG" \
|
| 39 |
+
--medsam3_dir "$MEDSAM3_DIR" \
|
| 40 |
+
${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_text.sh
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_text"
|
| 7 |
+
|
| 8 |
+
SEED=42
|
| 9 |
+
MAX_NEW_TOKENS=256
|
| 10 |
+
|
| 11 |
+
# Modality ablation: text-only. Only the scispaCy keyword text positions get
|
| 12 |
+
# biased (key_bias_text / nonkey_bias_text); the vis side is forced to 0 bias
|
| 13 |
+
# inside _make_attn_ctx regardless of what's passed here. SAM/MedSAM3 is
|
| 14 |
+
# skipped entirely (_needs_sam is False for "text"), so no medsam3_* args.
|
| 15 |
+
# Matches run_eval_attnbias_sam_both.sh's mechanism (amplify-only, auction
|
| 16 |
+
# OFF) so this differs from the final method by exactly one factor (modality
|
| 17 |
+
# restricted to text); compare against run_eval_attnbias_sam_vis.sh and
|
| 18 |
+
# run_eval_attnbias_sam_both.sh.
|
| 19 |
+
INTERVENTION="text"
|
| 20 |
+
ATTN_LAYERS_TEXT=17
|
| 21 |
+
ATTN_KEY_BIAS_TEXT=5.0
|
| 22 |
+
ATTN_NONKEY_BIAS_TEXT=0.0
|
| 23 |
+
ATTN_LAYERS_VIS="17"
|
| 24 |
+
|
| 25 |
+
MAX_SAMPLES=""
|
| 26 |
+
|
| 27 |
+
accelerate launch --num_processes=1 eval_attnbias_sam.py \
|
| 28 |
+
--data_path "$DATA_PATH" \
|
| 29 |
+
--model_path "$MODEL_PATH" \
|
| 30 |
+
--seed "$SEED" \
|
| 31 |
+
--max_new_tokens "$MAX_NEW_TOKENS" \
|
| 32 |
+
--output_path "$OUTPUT_PATH" \
|
| 33 |
+
--intervention "$INTERVENTION" \
|
| 34 |
+
--attn_layers_text "$ATTN_LAYERS_TEXT" \
|
| 35 |
+
--attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
|
| 36 |
+
--attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
|
| 37 |
+
--attn_layers_vis "$ATTN_LAYERS_VIS" \
|
| 38 |
+
${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis2.0/_snapshot/run_eval_attnbias_sam_vis.sh
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_vis"
|
| 7 |
+
|
| 8 |
+
SEED=42
|
| 9 |
+
MAX_NEW_TOKENS=256
|
| 10 |
+
|
| 11 |
+
MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
|
| 12 |
+
MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
|
| 13 |
+
|
| 14 |
+
# Modality ablation: vis-only. Only the SAM bbox patches get biased
|
| 15 |
+
# (key_bias_vis / nonkey_bias_vis); the text side is forced to 0 bias inside
|
| 16 |
+
# _make_attn_ctx regardless of what's passed here. SAM/MedSAM3 still runs
|
| 17 |
+
# (_needs_sam is True for "vis"). Matches run_eval_attnbias_sam_both.sh's
|
| 18 |
+
# mechanism (amplify-only, auction OFF) so this differs from the final method
|
| 19 |
+
# by exactly one factor (modality restricted to vis); compare against
|
| 20 |
+
# run_eval_attnbias_sam_text.sh and run_eval_attnbias_sam_both.sh.
|
| 21 |
+
INTERVENTION="vis"
|
| 22 |
+
ATTN_LAYERS_TEXT=17
|
| 23 |
+
ATTN_LAYERS_VIS=17
|
| 24 |
+
ATTN_KEY_BIAS_VIS=1.0
|
| 25 |
+
ATTN_NONKEY_BIAS_VIS=0.0
|
| 26 |
+
|
| 27 |
+
MAX_SAMPLES=""
|
| 28 |
+
|
| 29 |
+
accelerate launch --num_processes=1 eval_attnbias_sam.py \
|
| 30 |
+
--data_path "$DATA_PATH" \
|
| 31 |
+
--model_path "$MODEL_PATH" \
|
| 32 |
+
--seed "$SEED" \
|
| 33 |
+
--max_new_tokens "$MAX_NEW_TOKENS" \
|
| 34 |
+
--output_path "$OUTPUT_PATH" \
|
| 35 |
+
--intervention "$INTERVENTION" \
|
| 36 |
+
--attn_layers_text "$ATTN_LAYERS_TEXT" \
|
| 37 |
+
--attn_layers_vis "$ATTN_LAYERS_VIS" \
|
| 38 |
+
--attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
|
| 39 |
+
--attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
|
| 40 |
+
--medsam3_config "$MEDSAM3_CONFIG" \
|
| 41 |
+
--medsam3_dir "$MEDSAM3_DIR" \
|
| 42 |
+
${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis3.0/HuatuoGPT-Vision-7B_medical_multimodel_evaluation_data_both_Lt17_kt3.0_nt0.0_Lv17_kv3.0_nv0.0.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis3.0/HuatuoGPT-Vision-7B_medical_multimodel_evaluation_data_both_Lt17_kt3.0_nt0.0_Lv17_kv3.0_nv0.0_result.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"OmniMedVQA": 0.7461344839985616,
|
| 3 |
+
"PMC-VQA_test": 0.548,
|
| 4 |
+
"PathVQA_test": 0.5809042236763831,
|
| 5 |
+
"SLAKE_test": 0.7692307692307693,
|
| 6 |
+
"VQA-RAD_test": 0.6334661354581673,
|
| 7 |
+
"MMMU_Medical_Validation": 0.5310344827586206,
|
| 8 |
+
"The total score for multiple-choice questions": 0.6882298531622153,
|
| 9 |
+
"OmniMedVQA_MR (Mag-netic Resonance Imaging)": 0.7287128712871287,
|
| 10 |
+
"OmniMedVQA_ultrasound": 0.7776957163958641,
|
| 11 |
+
"OmniMedVQA_OCT (Optical Coherence Tomography": 0.8666666666666667,
|
| 12 |
+
"OmniMedVQA_Dermoscopy": 0.7211055276381909,
|
| 13 |
+
"OmniMedVQA_CT(Computed Tomography)": 0.6685082872928176,
|
| 14 |
+
"OmniMedVQA_X-Ray": 0.8056918547595682,
|
| 15 |
+
"OmniMedVQA_Microscopy Images": 0.7870879120879121,
|
| 16 |
+
"OmniMedVQA_Fundus Photography": 0.8146964856230032,
|
| 17 |
+
"MMMU_Medical_Validation_validation_Public_Health": 0.5,
|
| 18 |
+
"MMMU_Medical_Validation_validation_Diagnostics_and_Laboratory_Medicine": 0.4,
|
| 19 |
+
"MMMU_Medical_Validation_validation_Pharmacy": 0.48148148148148145,
|
| 20 |
+
"MMMU_Medical_Validation_validation_Basic_Medical_Science": 0.6071428571428571,
|
| 21 |
+
"MMMU_Medical_Validation_validation_Clinical_Medicine": 0.6666666666666666
|
| 22 |
+
}
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis3.0/_snapshot/run_ablation_grid_layer_worker.sh
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
# Runs a contiguous slice of the "remaining layers" sweep (the 23 layers NOT
|
| 5 |
+
# already covered by the original LAYERS=(3 10 17 24 27) test) on a single
|
| 6 |
+
# GPU, so the full sweep can be split across GPU 0 and GPU 2 and run
|
| 7 |
+
# concurrently (GPU 1/3 are occupied by other jobs on this workstation) --
|
| 8 |
+
# same pattern as run_ablation_grid_worker.sh for the strength grid, but for
|
| 9 |
+
# layers.
|
| 10 |
+
#
|
| 11 |
+
# NO cache-warmup step here (unlike run_ablation_grid.sh's stage 1): by the
|
| 12 |
+
# time this runs, the Pass0 cache (keyed on data_path/model_path/seed, shared
|
| 13 |
+
# across every combo/script in this repo) has already been fully populated by
|
| 14 |
+
# the earlier strength grid + original 5-layer sweep + run_all_attnbias_sam.sh
|
| 15 |
+
# runs, so both GPU workers should hit pure cache reads with nothing new to
|
| 16 |
+
# write -- eliminating the write-race risk without needing a serialized
|
| 17 |
+
# warmup run first. This assumption only breaks if the cache is somehow still
|
| 18 |
+
# incomplete (e.g. an earlier run was interrupted before finishing Pass 0);
|
| 19 |
+
# if you're not confident the cache is fully warm, warm it manually first
|
| 20 |
+
# (run any single combo alone) before launching this in parallel.
|
| 21 |
+
#
|
| 22 |
+
# S_TEXT/S_VIS are re-derived from the strength grid's results (same as
|
| 23 |
+
# run_ablation_grid_layer.sh), not hand-filled.
|
| 24 |
+
#
|
| 25 |
+
# FINAL METHOD = run_eval_attnbias_sam_both.sh: nonkey_bias_text/vis
|
| 26 |
+
# are pinned at 0 (amplify_only) AND the auction mechanism is OFF, matching
|
| 27 |
+
# run_ablation_grid_worker.sh's strength grid exactly. Output dirs use the
|
| 28 |
+
# "sam_both_amplify_noauction_..." tag to match.
|
| 29 |
+
#
|
| 30 |
+
# Usage:
|
| 31 |
+
# ./run_ablation_grid_layer_worker.sh <gpu_id> <start_index> <count>
|
| 32 |
+
# Example (23 combos split 12/11 across 2 GPUs):
|
| 33 |
+
# ./run_ablation_grid_layer_worker.sh 0 0 12 &
|
| 34 |
+
# ./run_ablation_grid_layer_worker.sh 2 12 11 &
|
| 35 |
+
# wait
|
| 36 |
+
set -e
|
| 37 |
+
|
| 38 |
+
GPU_ID="$1"
|
| 39 |
+
START="$2"
|
| 40 |
+
COUNT="$3"
|
| 41 |
+
if [ -z "$GPU_ID" ] || [ -z "$START" ] || [ -z "$COUNT" ]; then
|
| 42 |
+
echo "usage: $0 <gpu_id> <start_index> <count>" >&2
|
| 43 |
+
exit 1
|
| 44 |
+
fi
|
| 45 |
+
export CUDA_VISIBLE_DEVICES="$GPU_ID"
|
| 46 |
+
|
| 47 |
+
source /home/jinhua/miniconda3/etc/profile.d/conda.sh
|
| 48 |
+
conda activate huatuovision
|
| 49 |
+
|
| 50 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 51 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 52 |
+
|
| 53 |
+
SEED=42
|
| 54 |
+
MAX_NEW_TOKENS=256
|
| 55 |
+
|
| 56 |
+
MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
|
| 57 |
+
MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
|
| 58 |
+
|
| 59 |
+
INTERVENTION="both"
|
| 60 |
+
# the 23 layers NOT in the original LAYERS=(3 10 17 24 27) test -- model has
|
| 61 |
+
# 28 layers total (indices 0-27), confirmed via
|
| 62 |
+
# PretrainedConfig.get_config_dict('FreedomIntelligence/HuatuoGPT-Vision-7B')['num_hidden_layers'] == 28.
|
| 63 |
+
# run_ablation_grid_layer.sh (the driver) does NOT keep its own copy of this
|
| 64 |
+
# array -- it only needs the total count (TOTAL=23) to split indices across
|
| 65 |
+
# GPU 0/1, plus a separate LAYERS_ALL (all 28) for the final "pick best
|
| 66 |
+
# layer" scan. If you change this array's length, update TOTAL/SPLIT in
|
| 67 |
+
# run_ablation_grid_layer.sh to match.
|
| 68 |
+
LAYERS_REMAINING=(0 1 2 4 5 6 7 8 9 11 12 13 14 15 16 18 19 20 21 22 23 25 26)
|
| 69 |
+
STAGE1_LAYER=17
|
| 70 |
+
STRENGTHS_TEXT=(1.0 2.0 3.0 4.0 5.0)
|
| 71 |
+
STRENGTHS_VIS=(1.0 2.0 3.0 4.0 5.0)
|
| 72 |
+
|
| 73 |
+
MAX_SAMPLES=""
|
| 74 |
+
|
| 75 |
+
# ── re-derive stage 1's winning (s_text, s_vis) directly from the strength
|
| 76 |
+
# grid's result files -- same scan-and-compare as run_ablation_grid_pick.sh.
|
| 77 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] re-scanning stage 1's results to find the winning (s_text, s_vis)..."
|
| 78 |
+
S_TEXT=""
|
| 79 |
+
S_VIS=""
|
| 80 |
+
STAGE1_BEST_SCORE=""
|
| 81 |
+
for ST in "${STRENGTHS_TEXT[@]}"; do
|
| 82 |
+
for SV in "${STRENGTHS_VIS[@]}"; do
|
| 83 |
+
STAGE1_OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${STAGE1_LAYER}_stext${ST}_svis${SV}"
|
| 84 |
+
STAGE1_RESULT_F=$(ls "$STAGE1_OUTPUT_PATH"/*_result.json 2>/dev/null | head -n1)
|
| 85 |
+
if [ -z "$STAGE1_RESULT_F" ]; then
|
| 86 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] missing *_result.json under $STAGE1_OUTPUT_PATH -- has the strength grid finished?" >&2
|
| 87 |
+
exit 1
|
| 88 |
+
fi
|
| 89 |
+
STAGE1_SCORE=$(python -c "
|
| 90 |
+
import json
|
| 91 |
+
with open('$STAGE1_RESULT_F') as f:
|
| 92 |
+
d = json.load(f)
|
| 93 |
+
print(d['The total score for multiple-choice questions'])
|
| 94 |
+
")
|
| 95 |
+
if [ -z "$STAGE1_BEST_SCORE" ] || python -c "exit(0 if $STAGE1_SCORE > $STAGE1_BEST_SCORE else 1)"; then
|
| 96 |
+
STAGE1_BEST_SCORE="$STAGE1_SCORE"
|
| 97 |
+
S_TEXT="$ST"
|
| 98 |
+
S_VIS="$SV"
|
| 99 |
+
fi
|
| 100 |
+
done
|
| 101 |
+
done
|
| 102 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] strength winner: s_text=$S_TEXT s_vis=$S_VIS (score=$STAGE1_BEST_SCORE) -- fixing strength at this combo for the layer sweep"
|
| 103 |
+
|
| 104 |
+
TOTAL=${#LAYERS_REMAINING[@]}
|
| 105 |
+
END=$((START + COUNT))
|
| 106 |
+
if [ "$END" -gt "$TOTAL" ]; then
|
| 107 |
+
END="$TOTAL"
|
| 108 |
+
fi
|
| 109 |
+
|
| 110 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] running layers [$START, $END) of $TOTAL total"
|
| 111 |
+
|
| 112 |
+
for ((i = START; i < END; i++)); do
|
| 113 |
+
LAYER="${LAYERS_REMAINING[$i]}"
|
| 114 |
+
OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${LAYER}_stext${S_TEXT}_svis${S_VIS}"
|
| 115 |
+
if [ -d "$OUTPUT_PATH" ]; then
|
| 116 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] $OUTPUT_PATH already exists, skipping layer=$LAYER (delete the dir manually to re-run)"
|
| 117 |
+
continue
|
| 118 |
+
fi
|
| 119 |
+
|
| 120 |
+
echo "=================================================="
|
| 121 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] idx=$i layer=$LAYER s_text=$S_TEXT s_vis=$S_VIS -> $OUTPUT_PATH"
|
| 122 |
+
echo "=================================================="
|
| 123 |
+
|
| 124 |
+
accelerate launch --num_processes=1 eval_attnbias_sam.py \
|
| 125 |
+
--data_path "$DATA_PATH" \
|
| 126 |
+
--model_path "$MODEL_PATH" \
|
| 127 |
+
--seed "$SEED" \
|
| 128 |
+
--max_new_tokens "$MAX_NEW_TOKENS" \
|
| 129 |
+
--output_path "$OUTPUT_PATH" \
|
| 130 |
+
--intervention "$INTERVENTION" \
|
| 131 |
+
--attn_layers_text "$LAYER" \
|
| 132 |
+
--attn_key_bias_text "$S_TEXT" \
|
| 133 |
+
--attn_nonkey_bias_text "0" \
|
| 134 |
+
--attn_layers_vis "$LAYER" \
|
| 135 |
+
--attn_key_bias_vis "$S_VIS" \
|
| 136 |
+
--attn_nonkey_bias_vis "0" \
|
| 137 |
+
--medsam3_config "$MEDSAM3_CONFIG" \
|
| 138 |
+
--medsam3_dir "$MEDSAM3_DIR" \
|
| 139 |
+
${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
|
| 140 |
+
|
| 141 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] idx=$i layer=$LAYER finished"
|
| 142 |
+
done
|
| 143 |
+
|
| 144 |
+
echo "[ablation-grid-layer-worker gpu=$GPU_ID] done with layers [$START, $END)"
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis3.0/_snapshot/run_ablation_grid_pick.sh
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
# Picks the best (strength_text, strength_vis) across the full grid and syncs
|
| 5 |
+
# it into every run_eval_attnbias_sam_*.sh via sync_attn_params.py. Run this
|
| 6 |
+
# ONCE, by hand, after every run_ablation_grid_worker.sh slice (on every GPU
|
| 7 |
+
# you split the grid across) has finished -- it requires *all* combos'
|
| 8 |
+
# *_result.json to be present, since the "best" choice isn't meaningful until
|
| 9 |
+
# the whole grid has been scored.
|
| 10 |
+
#
|
| 11 |
+
# FINAL METHOD = run_eval_attnbias_sam_both.sh: nonkey_bias is
|
| 12 |
+
# pinned at 0 (amplify_only -- boost key regions only, no suppression) AND the
|
| 13 |
+
# grid was searched with the auction mechanism OFF (see
|
| 14 |
+
# run_ablation_grid_worker.sh), matching the final method exactly.
|
| 15 |
+
# run_eval_attnbias_sam_both_suppress_only.sh has been dropped from
|
| 16 |
+
# run_all_attnbias_sam.sh's comparison set (no longer a live ablation arm), so
|
| 17 |
+
# there's no risk of this sync corrupting it.
|
| 18 |
+
set -e
|
| 19 |
+
|
| 20 |
+
source /home/jinhua/miniconda3/etc/profile.d/conda.sh
|
| 21 |
+
conda activate huatuovision
|
| 22 |
+
|
| 23 |
+
LAYER=17
|
| 24 |
+
# must stay identical to run_ablation_grid_worker.sh's copy of these arrays.
|
| 25 |
+
STRENGTHS_TEXT=(1.0 2.0 3.0 4.0 5.0)
|
| 26 |
+
STRENGTHS_VIS=(1.0 2.0 3.0 4.0 5.0)
|
| 27 |
+
|
| 28 |
+
# ── pick the best (s_text, s_vis) across the full grid, layer fixed at 17.
|
| 29 |
+
# Each combo's output dir holds exactly one *_result.json (eval_attnbias_sam.py's hparam_tag
|
| 30 |
+
# already makes the filename unique per layer/strength/auction config, so
|
| 31 |
+
# no risk of stale files from a previous combo lingering in the same dir),
|
| 32 |
+
# so glob for it directly instead of hand-reconstructing the filename --
|
| 33 |
+
# that reconstruction is what broke last time hparam_tag's format changed.
|
| 34 |
+
BEST_S_TEXT=""
|
| 35 |
+
BEST_S_VIS=""
|
| 36 |
+
BEST_SCORE=""
|
| 37 |
+
for S_TEXT in "${STRENGTHS_TEXT[@]}"; do
|
| 38 |
+
for S_VIS in "${STRENGTHS_VIS[@]}"; do
|
| 39 |
+
OUTPUT_PATH="results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer${LAYER}_stext${S_TEXT}_svis${S_VIS}"
|
| 40 |
+
RESULT_F=$(ls "$OUTPUT_PATH"/*_result.json 2>/dev/null | head -n1)
|
| 41 |
+
if [ -z "$RESULT_F" ]; then
|
| 42 |
+
echo "[ablation-grid-pick] missing *_result.json under $OUTPUT_PATH -- cannot pick best (s_text, s_vis). Did every run_ablation_grid_worker.sh slice finish?" >&2
|
| 43 |
+
exit 1
|
| 44 |
+
fi
|
| 45 |
+
SCORE=$(python -c "
|
| 46 |
+
import json
|
| 47 |
+
with open('$RESULT_F') as f:
|
| 48 |
+
d = json.load(f)
|
| 49 |
+
print(d['The total score for multiple-choice questions'])
|
| 50 |
+
")
|
| 51 |
+
echo "[ablation-grid-pick] s_text=$S_TEXT s_vis=$S_VIS score=$SCORE"
|
| 52 |
+
if [ -z "$BEST_SCORE" ] || python -c "exit(0 if $SCORE > $BEST_SCORE else 1)"; then
|
| 53 |
+
BEST_SCORE="$SCORE"
|
| 54 |
+
BEST_S_TEXT="$S_TEXT"
|
| 55 |
+
BEST_S_VIS="$S_VIS"
|
| 56 |
+
fi
|
| 57 |
+
done
|
| 58 |
+
done
|
| 59 |
+
|
| 60 |
+
echo "[ablation-grid-pick] best overall: layer=$LAYER s_text=$BEST_S_TEXT s_vis=$BEST_S_VIS (score=$BEST_SCORE)"
|
| 61 |
+
echo "[ablation-grid-pick] syncing into every run_eval_attnbias_sam_*.sh via sync_attn_params.py"
|
| 62 |
+
|
| 63 |
+
python sync_attn_params.py \
|
| 64 |
+
--layers_text "$LAYER" --key_bias_text "$BEST_S_TEXT" --nonkey_bias_text "0" \
|
| 65 |
+
--layers_vis "$LAYER" --key_bias_vis "$BEST_S_VIS" --nonkey_bias_vis "0"
|
| 66 |
+
|
| 67 |
+
echo "[ablation-grid-pick] done. All run_eval_attnbias_sam_*.sh now use the ablation-selected layer/strength (nonkey_bias=0, amplify_only style)"
|
| 68 |
+
echo "[ablation-grid-pick] (amplify_only keeps its pinned-zero side; text.sh/vis.sh keep their single-modality side -- see sync_attn_params.py)."
|
HuatuoGPT-Vision-Abla/results_attnbias_ablation/HuatuoGPT-Vision-7B/sam_both_amplify_noauction_layer17_stext3.0_svis3.0/_snapshot/run_eval_attnbias_sam_both.sh
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
cd "$(dirname "$0")"
|
| 3 |
+
|
| 4 |
+
DATA_PATH="/home/jinhua/ExplainableVQA/benchmarks/Medical_Multimodal_Evaluation_Data/medical_multimodel_evaluation_data.json"
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
OUTPUT_PATH="results_attnbias/HuatuoGPT-Vision-7B/sam_both"
|
| 7 |
+
|
| 8 |
+
SEED=42
|
| 9 |
+
MAX_NEW_TOKENS=256
|
| 10 |
+
|
| 11 |
+
MEDSAM3_CONFIG="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/configs/full_lora_config.yaml"
|
| 12 |
+
MEDSAM3_DIR="/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3"
|
| 13 |
+
|
| 14 |
+
# FINAL METHOD: both mode, amplify-only (nonkey_bias pinned at 0 -- boost key
|
| 15 |
+
# regions, don't suppress anything else) and auction OFF -- every Stage1/SAM-
|
| 16 |
+
# detected key position gets boosted directly, not just an auction-selected
|
| 17 |
+
# subset (ablation found the auction mechanism doesn't help over this simpler
|
| 18 |
+
# design; see run_eval_attnbias_sam_both_noauction.sh, kept around for
|
| 19 |
+
# reference but no longer part of the active comparison set).
|
| 20 |
+
INTERVENTION="both"
|
| 21 |
+
ATTN_LAYERS_TEXT=17
|
| 22 |
+
ATTN_KEY_BIAS_TEXT=5.0
|
| 23 |
+
ATTN_NONKEY_BIAS_TEXT=0.0
|
| 24 |
+
ATTN_LAYERS_VIS=17
|
| 25 |
+
ATTN_KEY_BIAS_VIS=1.0
|
| 26 |
+
ATTN_NONKEY_BIAS_VIS=0.0
|
| 27 |
+
|
| 28 |
+
MAX_SAMPLES=""
|
| 29 |
+
|
| 30 |
+
accelerate launch --num_processes=1 eval_attnbias_sam.py \
|
| 31 |
+
--data_path "$DATA_PATH" \
|
| 32 |
+
--model_path "$MODEL_PATH" \
|
| 33 |
+
--seed "$SEED" \
|
| 34 |
+
--max_new_tokens "$MAX_NEW_TOKENS" \
|
| 35 |
+
--output_path "$OUTPUT_PATH" \
|
| 36 |
+
--intervention "$INTERVENTION" \
|
| 37 |
+
--attn_layers_text "$ATTN_LAYERS_TEXT" \
|
| 38 |
+
--attn_key_bias_text "$ATTN_KEY_BIAS_TEXT" \
|
| 39 |
+
--attn_nonkey_bias_text "$ATTN_NONKEY_BIAS_TEXT" \
|
| 40 |
+
--attn_layers_vis "$ATTN_LAYERS_VIS" \
|
| 41 |
+
--attn_key_bias_vis "$ATTN_KEY_BIAS_VIS" \
|
| 42 |
+
--attn_nonkey_bias_vis "$ATTN_NONKEY_BIAS_VIS" \
|
| 43 |
+
--medsam3_config "$MEDSAM3_CONFIG" \
|
| 44 |
+
--medsam3_dir "$MEDSAM3_DIR" \
|
| 45 |
+
${MAX_SAMPLES:+--max_samples "$MAX_SAMPLES"}
|