Add files using upload-large-folder tool
Browse files- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_COCO_LLaVA_13B.sh +24 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_COCO_MedGemma_27B_IT.sh +27 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_COCO_MedGemma_4B_IT.sh +24 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_COCO_Qwen25VL_7B.sh +24 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_VGMED_HuatuoGPT_V_7B.sh +21 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_VGMED_LLaVA_13B.sh +21 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_VGMED_LLaVA_7B.sh +21 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_VGMED_MedGemma_4B_IT.sh +21 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/run_all_diff_region.sh +51 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/run_all_diff_text.sh +51 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/run_all_mask_region.sh +51 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/run_all_mask_text.sh +51 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/run_all_measure_attention.sh +52 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/.ipynb_checkpoints/HealthGPT-checkpoint.py +173 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/.ipynb_checkpoints/HealthGPT_phi-checkpoint.py +169 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/llava/demo/com_infer.py +128 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/llava/demo/com_infer_phi4.sh +18 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/llava/demo/gen_infer.py +134 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/llava/demo/gen_infer.sh +21 -0
- 之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/llava/demo/utils.py +103 -0
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_COCO_LLaVA_13B.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="llava-hf/llava-1.5-13b-hf"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/LLaVA-13B"
|
| 9 |
+
|
| 10 |
+
python measure_attention.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_COCO_MedGemma_27B_IT.sh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
export CUDA_VISIBLE_DEVICES=0,2,3
|
| 6 |
+
|
| 7 |
+
MODEL_PATH="google/medgemma-27b-it"
|
| 8 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 9 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 10 |
+
OUTPUT_ROOT="attention_results/MedGemma-27B-IT"
|
| 11 |
+
|
| 12 |
+
python measure_attention.py \
|
| 13 |
+
--dataset COCO \
|
| 14 |
+
--q_type localization \
|
| 15 |
+
--model_path "$MODEL_PATH" \
|
| 16 |
+
--coco_root "$COCO_ROOT" \
|
| 17 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 18 |
+
--output_root "$OUTPUT_ROOT" \
|
| 19 |
+
--device auto
|
| 20 |
+
|
| 21 |
+
# python measure_attention.py \
|
| 22 |
+
# --dataset COCO \
|
| 23 |
+
# --q_type attribute \
|
| 24 |
+
# --model_path "$MODEL_PATH" \
|
| 25 |
+
# --coco_root "$COCO_ROOT" \
|
| 26 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 27 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_COCO_MedGemma_4B_IT.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="google/medgemma-4b-it"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/MedGemma-4B-IT"
|
| 9 |
+
|
| 10 |
+
python measure_attention.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_COCO_Qwen25VL_7B.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="Qwen/Qwen2.5-VL-7B-Instruct"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/Qwen2.5VL-7B"
|
| 9 |
+
|
| 10 |
+
python measure_attention.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_VGMED_HuatuoGPT_V_7B.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
VGMED_ROOT="../benchmarks/VGMED"
|
| 7 |
+
OUTPUT_ROOT="attention_results/HuatuoGPT-V-7B"
|
| 8 |
+
|
| 9 |
+
python measure_attention.py \
|
| 10 |
+
--dataset VGMED \
|
| 11 |
+
--q_type localization \
|
| 12 |
+
--model_path "$MODEL_PATH" \
|
| 13 |
+
--vgmed_root "$VGMED_ROOT" \
|
| 14 |
+
--output_root "$OUTPUT_ROOT"
|
| 15 |
+
|
| 16 |
+
# python measure_attention.py \
|
| 17 |
+
# --dataset VGMED \
|
| 18 |
+
# --q_type attribute \
|
| 19 |
+
# --model_path "$MODEL_PATH" \
|
| 20 |
+
# --vgmed_root "$VGMED_ROOT" \
|
| 21 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_VGMED_LLaVA_13B.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="llava-hf/llava-1.5-13b-hf"
|
| 6 |
+
VGMED_ROOT="../benchmarks/VGMED"
|
| 7 |
+
OUTPUT_ROOT="attention_results/LLaVA-13B"
|
| 8 |
+
|
| 9 |
+
python measure_attention.py \
|
| 10 |
+
--dataset VGMED \
|
| 11 |
+
--q_type localization \
|
| 12 |
+
--model_path "$MODEL_PATH" \
|
| 13 |
+
--vgmed_root "$VGMED_ROOT" \
|
| 14 |
+
--output_root "$OUTPUT_ROOT"
|
| 15 |
+
|
| 16 |
+
# python measure_attention.py \
|
| 17 |
+
# --dataset VGMED \
|
| 18 |
+
# --q_type attribute \
|
| 19 |
+
# --model_path "$MODEL_PATH" \
|
| 20 |
+
# --vgmed_root "$VGMED_ROOT" \
|
| 21 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_VGMED_LLaVA_7B.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="llava-hf/llava-1.5-7b-hf"
|
| 6 |
+
VGMED_ROOT="../benchmarks/VGMED"
|
| 7 |
+
OUTPUT_ROOT="attention_results/LLaVA-7B"
|
| 8 |
+
|
| 9 |
+
python measure_attention.py \
|
| 10 |
+
--dataset VGMED \
|
| 11 |
+
--q_type localization \
|
| 12 |
+
--model_path "$MODEL_PATH" \
|
| 13 |
+
--vgmed_root "$VGMED_ROOT" \
|
| 14 |
+
--output_root "$OUTPUT_ROOT"
|
| 15 |
+
|
| 16 |
+
# python measure_attention.py \
|
| 17 |
+
# --dataset VGMED \
|
| 18 |
+
# --q_type attribute \
|
| 19 |
+
# --model_path "$MODEL_PATH" \
|
| 20 |
+
# --vgmed_root "$VGMED_ROOT" \
|
| 21 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/measure_attention/measure_attention_VGMED_MedGemma_4B_IT.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="google/medgemma-4b-it"
|
| 6 |
+
VGMED_ROOT="../benchmarks/VGMED"
|
| 7 |
+
OUTPUT_ROOT="attention_results/MedGemma-4B-IT"
|
| 8 |
+
|
| 9 |
+
python measure_attention.py \
|
| 10 |
+
--dataset VGMED \
|
| 11 |
+
--q_type localization \
|
| 12 |
+
--model_path "$MODEL_PATH" \
|
| 13 |
+
--vgmed_root "$VGMED_ROOT" \
|
| 14 |
+
--output_root "$OUTPUT_ROOT"
|
| 15 |
+
|
| 16 |
+
# python measure_attention.py \
|
| 17 |
+
# --dataset VGMED \
|
| 18 |
+
# --q_type attribute \
|
| 19 |
+
# --model_path "$MODEL_PATH" \
|
| 20 |
+
# --vgmed_root "$VGMED_ROOT" \
|
| 21 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/run_all_diff_region.sh
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# run_all_diff_region: grounding_diff_region.py
|
| 3 |
+
# Oversized models (32B/34B/27B-IT) are pushed to the very end, after every
|
| 4 |
+
# normal-size model has finished, so a stuck/OOM large model never blocks them.
|
| 5 |
+
export CUDA_VISIBLE_DEVICES=0
|
| 6 |
+
cd "$(dirname "$0")/.."
|
| 7 |
+
|
| 8 |
+
echo "=== [qianwen] Qwen25VL_7B COCO ==="
|
| 9 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/diff_region/diff_region_COCO_Qwen25VL_7B.sh
|
| 10 |
+
echo "=== [qianwen] Qwen25VL_7B VGMED ==="
|
| 11 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/diff_region/diff_region_VGMED_Qwen25VL_7B.sh
|
| 12 |
+
echo "=== [qianwen] Qwen25VL_3B COCO ==="
|
| 13 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/diff_region/diff_region_COCO_Qwen25VL_3B.sh
|
| 14 |
+
echo "=== [qianwen] Qwen25VL_3B VGMED ==="
|
| 15 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/diff_region/diff_region_VGMED_Qwen25VL_3B.sh
|
| 16 |
+
echo "=== [llava-natural] LLaVA_7B COCO ==="
|
| 17 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/diff_region/diff_region_COCO_LLaVA_7B.sh
|
| 18 |
+
echo "=== [llava-natural] LLaVA_7B VGMED ==="
|
| 19 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/diff_region/diff_region_VGMED_LLaVA_7B.sh
|
| 20 |
+
echo "=== [llava-natural] LLaVA_13B COCO ==="
|
| 21 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/diff_region/diff_region_COCO_LLaVA_13B.sh
|
| 22 |
+
echo "=== [llava-natural] LLaVA_13B VGMED ==="
|
| 23 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/diff_region/diff_region_VGMED_LLaVA_13B.sh
|
| 24 |
+
echo "=== [llava-med] LLaVA_Med_7B COCO ==="
|
| 25 |
+
conda run --no-capture-output -n llava-med bash eval_scripts/grounding/diff_region/diff_region_COCO_LLaVA_Med_7B.sh
|
| 26 |
+
echo "=== [llava-med] LLaVA_Med_7B VGMED ==="
|
| 27 |
+
conda run --no-capture-output -n llava-med bash eval_scripts/grounding/diff_region/diff_region_VGMED_LLaVA_Med_7B.sh
|
| 28 |
+
echo "=== [huatuogpt] HuatuoGPT_V_7B COCO ==="
|
| 29 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/diff_region/diff_region_COCO_HuatuoGPT_V_7B.sh
|
| 30 |
+
echo "=== [huatuogpt] HuatuoGPT_V_7B VGMED ==="
|
| 31 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/diff_region/diff_region_VGMED_HuatuoGPT_V_7B.sh
|
| 32 |
+
echo "=== [gemma] MedGemma_4B_IT COCO ==="
|
| 33 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/diff_region/diff_region_COCO_MedGemma_4B_IT.sh
|
| 34 |
+
echo "=== [gemma] MedGemma_4B_IT VGMED ==="
|
| 35 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/diff_region/diff_region_VGMED_MedGemma_4B_IT.sh
|
| 36 |
+
|
| 37 |
+
# ── Oversized models (run last; failures here don't block anything above) ──
|
| 38 |
+
echo "=== [qianwen] Qwen25VL_32B COCO ==="
|
| 39 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/diff_region/diff_region_COCO_Qwen25VL_32B.sh
|
| 40 |
+
echo "=== [qianwen] Qwen25VL_32B VGMED ==="
|
| 41 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/diff_region/diff_region_VGMED_Qwen25VL_32B.sh
|
| 42 |
+
echo "=== [huatuogpt] HuatuoGPT_V_34B COCO ==="
|
| 43 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/diff_region/diff_region_COCO_HuatuoGPT_V_34B.sh
|
| 44 |
+
echo "=== [huatuogpt] HuatuoGPT_V_34B VGMED ==="
|
| 45 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/diff_region/diff_region_VGMED_HuatuoGPT_V_34B.sh
|
| 46 |
+
echo "=== [gemma] MedGemma_27B_IT COCO ==="
|
| 47 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/diff_region/diff_region_COCO_MedGemma_27B_IT.sh
|
| 48 |
+
echo "=== [gemma] MedGemma_27B_IT VGMED ==="
|
| 49 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/diff_region/diff_region_VGMED_MedGemma_27B_IT.sh
|
| 50 |
+
|
| 51 |
+
echo "All diff_region jobs finished."
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/run_all_diff_text.sh
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# run_all_diff_text: grounding_diff_text.py
|
| 3 |
+
# Oversized models (32B/34B/27B-IT) are pushed to the very end, after every
|
| 4 |
+
# normal-size model has finished, so a stuck/OOM large model never blocks them.
|
| 5 |
+
export CUDA_VISIBLE_DEVICES=0
|
| 6 |
+
cd "$(dirname "$0")/.."
|
| 7 |
+
|
| 8 |
+
echo "=== [qianwen] Qwen25VL_7B COCO ==="
|
| 9 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/diff_text/diff_text_COCO_Qwen25VL_7B.sh
|
| 10 |
+
echo "=== [qianwen] Qwen25VL_7B VGMED ==="
|
| 11 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/diff_text/diff_text_VGMED_Qwen25VL_7B.sh
|
| 12 |
+
echo "=== [qianwen] Qwen25VL_3B COCO ==="
|
| 13 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/diff_text/diff_text_COCO_Qwen25VL_3B.sh
|
| 14 |
+
echo "=== [qianwen] Qwen25VL_3B VGMED ==="
|
| 15 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/diff_text/diff_text_VGMED_Qwen25VL_3B.sh
|
| 16 |
+
echo "=== [llava-natural] LLaVA_7B COCO ==="
|
| 17 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/diff_text/diff_text_COCO_LLaVA_7B.sh
|
| 18 |
+
echo "=== [llava-natural] LLaVA_7B VGMED ==="
|
| 19 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/diff_text/diff_text_VGMED_LLaVA_7B.sh
|
| 20 |
+
echo "=== [llava-natural] LLaVA_13B COCO ==="
|
| 21 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/diff_text/diff_text_COCO_LLaVA_13B.sh
|
| 22 |
+
echo "=== [llava-natural] LLaVA_13B VGMED ==="
|
| 23 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/diff_text/diff_text_VGMED_LLaVA_13B.sh
|
| 24 |
+
echo "=== [llava-med] LLaVA_Med_7B COCO ==="
|
| 25 |
+
conda run --no-capture-output -n llava-med bash eval_scripts/grounding/diff_text/diff_text_COCO_LLaVA_Med_7B.sh
|
| 26 |
+
echo "=== [llava-med] LLaVA_Med_7B VGMED ==="
|
| 27 |
+
conda run --no-capture-output -n llava-med bash eval_scripts/grounding/diff_text/diff_text_VGMED_LLaVA_Med_7B.sh
|
| 28 |
+
echo "=== [huatuogpt] HuatuoGPT_V_7B COCO ==="
|
| 29 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/diff_text/diff_text_COCO_HuatuoGPT_V_7B.sh
|
| 30 |
+
echo "=== [huatuogpt] HuatuoGPT_V_7B VGMED ==="
|
| 31 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/diff_text/diff_text_VGMED_HuatuoGPT_V_7B.sh
|
| 32 |
+
echo "=== [gemma] MedGemma_4B_IT COCO ==="
|
| 33 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/diff_text/diff_text_COCO_MedGemma_4B_IT.sh
|
| 34 |
+
echo "=== [gemma] MedGemma_4B_IT VGMED ==="
|
| 35 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/diff_text/diff_text_VGMED_MedGemma_4B_IT.sh
|
| 36 |
+
|
| 37 |
+
# ── Oversized models (run last; failures here don't block anything above) ──
|
| 38 |
+
echo "=== [qianwen] Qwen25VL_32B COCO ==="
|
| 39 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/diff_text/diff_text_COCO_Qwen25VL_32B.sh
|
| 40 |
+
echo "=== [qianwen] Qwen25VL_32B VGMED ==="
|
| 41 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/diff_text/diff_text_VGMED_Qwen25VL_32B.sh
|
| 42 |
+
echo "=== [huatuogpt] HuatuoGPT_V_34B COCO ==="
|
| 43 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/diff_text/diff_text_COCO_HuatuoGPT_V_34B.sh
|
| 44 |
+
echo "=== [huatuogpt] HuatuoGPT_V_34B VGMED ==="
|
| 45 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/diff_text/diff_text_VGMED_HuatuoGPT_V_34B.sh
|
| 46 |
+
echo "=== [gemma] MedGemma_27B_IT COCO ==="
|
| 47 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/diff_text/diff_text_COCO_MedGemma_27B_IT.sh
|
| 48 |
+
echo "=== [gemma] MedGemma_27B_IT VGMED ==="
|
| 49 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/diff_text/diff_text_VGMED_MedGemma_27B_IT.sh
|
| 50 |
+
|
| 51 |
+
echo "All diff_text jobs finished."
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/run_all_mask_region.sh
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# run_all_mask_region: grounding_mask_region.py
|
| 3 |
+
# Oversized models (32B/34B/27B-IT) are pushed to the very end, after every
|
| 4 |
+
# normal-size model has finished, so a stuck/OOM large model never blocks them.
|
| 5 |
+
export CUDA_VISIBLE_DEVICES=0
|
| 6 |
+
cd "$(dirname "$0")/.."
|
| 7 |
+
|
| 8 |
+
echo "=== [qianwen] Qwen25VL_7B COCO ==="
|
| 9 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/mask_region/mask_region_COCO_Qwen25VL_7B.sh
|
| 10 |
+
echo "=== [qianwen] Qwen25VL_7B VGMED ==="
|
| 11 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/mask_region/mask_region_VGMED_Qwen25VL_7B.sh
|
| 12 |
+
echo "=== [qianwen] Qwen25VL_3B COCO ==="
|
| 13 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/mask_region/mask_region_COCO_Qwen25VL_3B.sh
|
| 14 |
+
echo "=== [qianwen] Qwen25VL_3B VGMED ==="
|
| 15 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/mask_region/mask_region_VGMED_Qwen25VL_3B.sh
|
| 16 |
+
echo "=== [llava-natural] LLaVA_7B COCO ==="
|
| 17 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/mask_region/mask_region_COCO_LLaVA_7B.sh
|
| 18 |
+
echo "=== [llava-natural] LLaVA_7B VGMED ==="
|
| 19 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/mask_region/mask_region_VGMED_LLaVA_7B.sh
|
| 20 |
+
echo "=== [llava-natural] LLaVA_13B COCO ==="
|
| 21 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/mask_region/mask_region_COCO_LLaVA_13B.sh
|
| 22 |
+
echo "=== [llava-natural] LLaVA_13B VGMED ==="
|
| 23 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/mask_region/mask_region_VGMED_LLaVA_13B.sh
|
| 24 |
+
echo "=== [llava-med] LLaVA_Med_7B COCO ==="
|
| 25 |
+
conda run --no-capture-output -n llava-med bash eval_scripts/grounding/mask_region/mask_region_COCO_LLaVA_Med_7B.sh
|
| 26 |
+
echo "=== [llava-med] LLaVA_Med_7B VGMED ==="
|
| 27 |
+
conda run --no-capture-output -n llava-med bash eval_scripts/grounding/mask_region/mask_region_VGMED_LLaVA_Med_7B.sh
|
| 28 |
+
echo "=== [huatuogpt] HuatuoGPT_V_7B COCO ==="
|
| 29 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/mask_region/mask_region_COCO_HuatuoGPT_V_7B.sh
|
| 30 |
+
echo "=== [huatuogpt] HuatuoGPT_V_7B VGMED ==="
|
| 31 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/mask_region/mask_region_VGMED_HuatuoGPT_V_7B.sh
|
| 32 |
+
echo "=== [gemma] MedGemma_4B_IT COCO ==="
|
| 33 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/mask_region/mask_region_COCO_MedGemma_4B_IT.sh
|
| 34 |
+
echo "=== [gemma] MedGemma_4B_IT VGMED ==="
|
| 35 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/mask_region/mask_region_VGMED_MedGemma_4B_IT.sh
|
| 36 |
+
|
| 37 |
+
# ── Oversized models (run last; failures here don't block anything above) ──
|
| 38 |
+
echo "=== [qianwen] Qwen25VL_32B COCO ==="
|
| 39 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/mask_region/mask_region_COCO_Qwen25VL_32B.sh
|
| 40 |
+
echo "=== [qianwen] Qwen25VL_32B VGMED ==="
|
| 41 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/mask_region/mask_region_VGMED_Qwen25VL_32B.sh
|
| 42 |
+
echo "=== [huatuogpt] HuatuoGPT_V_34B COCO ==="
|
| 43 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/mask_region/mask_region_COCO_HuatuoGPT_V_34B.sh
|
| 44 |
+
echo "=== [huatuogpt] HuatuoGPT_V_34B VGMED ==="
|
| 45 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/mask_region/mask_region_VGMED_HuatuoGPT_V_34B.sh
|
| 46 |
+
echo "=== [gemma] MedGemma_27B_IT COCO ==="
|
| 47 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/mask_region/mask_region_COCO_MedGemma_27B_IT.sh
|
| 48 |
+
echo "=== [gemma] MedGemma_27B_IT VGMED ==="
|
| 49 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/mask_region/mask_region_VGMED_MedGemma_27B_IT.sh
|
| 50 |
+
|
| 51 |
+
echo "All mask_region jobs finished."
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/run_all_mask_text.sh
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# run_all_mask_text: grounding_mask_text.py
|
| 3 |
+
# Oversized models (32B/34B/27B-IT) are pushed to the very end, after every
|
| 4 |
+
# normal-size model has finished, so a stuck/OOM large model never blocks them.
|
| 5 |
+
export CUDA_VISIBLE_DEVICES=0
|
| 6 |
+
cd "$(dirname "$0")/.."
|
| 7 |
+
|
| 8 |
+
echo "=== [qianwen] Qwen25VL_7B COCO ==="
|
| 9 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/mask_text/mask_text_COCO_Qwen25VL_7B.sh
|
| 10 |
+
echo "=== [qianwen] Qwen25VL_7B VGMED ==="
|
| 11 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/mask_text/mask_text_VGMED_Qwen25VL_7B.sh
|
| 12 |
+
echo "=== [qianwen] Qwen25VL_3B COCO ==="
|
| 13 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/mask_text/mask_text_COCO_Qwen25VL_3B.sh
|
| 14 |
+
echo "=== [qianwen] Qwen25VL_3B VGMED ==="
|
| 15 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/mask_text/mask_text_VGMED_Qwen25VL_3B.sh
|
| 16 |
+
echo "=== [llava-natural] LLaVA_7B COCO ==="
|
| 17 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/mask_text/mask_text_COCO_LLaVA_7B.sh
|
| 18 |
+
echo "=== [llava-natural] LLaVA_7B VGMED ==="
|
| 19 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/mask_text/mask_text_VGMED_LLaVA_7B.sh
|
| 20 |
+
echo "=== [llava-natural] LLaVA_13B COCO ==="
|
| 21 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/mask_text/mask_text_COCO_LLaVA_13B.sh
|
| 22 |
+
echo "=== [llava-natural] LLaVA_13B VGMED ==="
|
| 23 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/grounding/mask_text/mask_text_VGMED_LLaVA_13B.sh
|
| 24 |
+
echo "=== [llava-med] LLaVA_Med_7B COCO ==="
|
| 25 |
+
conda run --no-capture-output -n llava-med bash eval_scripts/grounding/mask_text/mask_text_COCO_LLaVA_Med_7B.sh
|
| 26 |
+
echo "=== [llava-med] LLaVA_Med_7B VGMED ==="
|
| 27 |
+
conda run --no-capture-output -n llava-med bash eval_scripts/grounding/mask_text/mask_text_VGMED_LLaVA_Med_7B.sh
|
| 28 |
+
echo "=== [huatuogpt] HuatuoGPT_V_7B COCO ==="
|
| 29 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/mask_text/mask_text_COCO_HuatuoGPT_V_7B.sh
|
| 30 |
+
echo "=== [huatuogpt] HuatuoGPT_V_7B VGMED ==="
|
| 31 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/mask_text/mask_text_VGMED_HuatuoGPT_V_7B.sh
|
| 32 |
+
echo "=== [gemma] MedGemma_4B_IT COCO ==="
|
| 33 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/mask_text/mask_text_COCO_MedGemma_4B_IT.sh
|
| 34 |
+
echo "=== [gemma] MedGemma_4B_IT VGMED ==="
|
| 35 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/mask_text/mask_text_VGMED_MedGemma_4B_IT.sh
|
| 36 |
+
|
| 37 |
+
# ── Oversized models (run last; failures here don't block anything above) ──
|
| 38 |
+
echo "=== [qianwen] Qwen25VL_32B COCO ==="
|
| 39 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/mask_text/mask_text_COCO_Qwen25VL_32B.sh
|
| 40 |
+
echo "=== [qianwen] Qwen25VL_32B VGMED ==="
|
| 41 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/grounding/mask_text/mask_text_VGMED_Qwen25VL_32B.sh
|
| 42 |
+
echo "=== [huatuogpt] HuatuoGPT_V_34B COCO ==="
|
| 43 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/mask_text/mask_text_COCO_HuatuoGPT_V_34B.sh
|
| 44 |
+
echo "=== [huatuogpt] HuatuoGPT_V_34B VGMED ==="
|
| 45 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/grounding/mask_text/mask_text_VGMED_HuatuoGPT_V_34B.sh
|
| 46 |
+
echo "=== [gemma] MedGemma_27B_IT COCO ==="
|
| 47 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/mask_text/mask_text_COCO_MedGemma_27B_IT.sh
|
| 48 |
+
echo "=== [gemma] MedGemma_27B_IT VGMED ==="
|
| 49 |
+
conda run --no-capture-output -n gemma bash eval_scripts/grounding/mask_text/mask_text_VGMED_MedGemma_27B_IT.sh
|
| 50 |
+
|
| 51 |
+
echo "All mask_text jobs finished."
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/eval_scripts/run_all_measure_attention.sh
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# GPU2: measure_attention for all models (sequential, MedGemma last)
|
| 3 |
+
# Env: qianwen -> llava-natural -> llava-med -> huatuogpt -> gemma
|
| 4 |
+
# Oversized models (32B/34B/27B-IT) are pushed to the very end, after every
|
| 5 |
+
# normal-size model has finished, so a stuck/OOM large model never blocks them.
|
| 6 |
+
export CUDA_VISIBLE_DEVICES=0
|
| 7 |
+
cd "$(dirname "$0")/.."
|
| 8 |
+
|
| 9 |
+
echo "=== [qianwen] Qwen25VL_7B COCO ==="
|
| 10 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/measure_attention/measure_attention_COCO_Qwen25VL_7B.sh
|
| 11 |
+
echo "=== [qianwen] Qwen25VL_7B VGMED ==="
|
| 12 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/measure_attention/measure_attention_VGMED_Qwen25VL_7B.sh
|
| 13 |
+
echo "=== [qianwen] Qwen25VL_3B COCO ==="
|
| 14 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/measure_attention/measure_attention_COCO_Qwen25VL_3B.sh
|
| 15 |
+
echo "=== [qianwen] Qwen25VL_3B VGMED ==="
|
| 16 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/measure_attention/measure_attention_VGMED_Qwen25VL_3B.sh
|
| 17 |
+
echo "=== [llava-natural] LLaVA_7B COCO ==="
|
| 18 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/measure_attention/measure_attention_COCO_LLaVA_7B.sh
|
| 19 |
+
echo "=== [llava-natural] LLaVA_7B VGMED ==="
|
| 20 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/measure_attention/measure_attention_VGMED_LLaVA_7B.sh
|
| 21 |
+
echo "=== [llava-natural] LLaVA_13B COCO ==="
|
| 22 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/measure_attention/measure_attention_COCO_LLaVA_13B.sh
|
| 23 |
+
echo "=== [llava-natural] LLaVA_13B VGMED ==="
|
| 24 |
+
conda run --no-capture-output -n llava-natural bash eval_scripts/measure_attention/measure_attention_VGMED_LLaVA_13B.sh
|
| 25 |
+
echo "=== [llava-med] LLaVA_Med_7B COCO ==="
|
| 26 |
+
conda run --no-capture-output -n llava-med bash eval_scripts/measure_attention/measure_attention_COCO_LLaVA_Med_7B.sh
|
| 27 |
+
echo "=== [llava-med] LLaVA_Med_7B VGMED ==="
|
| 28 |
+
conda run --no-capture-output -n llava-med bash eval_scripts/measure_attention/measure_attention_VGMED_LLaVA_Med_7B.sh
|
| 29 |
+
echo "=== [huatuogpt] HuatuoGPT_V_7B COCO ==="
|
| 30 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/measure_attention/measure_attention_COCO_HuatuoGPT_V_7B.sh
|
| 31 |
+
echo "=== [huatuogpt] HuatuoGPT_V_7B VGMED ==="
|
| 32 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/measure_attention/measure_attention_VGMED_HuatuoGPT_V_7B.sh
|
| 33 |
+
echo "=== [gemma] MedGemma_4B_IT COCO ==="
|
| 34 |
+
conda run --no-capture-output -n gemma bash eval_scripts/measure_attention/measure_attention_COCO_MedGemma_4B_IT.sh
|
| 35 |
+
echo "=== [gemma] MedGemma_4B_IT VGMED ==="
|
| 36 |
+
conda run --no-capture-output -n gemma bash eval_scripts/measure_attention/measure_attention_VGMED_MedGemma_4B_IT.sh
|
| 37 |
+
|
| 38 |
+
# ── Oversized models (run last; failures here don't block anything above) ──
|
| 39 |
+
echo "=== [qianwen] Qwen25VL_32B COCO ==="
|
| 40 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/measure_attention/measure_attention_COCO_Qwen25VL_32B.sh
|
| 41 |
+
echo "=== [qianwen] Qwen25VL_32B VGMED ==="
|
| 42 |
+
conda run --no-capture-output -n qianwen bash eval_scripts/measure_attention/measure_attention_VGMED_Qwen25VL_32B.sh
|
| 43 |
+
echo "=== [huatuogpt] HuatuoGPT_V_34B COCO ==="
|
| 44 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/measure_attention/measure_attention_COCO_HuatuoGPT_V_34B.sh
|
| 45 |
+
echo "=== [huatuogpt] HuatuoGPT_V_34B VGMED ==="
|
| 46 |
+
conda run --no-capture-output -n huatuogpt bash eval_scripts/measure_attention/measure_attention_VGMED_HuatuoGPT_V_34B.sh
|
| 47 |
+
echo "=== [gemma] MedGemma_27B_IT COCO ==="
|
| 48 |
+
conda run --no-capture-output -n gemma bash eval_scripts/measure_attention/measure_attention_COCO_MedGemma_27B_IT.sh
|
| 49 |
+
echo "=== [gemma] MedGemma_27B_IT VGMED ==="
|
| 50 |
+
conda run --no-capture-output -n gemma bash eval_scripts/measure_attention/measure_attention_VGMED_MedGemma_27B_IT.sh
|
| 51 |
+
|
| 52 |
+
echo "All measure_attention jobs finished."
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/.ipynb_checkpoints/HealthGPT-checkpoint.py
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, sys
|
| 2 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
| 3 |
+
import torch
|
| 4 |
+
import transformers
|
| 5 |
+
import tokenizers
|
| 6 |
+
|
| 7 |
+
from PIL import Image
|
| 8 |
+
from tqdm import tqdm
|
| 9 |
+
from packaging import version
|
| 10 |
+
IS_TOKENIZER_GREATER_THAN_0_14 = version.parse(tokenizers.__version__) >= version.parse('0.14')
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
from .llava import conversation as conversation_lib
|
| 14 |
+
from .llava.model import *
|
| 15 |
+
from .llava.mm_utils import tokenizer_image_token,process_images
|
| 16 |
+
from .llava.model.language_model.llava_phi3 import LlavaPhiForCausalLM, LlavaPhiConfig
|
| 17 |
+
|
| 18 |
+
from .utils import find_all_linear_names, add_special_tokens_and_resize_model, load_weights, expand2square,com_vision_args
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class HealthGPT:
|
| 22 |
+
def __init__(self,model_path,args):
|
| 23 |
+
super().__init__()
|
| 24 |
+
self.llm = LlavaQwen2ForCausalLM.from_pretrained(
|
| 25 |
+
pretrained_model_name_or_path = model_path,
|
| 26 |
+
attn_implementation="flash_attention_2",
|
| 27 |
+
torch_dtype= torch.float16,
|
| 28 |
+
device_map="cuda"
|
| 29 |
+
)
|
| 30 |
+
from .llava.peft import LoraConfig, get_peft_model
|
| 31 |
+
print("load model done")
|
| 32 |
+
lora_config = LoraConfig(
|
| 33 |
+
r= 32,
|
| 34 |
+
lora_alpha=64,
|
| 35 |
+
target_modules=find_all_linear_names(self.llm),
|
| 36 |
+
lora_dropout=0.0,
|
| 37 |
+
bias='none',
|
| 38 |
+
task_type="CAUSAL_LM",
|
| 39 |
+
lora_nums=4,
|
| 40 |
+
)
|
| 41 |
+
self.llm = get_peft_model(self.llm, lora_config)
|
| 42 |
+
print("load lora done")
|
| 43 |
+
|
| 44 |
+
self.tokenizer = transformers.AutoTokenizer.from_pretrained(
|
| 45 |
+
model_path,
|
| 46 |
+
padding_side="right",
|
| 47 |
+
use_fast=False,
|
| 48 |
+
)
|
| 49 |
+
if self.tokenizer.unk_token:
|
| 50 |
+
self.tokenizer.pad_token = tokenizer.unk_token
|
| 51 |
+
else:
|
| 52 |
+
self.tokenizer.legacy = False
|
| 53 |
+
print("load tokenizer done")
|
| 54 |
+
|
| 55 |
+
from .utils import com_vision_args
|
| 56 |
+
com_vision_args.model_name_or_path = model_path
|
| 57 |
+
com_vision_args.vision_tower = '/mnt/workspace/workgroup_dev/longli/models/hub/clip-vit-large-patch14-336'
|
| 58 |
+
com_vision_args.version = "qwen_2"
|
| 59 |
+
|
| 60 |
+
self.llm.get_model().initialize_vision_modules(model_args=com_vision_args)
|
| 61 |
+
self.llm.get_vision_tower().to(dtype=torch.float16)
|
| 62 |
+
self.llm.get_model().mm_projector.to(dtype=torch.float16)
|
| 63 |
+
print("load vision tower done")
|
| 64 |
+
|
| 65 |
+
self.llm = load_weights(self.llm, "/mnt/workspace/workgroup_dev/longli/models/hub/HealthGPT-XL32/com_hlora_weights_QWEN_32B.bin")
|
| 66 |
+
print("load weights done")
|
| 67 |
+
self.llm.eval()
|
| 68 |
+
self.llm.to(dtype=torch.float16).cuda()
|
| 69 |
+
|
| 70 |
+
self.temperature = args.temperature
|
| 71 |
+
self.top_p = args.top_p
|
| 72 |
+
self.repetition_penalty = args.repetition_penalty
|
| 73 |
+
self.max_tokens = args.max_new_tokens
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def process_messages(self,messages):
|
| 77 |
+
conv = conversation_lib.conv_templates["qwen_2"].copy()
|
| 78 |
+
conv.messages = []
|
| 79 |
+
if "system" in messages:
|
| 80 |
+
conv.system = messages["system"]
|
| 81 |
+
|
| 82 |
+
imgs = []
|
| 83 |
+
if "image" in messages:
|
| 84 |
+
image = messages["image"]
|
| 85 |
+
if isinstance(image,str):
|
| 86 |
+
image = Image.open(image).convert('RGB')
|
| 87 |
+
elif isinstance(image,Image.Image):
|
| 88 |
+
image = image.convert('RGB')
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
imgs.append(image)
|
| 92 |
+
prompt = DEFAULT_IMAGE_TOKEN + '\n' + messages["prompt"]
|
| 93 |
+
elif "images" in messages:
|
| 94 |
+
images = messages["images"]
|
| 95 |
+
prompt = ""
|
| 96 |
+
for i,image in enumerate(images):
|
| 97 |
+
prompt += f"<image_{i+1}>: " + DEFAULT_IMAGE_TOKEN + '\n'
|
| 98 |
+
if isinstance(image,str):
|
| 99 |
+
if os.path.exists(image):
|
| 100 |
+
image = Image.open(image)
|
| 101 |
+
elif isinstance(image,Image.Image):
|
| 102 |
+
image = image.convert("RGB")
|
| 103 |
+
imgs.append(image)
|
| 104 |
+
prompt += messages["prompt"]
|
| 105 |
+
else:
|
| 106 |
+
prompt = messages["prompt"]
|
| 107 |
+
conv.append_message(conv.roles[0],prompt)
|
| 108 |
+
conv.append_message(conv.roles[1],None)
|
| 109 |
+
prompt = conv.get_prompt()
|
| 110 |
+
imgs = None if len(imgs) == 0 else imgs
|
| 111 |
+
return prompt,imgs
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def generate_output(self,messages):
|
| 115 |
+
prompt,imgs = self.process_messages(messages)
|
| 116 |
+
if imgs:
|
| 117 |
+
# imgs = imgs[0]
|
| 118 |
+
input_ids = tokenizer_image_token(prompt, self.tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze_(0).cuda()
|
| 119 |
+
imgs = [expand2square(img, tuple(int(x*255) for x in self.llm.get_vision_tower().image_processor.image_mean)) for img in imgs]
|
| 120 |
+
imgs = self.llm.get_vision_tower().image_processor.preprocess(imgs, return_tensors='pt')['pixel_values'].to(dtype=torch.float16, device='cuda', non_blocking=True)
|
| 121 |
+
# imgs = process_images(imgs,self.llm.get_vision_tower().image_processor,self.llm.config)
|
| 122 |
+
else:
|
| 123 |
+
input_ids = tokenizer_image_token(prompt, self.tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze_(0).cuda()
|
| 124 |
+
imgs = None
|
| 125 |
+
|
| 126 |
+
with torch.inference_mode():
|
| 127 |
+
do_sample = False if self.temperature == 0 else True
|
| 128 |
+
output_ids = self.llm.base_model.model.generate(input_ids,images=imgs,do_sample=do_sample,num_beams=5,max_new_tokens=self.max_tokens,temperature = self.temperature,top_p = self.top_p,repetition_penalty = self.repetition_penalty,use_cache=True)
|
| 129 |
+
|
| 130 |
+
outputs = self.tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
|
| 131 |
+
return outputs
|
| 132 |
+
|
| 133 |
+
def generate_outputs(self,messages_list):
|
| 134 |
+
outputs = []
|
| 135 |
+
for messages in tqdm(messages_list):
|
| 136 |
+
output = self.generate_output(messages)
|
| 137 |
+
outputs.append(output)
|
| 138 |
+
return outputs
|
| 139 |
+
|
| 140 |
+
if __name__ == '__main__':
|
| 141 |
+
# def construct_messages(sample):
|
| 142 |
+
# question = sample["question"]
|
| 143 |
+
# image = sample["image"]
|
| 144 |
+
# answer = sample["answer"]
|
| 145 |
+
# if answer in ["yes","no"]:
|
| 146 |
+
# question += "Please output 'yes' or 'no'(no extra output)"
|
| 147 |
+
# if os.environ.get("STRICT_PROMPT","False") == "True":
|
| 148 |
+
# question += "Wrap your final answer between <answer> and </answer>, for example: <answer>yes</answer>"
|
| 149 |
+
# else:
|
| 150 |
+
# question += 'Answer the question concisely(Keep it short and concise).'
|
| 151 |
+
# if os.environ.get("STRICT_PROMPT","False") == "True":
|
| 152 |
+
# question += "Wrap your final answer between <answer> and </answer>, for example: <answer>positive influence</answer>"
|
| 153 |
+
# messages = {"prompt":question,"image":image}
|
| 154 |
+
# sample["messages"] = messages
|
| 155 |
+
# return sample
|
| 156 |
+
|
| 157 |
+
# from datasets import load_dataset
|
| 158 |
+
# from tqdm import tqdm
|
| 159 |
+
# dataset = load_dataset("/mnt/workspace/workgroup_dev/longli/MedLLMBenchmarks/benchmarks/VQA_RAD",split="test")
|
| 160 |
+
|
| 161 |
+
# llm = HealthGPT()
|
| 162 |
+
# for data in tqdm(dataset):
|
| 163 |
+
# data = construct_messages(data)
|
| 164 |
+
# image = data["image"]
|
| 165 |
+
# messages = {"prompt":data["question"],"image":image}
|
| 166 |
+
# result = llm.generate_output(messages)
|
| 167 |
+
|
| 168 |
+
llm = HealthGPT()
|
| 169 |
+
image = "/mnt/workspace/workgroup_dev/longli/MedLLMBenchmarks/benchmarks/OmniMedVQA/Images/ACRIMA/Im553_g_ACRIMA.png"
|
| 170 |
+
image2 = "/mnt/workspace/workgroup_dev/longli/MedLLMBenchmarks/benchmarks/OmniMedVQA/Images/BreakHis/benign/SOB_B_A-14-22549AB-40-005.png"
|
| 171 |
+
messages = [{ 'images': [image,image2],"prompt":"\nQuestion: 你是一个医疗助手,我的问题是这两张图片里的内容是什么?"}]
|
| 172 |
+
result = llm.generate_outputs(messages)
|
| 173 |
+
print("result:",result)
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/.ipynb_checkpoints/HealthGPT_phi-checkpoint.py
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, sys
|
| 2 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
| 3 |
+
import torch
|
| 4 |
+
import transformers
|
| 5 |
+
import tokenizers
|
| 6 |
+
|
| 7 |
+
from PIL import Image
|
| 8 |
+
from tqdm import tqdm
|
| 9 |
+
from packaging import version
|
| 10 |
+
IS_TOKENIZER_GREATER_THAN_0_14 = version.parse(tokenizers.__version__) >= version.parse('0.14')
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
from .llava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN
|
| 14 |
+
from .llava.peft import LoraConfig, get_peft_model
|
| 15 |
+
from .llava import conversation as conversation_lib
|
| 16 |
+
from .llava.model import *
|
| 17 |
+
from .llava.mm_utils import tokenizer_image_token,process_images
|
| 18 |
+
from .llava.model.language_model.llava_phi3 import LlavaPhiForCausalLM
|
| 19 |
+
from .utils import find_all_linear_names, add_special_tokens_and_resize_model, load_weights, expand2square,com_vision_args
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class HealthGPT:
|
| 23 |
+
def __init__(self,model_path,args):
|
| 24 |
+
super().__init__()
|
| 25 |
+
self.llm = LlavaPhiForCausalLM.from_pretrained(
|
| 26 |
+
pretrained_model_name_or_path = model_path,
|
| 27 |
+
attn_implementation="flash_attention_2",
|
| 28 |
+
torch_dtype= torch.float16,
|
| 29 |
+
device_map="cuda"
|
| 30 |
+
)
|
| 31 |
+
print("load model done")
|
| 32 |
+
lora_config = LoraConfig(
|
| 33 |
+
r= 32,
|
| 34 |
+
lora_alpha=64,
|
| 35 |
+
target_modules=find_all_linear_names(self.llm),
|
| 36 |
+
lora_dropout=0.0,
|
| 37 |
+
bias='none',
|
| 38 |
+
task_type="CAUSAL_LM",
|
| 39 |
+
lora_nums=4,
|
| 40 |
+
)
|
| 41 |
+
self.llm = get_peft_model(self.llm, lora_config)
|
| 42 |
+
print("load lora done")
|
| 43 |
+
|
| 44 |
+
self.tokenizer = transformers.AutoTokenizer.from_pretrained(
|
| 45 |
+
model_path,
|
| 46 |
+
padding_side="right",
|
| 47 |
+
use_fast=False,
|
| 48 |
+
)
|
| 49 |
+
print("load tokenizer done")
|
| 50 |
+
|
| 51 |
+
num_new_tokens = add_special_tokens_and_resize_model(self.tokenizer, self.llm, 8192)
|
| 52 |
+
print(f"Number of new tokens added for unified task: {num_new_tokens}")
|
| 53 |
+
|
| 54 |
+
com_vision_args.model_name_or_path = model_path
|
| 55 |
+
com_vision_args.vision_tower = '/mnt/workspace/workgroup_dev/longli/models/hub/clip-vit-large-patch14-336'
|
| 56 |
+
com_vision_args.version = "phi4_instruct"
|
| 57 |
+
|
| 58 |
+
self.llm.get_model().initialize_vision_modules(model_args=com_vision_args)
|
| 59 |
+
self.llm.get_vision_tower().to(dtype=torch.float16)
|
| 60 |
+
self.llm.get_model().mm_projector.to(dtype=torch.float16)
|
| 61 |
+
print("load vision tower done")
|
| 62 |
+
|
| 63 |
+
self.llm = load_weights(self.llm, "/mnt/workspace/workgroup_dev/longli/models/hub/HealthGPT-L14/com_hlora_weights_phi4.bin")
|
| 64 |
+
print("load weights done")
|
| 65 |
+
self.llm.eval()
|
| 66 |
+
self.llm.to(dtype=torch.float16).cuda()
|
| 67 |
+
|
| 68 |
+
self.temperature = args.temperature
|
| 69 |
+
self.top_p = args.top_p
|
| 70 |
+
self.repetition_penalty = args.repetition_penalty
|
| 71 |
+
self.max_tokens = args.max_new_tokens
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def process_messages(self,messages):
|
| 75 |
+
conv = conversation_lib.conv_templates["phi4_instruct"].copy()
|
| 76 |
+
conv.messages = []
|
| 77 |
+
if "system" in messages:
|
| 78 |
+
conv.system = messages["system"]
|
| 79 |
+
|
| 80 |
+
imgs = []
|
| 81 |
+
if "image" in messages:
|
| 82 |
+
image = messages["image"]
|
| 83 |
+
if isinstance(image,str):
|
| 84 |
+
image = Image.open(image).convert('RGB')
|
| 85 |
+
elif isinstance(image,Image.Image):
|
| 86 |
+
image = image.convert('RGB')
|
| 87 |
+
imgs.append(image)
|
| 88 |
+
prompt = DEFAULT_IMAGE_TOKEN + '\n' + messages["prompt"]
|
| 89 |
+
elif "images" in messages:
|
| 90 |
+
images = messages["images"]
|
| 91 |
+
prompt = ""
|
| 92 |
+
for i,image in enumerate(images):
|
| 93 |
+
prompt += f"<image_{i+1}>: " + DEFAULT_IMAGE_TOKEN + '\n'
|
| 94 |
+
if isinstance(image,str):
|
| 95 |
+
if os.path.exists(image):
|
| 96 |
+
image = Image.open(image)
|
| 97 |
+
elif isinstance(image,Image.Image):
|
| 98 |
+
image = image.convert("RGB")
|
| 99 |
+
imgs.append(image)
|
| 100 |
+
prompt += messages["prompt"]
|
| 101 |
+
else:
|
| 102 |
+
prompt = messages["prompt"]
|
| 103 |
+
conv.append_message(conv.roles[0],prompt)
|
| 104 |
+
conv.append_message(conv.roles[1],None)
|
| 105 |
+
prompt = conv.get_prompt()
|
| 106 |
+
imgs = None if len(imgs) == 0 else imgs
|
| 107 |
+
return prompt,imgs
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def generate_output(self,messages):
|
| 111 |
+
prompt,imgs = self.process_messages(messages)
|
| 112 |
+
if imgs:
|
| 113 |
+
# imgs = imgs[0]
|
| 114 |
+
input_ids = tokenizer_image_token(prompt, self.tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze_(0).cuda()
|
| 115 |
+
imgs = [expand2square(img, tuple(int(x*255) for x in self.llm.get_vision_tower().image_processor.image_mean)) for img in imgs]
|
| 116 |
+
imgs = self.llm.get_vision_tower().image_processor.preprocess(imgs, return_tensors='pt')['pixel_values'].to(dtype=torch.float16, device='cuda', non_blocking=True)
|
| 117 |
+
# imgs = process_images(imgs,self.llm.get_vision_tower().image_processor,self.llm.config)
|
| 118 |
+
else:
|
| 119 |
+
input_ids = tokenizer_image_token(prompt, self.tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze_(0).cuda()
|
| 120 |
+
imgs = None
|
| 121 |
+
|
| 122 |
+
with torch.inference_mode():
|
| 123 |
+
do_sample = False if self.temperature == 0 else True
|
| 124 |
+
output_ids = self.llm.base_model.model.generate(input_ids,images=imgs,do_sample=do_sample,num_beams=5,max_new_tokens=self.max_tokens,temperature = self.temperature,top_p = self.top_p,repetition_penalty = self.repetition_penalty,use_cache=True)
|
| 125 |
+
|
| 126 |
+
outputs = self.tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
|
| 127 |
+
return outputs
|
| 128 |
+
|
| 129 |
+
def generate_outputs(self,messages_list):
|
| 130 |
+
outputs = []
|
| 131 |
+
for messages in tqdm(messages_list):
|
| 132 |
+
output = self.generate_output(messages)
|
| 133 |
+
outputs.append(output)
|
| 134 |
+
return outputs
|
| 135 |
+
|
| 136 |
+
if __name__ == '__main__':
|
| 137 |
+
# def construct_messages(sample):
|
| 138 |
+
# question = sample["question"]
|
| 139 |
+
# image = sample["image"]
|
| 140 |
+
# answer = sample["answer"]
|
| 141 |
+
# if answer in ["yes","no"]:
|
| 142 |
+
# question += "Please output 'yes' or 'no'(no extra output)"
|
| 143 |
+
# if os.environ.get("STRICT_PROMPT","False") == "True":
|
| 144 |
+
# question += "Wrap your final answer between <answer> and </answer>, for example: <answer>yes</answer>"
|
| 145 |
+
# else:
|
| 146 |
+
# question += 'Answer the question concisely(Keep it short and concise).'
|
| 147 |
+
# if os.environ.get("STRICT_PROMPT","False") == "True":
|
| 148 |
+
# question += "Wrap your final answer between <answer> and </answer>, for example: <answer>positive influence</answer>"
|
| 149 |
+
# messages = {"prompt":question,"image":image}
|
| 150 |
+
# sample["messages"] = messages
|
| 151 |
+
# return sample
|
| 152 |
+
|
| 153 |
+
# from datasets import load_dataset
|
| 154 |
+
# from tqdm import tqdm
|
| 155 |
+
# dataset = load_dataset("/mnt/workspace/workgroup_dev/longli/MedLLMBenchmarks/benchmarks/VQA_RAD",split="test")
|
| 156 |
+
|
| 157 |
+
# llm = HealthGPT()
|
| 158 |
+
# for data in tqdm(dataset):
|
| 159 |
+
# data = construct_messages(data)
|
| 160 |
+
# image = data["image"]
|
| 161 |
+
# messages = {"prompt":data["question"],"image":image}
|
| 162 |
+
# result = llm.generate_output(messages)
|
| 163 |
+
|
| 164 |
+
llm = HealthGPT()
|
| 165 |
+
image = "/mnt/workspace/workgroup_dev/longli/MedLLMBenchmarks/benchmarks/OmniMedVQA/Images/ACRIMA/Im553_g_ACRIMA.png"
|
| 166 |
+
image2 = "/mnt/workspace/workgroup_dev/longli/MedLLMBenchmarks/benchmarks/OmniMedVQA/Images/BreakHis/benign/SOB_B_A-14-22549AB-40-005.png"
|
| 167 |
+
messages = [{ 'images': [image,image2],"prompt":"\nQuestion: 你是一个医疗助手,我的问题是这两张图片里的内容是什么?"}]
|
| 168 |
+
result = llm.generate_outputs(messages)
|
| 169 |
+
print("result:",result)
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/llava/demo/com_infer.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, sys
|
| 2 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
| 3 |
+
|
| 4 |
+
import copy
|
| 5 |
+
from dataclasses import dataclass, field
|
| 6 |
+
import json
|
| 7 |
+
import logging
|
| 8 |
+
import pathlib
|
| 9 |
+
from typing import Dict, Optional, Sequence, List
|
| 10 |
+
import torch
|
| 11 |
+
import transformers
|
| 12 |
+
import tokenizers
|
| 13 |
+
from llava.constants import IGNORE_INDEX, IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN
|
| 14 |
+
from torch.utils.data import Dataset
|
| 15 |
+
|
| 16 |
+
from llava import conversation as conversation_lib
|
| 17 |
+
from llava.model import *
|
| 18 |
+
from llava.mm_utils import tokenizer_image_token
|
| 19 |
+
from llava.model.language_model.llava_phi3 import LlavaPhiForCausalLM, LlavaPhiConfig
|
| 20 |
+
from PIL import Image
|
| 21 |
+
import pickle
|
| 22 |
+
import argparse
|
| 23 |
+
from packaging import version
|
| 24 |
+
IS_TOKENIZER_GREATER_THAN_0_14 = version.parse(tokenizers.__version__) >= version.parse('0.14')
|
| 25 |
+
from utils import find_all_linear_names, add_special_tokens_and_resize_model, load_weights, expand2square
|
| 26 |
+
|
| 27 |
+
def infer():
|
| 28 |
+
parser = argparse.ArgumentParser()
|
| 29 |
+
parser.add_argument('--model_name_or_path', type=str, default='microsoft/Phi-3-mini-4k-instruct')
|
| 30 |
+
parser.add_argument('--dtype', type=str, default='FP32')
|
| 31 |
+
parser.add_argument('--attn_implementation', type=str, default=None)
|
| 32 |
+
parser.add_argument('--hlora_r', type=int, default=16)
|
| 33 |
+
parser.add_argument('--hlora_alpha', type=int, default=32)
|
| 34 |
+
parser.add_argument('--hlora_dropout', type=float, default=0.0)
|
| 35 |
+
parser.add_argument('--hlora_nums', type=int, default=4)
|
| 36 |
+
parser.add_argument('--vq_idx_nums', type=int, default=1024)
|
| 37 |
+
parser.add_argument('--instruct_template', type=str, default='phi3_instruct')
|
| 38 |
+
parser.add_argument('--vit_path', type=str, default='openai/clip-vit-large-patch14-336')
|
| 39 |
+
parser.add_argument('--hlora_path', type=str, default=None)
|
| 40 |
+
parser.add_argument('--fusion_layer_path', type=str, default=None)
|
| 41 |
+
parser.add_argument('--question', type=str, default=None)
|
| 42 |
+
parser.add_argument('--img_path', type=str, default=None)
|
| 43 |
+
parser.add_argument('--do_sample', type=bool, default=False)
|
| 44 |
+
parser.add_argument('--temperature', type=float, default=0.0)
|
| 45 |
+
parser.add_argument('--top_p', type=float, default=None)
|
| 46 |
+
parser.add_argument('--num_beams', type=int, default=1)
|
| 47 |
+
parser.add_argument('--max_new_tokens', type=int, default=1024)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
args = parser.parse_args()
|
| 52 |
+
|
| 53 |
+
model_dtype = torch.float32 if args.dtype == 'FP32' else (torch.float16 if args.dtype == 'FP16' else torch.bfloat16)
|
| 54 |
+
|
| 55 |
+
model = LlavaPhiForCausalLM.from_pretrained(
|
| 56 |
+
pretrained_model_name_or_path=args.model_name_or_path,
|
| 57 |
+
attn_implementation=args.attn_implementation,
|
| 58 |
+
torch_dtype=model_dtype
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
from llava.peft import LoraConfig, get_peft_model
|
| 62 |
+
lora_config = LoraConfig(
|
| 63 |
+
r=args.hlora_r,
|
| 64 |
+
lora_alpha=args.hlora_alpha,
|
| 65 |
+
target_modules=find_all_linear_names(model),
|
| 66 |
+
lora_dropout=args.hlora_dropout,
|
| 67 |
+
bias='none',
|
| 68 |
+
task_type="CAUSAL_LM",
|
| 69 |
+
lora_nums=args.hlora_nums,
|
| 70 |
+
)
|
| 71 |
+
model = get_peft_model(model, lora_config)
|
| 72 |
+
|
| 73 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(
|
| 74 |
+
args.model_name_or_path,
|
| 75 |
+
padding_side="right",
|
| 76 |
+
use_fast=False,
|
| 77 |
+
)
|
| 78 |
+
num_new_tokens = add_special_tokens_and_resize_model(tokenizer, model, args.vq_idx_nums)
|
| 79 |
+
print(f"Number of new tokens added for unified task: {num_new_tokens}")
|
| 80 |
+
|
| 81 |
+
from utils import com_vision_args
|
| 82 |
+
com_vision_args.model_name_or_path = args.model_name_or_path
|
| 83 |
+
com_vision_args.vision_tower = args.vit_path
|
| 84 |
+
com_vision_args.version = args.instruct_template
|
| 85 |
+
|
| 86 |
+
model.get_model().initialize_vision_modules(model_args=com_vision_args)
|
| 87 |
+
model.get_vision_tower().to(dtype=model_dtype)
|
| 88 |
+
|
| 89 |
+
model = load_weights(model, args.hlora_path)
|
| 90 |
+
model.eval()
|
| 91 |
+
model.to(model_dtype).cuda()
|
| 92 |
+
|
| 93 |
+
question = args.question
|
| 94 |
+
img_path = args.img_path
|
| 95 |
+
|
| 96 |
+
if img_path:
|
| 97 |
+
qs = DEFAULT_IMAGE_TOKEN + '\n' + question
|
| 98 |
+
else:
|
| 99 |
+
qs = question
|
| 100 |
+
conv = conversation_lib.conv_templates[args.instruct_template].copy()
|
| 101 |
+
conv.append_message(conv.roles[0], qs)
|
| 102 |
+
conv.append_message(conv.roles[1], None)
|
| 103 |
+
prompt = conv.get_prompt()
|
| 104 |
+
input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').cuda().unsqueeze_(0)
|
| 105 |
+
if img_path:
|
| 106 |
+
image = Image.open(img_path).convert('RGB')
|
| 107 |
+
image = expand2square(image, tuple(int(x*255) for x in model.get_vision_tower().image_processor.image_mean))
|
| 108 |
+
image_tensor = model.get_vision_tower().image_processor.preprocess(image, return_tensors='pt')['pixel_values'][0].unsqueeze_(0)
|
| 109 |
+
with torch.inference_mode():
|
| 110 |
+
output_ids = model.base_model.model.generate(
|
| 111 |
+
input_ids,
|
| 112 |
+
images=image_tensor.to(dtype=model_dtype, device='cuda', non_blocking=True) if img_path else None,
|
| 113 |
+
image_sizes=image.size if img_path else None,
|
| 114 |
+
do_sample=args.do_sample,
|
| 115 |
+
temperature=args.temperature,
|
| 116 |
+
top_p=args.top_p,
|
| 117 |
+
num_beams=args.num_beams,
|
| 118 |
+
max_new_tokens=args.max_new_tokens,
|
| 119 |
+
use_cache=True)
|
| 120 |
+
|
| 121 |
+
response = tokenizer.decode(output_ids[0], skip_special_tokens=True)[:-8]
|
| 122 |
+
print(f'Q: {question}')
|
| 123 |
+
print(f'HealthGPT: {response}')
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
|
| 128 |
+
infer()
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/llava/demo/com_infer_phi4.sh
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
MODEL_NAME_OR_PATH="microsoft/Phi-4"
|
| 4 |
+
VIT_PATH="openai/clip-vit-large-patch14-336/"
|
| 5 |
+
HLORA_PATH="com_hlora_weights_phi4.bin"
|
| 6 |
+
|
| 7 |
+
python3 com_infer_phi4.py \
|
| 8 |
+
--model_name_or_path "$MODEL_NAME_OR_PATH" \
|
| 9 |
+
--dtype "FP16" \
|
| 10 |
+
--hlora_r "32" \
|
| 11 |
+
--hlora_alpha "64" \
|
| 12 |
+
--hlora_nums "4" \
|
| 13 |
+
--vq_idx_nums "8192" \
|
| 14 |
+
--instruct_template "phi4_instruct" \
|
| 15 |
+
--vit_path "$VIT_PATH" \
|
| 16 |
+
--hlora_path "$HLORA_PATH" \
|
| 17 |
+
--question "Your question" \
|
| 18 |
+
--img_path "path/to/image.jpg"
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/llava/demo/gen_infer.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, sys
|
| 2 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
| 3 |
+
|
| 4 |
+
import copy, re
|
| 5 |
+
from dataclasses import dataclass, field
|
| 6 |
+
import json
|
| 7 |
+
import logging
|
| 8 |
+
import pathlib
|
| 9 |
+
from typing import Dict, Optional, Sequence, List
|
| 10 |
+
import torch
|
| 11 |
+
import transformers
|
| 12 |
+
import tokenizers
|
| 13 |
+
from llava.constants import IGNORE_INDEX, IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN
|
| 14 |
+
from torch.utils.data import Dataset
|
| 15 |
+
|
| 16 |
+
from llava import conversation as conversation_lib
|
| 17 |
+
from llava.model import *
|
| 18 |
+
from llava.mm_utils import tokenizer_image_token
|
| 19 |
+
from llava.model.language_model.llava_phi3 import LlavaPhiForCausalLM, LlavaPhiConfig
|
| 20 |
+
from PIL import Image
|
| 21 |
+
import pickle
|
| 22 |
+
import argparse
|
| 23 |
+
from packaging import version
|
| 24 |
+
IS_TOKENIZER_GREATER_THAN_0_14 = version.parse(tokenizers.__version__) >= version.parse('0.14')
|
| 25 |
+
from utils import find_all_linear_names, add_special_tokens_and_resize_model, load_weights, expand2square
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def infer():
|
| 30 |
+
parser = argparse.ArgumentParser()
|
| 31 |
+
parser.add_argument('--model_name_or_path', type=str, default='microsoft/Phi-3-mini-4k-instruct')
|
| 32 |
+
parser.add_argument('--dtype', type=str, default='FP32')
|
| 33 |
+
parser.add_argument('--attn_implementation', type=str, default=None)
|
| 34 |
+
parser.add_argument('--hlora_r', type=int, default=16)
|
| 35 |
+
parser.add_argument('--hlora_alpha', type=int, default=32)
|
| 36 |
+
parser.add_argument('--hlora_dropout', type=float, default=0.0)
|
| 37 |
+
parser.add_argument('--hlora_nums', type=int, default=4)
|
| 38 |
+
parser.add_argument('--vq_idx_nums', type=int, default=1024)
|
| 39 |
+
parser.add_argument('--instruct_template', type=str, default='phi3_instruct')
|
| 40 |
+
parser.add_argument('--vit_path', type=str, default='openai/clip-vit-large-patch14-336')
|
| 41 |
+
parser.add_argument('--hlora_path', type=str, default=None)
|
| 42 |
+
parser.add_argument('--fusion_layer_path', type=str, default=None)
|
| 43 |
+
parser.add_argument('--question', type=str, default=None)
|
| 44 |
+
parser.add_argument('--img_path', type=str, default=None)
|
| 45 |
+
parser.add_argument('--do_sample', type=bool, default=False)
|
| 46 |
+
parser.add_argument('--temperature', type=float, default=0.0)
|
| 47 |
+
parser.add_argument('--top_p', type=float, default=None)
|
| 48 |
+
parser.add_argument('--num_beams', type=int, default=1)
|
| 49 |
+
parser.add_argument('--max_new_tokens', type=int, default=1100)
|
| 50 |
+
parser.add_argument('--save_path', type=str, default='./example.jpg')
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
args = parser.parse_args()
|
| 54 |
+
|
| 55 |
+
model_dtype = torch.float32 if args.dtype == 'FP32' else (torch.float16 if args.dtype == 'FP16' else torch.bfloat16)
|
| 56 |
+
|
| 57 |
+
model = LlavaPhiForCausalLM.from_pretrained(
|
| 58 |
+
pretrained_model_name_or_path=args.model_name_or_path,
|
| 59 |
+
attn_implementation=args.attn_implementation,
|
| 60 |
+
torch_dtype=model_dtype
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
from llava.peft import LoraConfig, get_peft_model
|
| 64 |
+
lora_config = LoraConfig(
|
| 65 |
+
r=args.hlora_r,
|
| 66 |
+
lora_alpha=args.hlora_alpha,
|
| 67 |
+
target_modules=find_all_linear_names(model),
|
| 68 |
+
lora_dropout=args.hlora_dropout,
|
| 69 |
+
bias='none',
|
| 70 |
+
task_type="CAUSAL_LM",
|
| 71 |
+
lora_nums=args.hlora_nums,
|
| 72 |
+
)
|
| 73 |
+
model = get_peft_model(model, lora_config)
|
| 74 |
+
|
| 75 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(
|
| 76 |
+
args.model_name_or_path,
|
| 77 |
+
padding_side="right",
|
| 78 |
+
use_fast=False,
|
| 79 |
+
)
|
| 80 |
+
num_new_tokens = add_special_tokens_and_resize_model(tokenizer, model, args.vq_idx_nums)
|
| 81 |
+
print(f"Number of new tokens added for unified task: {num_new_tokens}")
|
| 82 |
+
|
| 83 |
+
from utils import gen_vision_args
|
| 84 |
+
gen_vision_args.model_name_or_path = args.model_name_or_path
|
| 85 |
+
gen_vision_args.vision_tower = args.vit_path
|
| 86 |
+
gen_vision_args.version = args.instruct_template
|
| 87 |
+
|
| 88 |
+
model.get_model().initialize_vision_modules(model_args=gen_vision_args)
|
| 89 |
+
model.get_vision_tower().to(dtype=model_dtype)
|
| 90 |
+
|
| 91 |
+
model = load_weights(model, args.hlora_path, args.fusion_layer_path)
|
| 92 |
+
model.eval()
|
| 93 |
+
model.to(model_dtype).cuda()
|
| 94 |
+
|
| 95 |
+
from taming_transformers.idx2img import idx2img
|
| 96 |
+
|
| 97 |
+
question = args.question
|
| 98 |
+
img_path = args.img_path
|
| 99 |
+
|
| 100 |
+
if img_path:
|
| 101 |
+
qs = DEFAULT_IMAGE_TOKEN + '\n' + question
|
| 102 |
+
else:
|
| 103 |
+
qs = question
|
| 104 |
+
conv = conversation_lib.conv_templates[args.instruct_template].copy()
|
| 105 |
+
conv.append_message(conv.roles[0], qs)
|
| 106 |
+
conv.append_message(conv.roles[1], None)
|
| 107 |
+
prompt = conv.get_prompt() + '<start_index>'
|
| 108 |
+
input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').cuda().unsqueeze_(0)
|
| 109 |
+
if img_path:
|
| 110 |
+
image = Image.open(img_path).convert('RGB')
|
| 111 |
+
image = expand2square(image, tuple(int(x*255) for x in model.get_vision_tower().image_processor.image_mean))
|
| 112 |
+
image_tensor = model.get_vision_tower().image_processor.preprocess(image, return_tensors='pt')['pixel_values'][0].unsqueeze_(0)
|
| 113 |
+
with torch.inference_mode():
|
| 114 |
+
output_ids = model.base_model.model.generate(
|
| 115 |
+
input_ids,
|
| 116 |
+
images=image_tensor.to(dtype=model_dtype, device='cuda', non_blocking=True) if img_path else None,
|
| 117 |
+
image_sizes=image.size if img_path else None,
|
| 118 |
+
do_sample=args.do_sample,
|
| 119 |
+
temperature=args.temperature,
|
| 120 |
+
top_p=args.top_p,
|
| 121 |
+
num_beams=args.num_beams,
|
| 122 |
+
max_new_tokens=args.max_new_tokens,
|
| 123 |
+
use_cache=True)
|
| 124 |
+
|
| 125 |
+
response = [int(idx) for idx in re.findall(r'\d+', tokenizer.decode(output_ids[0])[:-8])]
|
| 126 |
+
print(f'Q: {question}')
|
| 127 |
+
print(f'HealthGPT: {response}')
|
| 128 |
+
idx2img(torch.tensor(response).cuda(), args.save_path)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
if __name__ == "__main__":
|
| 133 |
+
|
| 134 |
+
infer()
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/llava/demo/gen_infer.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
MODEL_NAME_OR_PATH="microsoft/Phi-3-mini-4k-instruct"
|
| 4 |
+
VIT_PATH="openai/clip-vit-large-patch14-336/"
|
| 5 |
+
HLORA_PATH="gen_hlora_weights.bin"
|
| 6 |
+
FUSION_LAYER_PATH="fusion_layer_weights.bin"
|
| 7 |
+
|
| 8 |
+
python3 gen_infer.py \
|
| 9 |
+
--model_name_or_path "$MODEL_NAME_OR_PATH" \
|
| 10 |
+
--dtype "FP16" \
|
| 11 |
+
--hlora_r "256" \
|
| 12 |
+
--hlora_alpha "512" \
|
| 13 |
+
--hlora_nums "4" \
|
| 14 |
+
--vq_idx_nums "8192" \
|
| 15 |
+
--instruct_template "phi3_instruct" \
|
| 16 |
+
--vit_path "$VIT_PATH" \
|
| 17 |
+
--hlora_path "$HLORA_PATH" \
|
| 18 |
+
--fusion_layer_path "$FUSION_LAYER_PATH" \
|
| 19 |
+
--question "Reconstruct the image." \
|
| 20 |
+
--img_path "path/to/image.jpg" \
|
| 21 |
+
--save_path "path/to/save.jpg"
|
之前的代码版本/注意力用于sam的prompt的版本/MedEvalKit/models/HealthGPT/llava/demo/utils.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import transformers
|
| 3 |
+
import tokenizers
|
| 4 |
+
import os, sys
|
| 5 |
+
from dataclasses import dataclass, field
|
| 6 |
+
import argparse
|
| 7 |
+
from PIL import Image
|
| 8 |
+
|
| 9 |
+
def expand2square(pil_img, background_color):
|
| 10 |
+
width, height = pil_img.size
|
| 11 |
+
if width == height:
|
| 12 |
+
return pil_img
|
| 13 |
+
elif width > height:
|
| 14 |
+
result = Image.new(pil_img.mode, (width, width), background_color)
|
| 15 |
+
result.paste(pil_img, (0, (width - height) // 2))
|
| 16 |
+
return result
|
| 17 |
+
else:
|
| 18 |
+
result = Image.new(pil_img.mode, (height, height), background_color)
|
| 19 |
+
result.paste(pil_img, ((height - width) // 2, 0))
|
| 20 |
+
return result
|
| 21 |
+
|
| 22 |
+
def find_all_linear_names(model):
|
| 23 |
+
cls = torch.nn.Linear
|
| 24 |
+
lora_module_names = set()
|
| 25 |
+
multimodal_keywords = ['mm_projector', 'vision_tower', 'vision_resampler']
|
| 26 |
+
for name, module in model.named_modules():
|
| 27 |
+
if any(mm_keyword in name for mm_keyword in multimodal_keywords):
|
| 28 |
+
continue
|
| 29 |
+
if isinstance(module, cls):
|
| 30 |
+
names = name.split('.')
|
| 31 |
+
lora_module_names.add(names[0] if len(names) == 1 else names[-1])
|
| 32 |
+
|
| 33 |
+
if 'lm_head' in lora_module_names: # needed for 16-bit
|
| 34 |
+
lora_module_names.remove('lm_head')
|
| 35 |
+
return list(lora_module_names)
|
| 36 |
+
|
| 37 |
+
def add_special_tokens_and_resize_model(tokenizer, model, vq_idx_nums=8192):
|
| 38 |
+
if len(tokenizer.additional_special_tokens) != 0:
|
| 39 |
+
return tokenizer.additional_special_tokens
|
| 40 |
+
index_tokens = [f"<idx_{i}>" for i in range(vq_idx_nums)]
|
| 41 |
+
special_tokens = {
|
| 42 |
+
'additional_special_tokens': ['<start_index>'] + index_tokens + ['<end_index>'] + ['<pixel_newline>']
|
| 43 |
+
}
|
| 44 |
+
num_new_tokens = tokenizer.add_special_tokens(special_tokens)
|
| 45 |
+
model.resize_token_embeddings(len(tokenizer))
|
| 46 |
+
if num_new_tokens > 0:
|
| 47 |
+
input_embeddings = model.get_input_embeddings().weight.data
|
| 48 |
+
output_embeddings = model.get_output_embeddings().weight.data
|
| 49 |
+
|
| 50 |
+
input_embeddings_avg = input_embeddings[:-num_new_tokens].mean(
|
| 51 |
+
dim=0, keepdim=True)
|
| 52 |
+
output_embeddings_avg = output_embeddings[:-num_new_tokens].mean(
|
| 53 |
+
dim=0, keepdim=True)
|
| 54 |
+
|
| 55 |
+
input_embeddings[-num_new_tokens:] = input_embeddings_avg
|
| 56 |
+
output_embeddings[-num_new_tokens:] = output_embeddings_avg
|
| 57 |
+
|
| 58 |
+
return num_new_tokens
|
| 59 |
+
|
| 60 |
+
com_vision_args = argparse.Namespace(
|
| 61 |
+
freeze_backbone=False,
|
| 62 |
+
mm_patch_merge_type='flat',
|
| 63 |
+
mm_projector_type='mlp2x_gelu',
|
| 64 |
+
mm_use_im_patch_token=False,
|
| 65 |
+
mm_use_im_start_end=False,
|
| 66 |
+
mm_vision_select_feature='patch',
|
| 67 |
+
mm_vision_select_layer=-2,
|
| 68 |
+
model_name_or_path=None,
|
| 69 |
+
pretrain_mm_mlp_adapter=None,
|
| 70 |
+
tune_mm_mlp_adapter=False,
|
| 71 |
+
version=None,
|
| 72 |
+
vision_tower=None
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
gen_vision_args = argparse.Namespace(
|
| 76 |
+
freeze_backbone=False,
|
| 77 |
+
mm_patch_merge_type='flat',
|
| 78 |
+
mm_projector_type='mlp2x_gelu',
|
| 79 |
+
mm_use_im_patch_token=False,
|
| 80 |
+
mm_use_im_start_end=False,
|
| 81 |
+
mm_vision_select_feature='patch',
|
| 82 |
+
mm_vision_select_layer=1,
|
| 83 |
+
model_name_or_path=None,
|
| 84 |
+
pretrain_mm_mlp_adapter=None,
|
| 85 |
+
tune_mm_mlp_adapter=False,
|
| 86 |
+
version=None,
|
| 87 |
+
vision_tower=None
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
def load_weights(model, hlora_path, fusion_layer_path=None):
|
| 91 |
+
hlora_weights = torch.load(hlora_path)
|
| 92 |
+
hlora_unexpected_keys = model.load_state_dict(hlora_weights, strict=False)[1]
|
| 93 |
+
if hlora_unexpected_keys:
|
| 94 |
+
print(f"Warning: Unexpected keys in hlora checkpoint: {hlora_unexpected_keys}")
|
| 95 |
+
|
| 96 |
+
if fusion_layer_path:
|
| 97 |
+
fusion_layer_weights = torch.load(fusion_layer_path)
|
| 98 |
+
fusion_layer_unexpected_keys = model.load_state_dict(fusion_layer_weights, strict=False)[1]
|
| 99 |
+
if fusion_layer_unexpected_keys:
|
| 100 |
+
print(f"Warning: Unexpected keys in fusion_layer checkpoint: {fusion_layer_unexpected_keys}")
|
| 101 |
+
|
| 102 |
+
return model
|
| 103 |
+
|