#!/bin/bash
#SBATCH -A nvr_elm_llm  
#SBATCH -p batch_block1,batch_block3,batch_block4
#SBATCH -t 02:00:00
#SBATCH -N 1
#SBATCH -J eval_qwen2_5vl_text
#SBATCH --gpus-per-node 8
#SBATCH --ntasks-per-node 8
#SBATCH -e workdir/%x_%j.err
#SBATCH -o workdir/%x_%j.out

set -eo pipefail

echo "[driver] start at $(date), host=$(hostname)"
echo "[driver] SLURM_JOB_ID=${SLURM_JOB_ID:-}"
echo "[driver] PWD=$(pwd)"

# job configuration
exp_id=eval_qwen2_5vl_text_8gpu
model_name_or_path=Qwen/Qwen2.5-VL-3B-Instruct
dataset_path=/home/chengyuew/chengyuew/workspace/shiyi/LMFlow/data/test_small
output_dir=output_models/${exp_id}
log_dir=log/${exp_id}
trust_remote_code=1
ds_config=configs/ds_config_zero3_no_offload.json

# ensure output/log dirs
echo "[driver] creating output and log directories..."
mkdir -p ${output_dir} ${log_dir}

# activate conda environment
echo "[driver] activating conda environment..."
source "${PROJECT_ROOT}/scripts/cluster_env.sh"
lmflow_activate_conda

which python3 && python3 -V || true
nvidia-smi -L || true

echo "[driver] launching torchrun 8-GPU text-only evaluation at $(date)"
set -x
DISABLE_TORCH_COMPILE=1 \
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True \
torchrun --nproc_per_node=8 shiyi_scripts/eval_qwen2_5_vl_text_only.py \
  --model_name_or_path ${model_name_or_path} \
  --dataset_path ${dataset_path} \
  --output_dir ${output_dir} \
  --deepspeed ${ds_config} \
  --max_eval_samples 100 \
  --per_device_eval_batch_size 1 \
  --block_size 128 \
  > >(tee ${log_dir}/eval.log) \
  2> >(tee ${log_dir}/eval.err >&2)
set +x

echo "[driver] end at $(date)"

