# !/bin/bash
export TRANSFORMERS_OFFLINE=1

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
gpu_list="${CUDA_VISIBLE_DEVICES:-0}"
IFS=',' read -ra GPULIST <<< "$gpu_list"

CHUNKS=${#GPULIST[@]}
SPLIT="things"

CKPT="InternVL2_5-4B"

for IDX in $(seq 0 $((CHUNKS-1))); do
    CUDA_VISIBLE_DEVICES=${GPULIST[$IDX]} python -m test_intern2_5vl \
        --model-path /mnt/82_store/LLM-weights/InternVL2_5-4B \
        --question-file ./dataset/CoP_dataset_${SPLIT}_test.json \
        --image-folder /path/to/image \
        --answers-file ./answers/$CKPT/$SPLIT/${CHUNKS}_${IDX}.jsonl \
        --num-chunks $CHUNKS \
        --chunk-idx $IDX \
        --temperature 0 \
        --answer_first 1 \
        --conv-mode vicuna_v1 &
done

wait

output_file=./answers/$CKPT/$SPLIT/merge.jsonl

# Clear out the output file if it exists.
> "$output_file"

# Loop through the indices and concatenate each file.
for IDX in $(seq 0 $((CHUNKS-1))); do
    cat ./answers/$CKPT/$SPLIT/${CHUNKS}_${IDX}.jsonl >> "$output_file"
done

echo $SPLIT

python eval.py \
    --result-file $output_file \
    --internvl True
