#!/bin/bash

MODELS=(
    "ALIGN_RoBERTa_ViT-B" 
    "CLIP_ViT-B-32_Laion2B"
    "CLIP_ViT-B-32_OpenAI"
    "DFN_ViT-B-32"
    "CoCa_ViT-B-32"
    "SigLIP_ViT-B-16"
    "EVA02_B-16"
    "ConvNeXt_Base" 
    "CLIP_ViT-L-14_OpenAI"
    "CLIP_ViT-L-14_Laion2B"     
)

SCOPES=("VISUAL_ONLY" "VISUAL_TEXT")

# Ensure logs directory exists
mkdir -p logs

# --- SUBMISSION LOOP ---
for model in "${MODELS[@]}"; do
    for scope in "${SCOPES[@]}"; do
        
        JOB_NAME="Q_${model}_${scope}"
        echo "Submitting Job: $JOB_NAME"

        # The following block is sent directly to sbatch
        sbatch <<EOT
#!/bin/bash
#SBATCH --job-name=${JOB_NAME}
#SBATCH --output=logs/%j_${JOB_NAME}.out
#SBATCH --error=logs/%j_${JOB_NAME}.err
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --gres=gpu:1
#SBATCH --time=164:00:00
#SBATCH --mem=200G
#SBATCH --partition=gpuh200p

# 1. FIX DIRECTORY
cd \$SLURM_SUBMIT_DIR
cd ..
echo "Running in: \$(pwd)"

# 2. LOAD ENV
module load python/3.12.1
module load cuda/12.5
export HF_HUB_OFFLINE=1

if [ -f ".venv/bin/activate" ]; then
    source .venv/bin/activate
else
    echo "ERROR: .venv not found"
    exit 1
fi

# 3. SET VARIABLES
export TARGET_MODEL_KEY="${model}"
export TARGET_QUANT_SCOPE="${scope}"

echo "Model: ${model}"
echo "Scope: ${scope}"

# 4. RUN
python run_experiments.py
EOT

    done
done

echo "Done submitting loops."