#!/bin/bash
#SBATCH -p gpu_devel
#SBATCH --gpus=2
#SBATCH -c 12
#SBATCH --mem=200G
#SBATCH -t 06:00:00
#SBATCH -J ph_sets
#SBATCH -o /home/bjc75/other/finetuning/logs/%x_%j.out
# MIT License, Bryan Cheng, 2026. Phenotypes of several adapter sets in one devel-lane job (continuation of dv_mix2).
# SETS="||;||;..." [NSH=16] sbatch slurm/pheno_sets.sh
# Same settings and worker rules as slurm/pheno_rep.sh (full battery, bank group 8, batch 128 / 256 capped by GPU memory
# inside the battery, D-038; 1 worker per GPU, 2 on GPUs >= 120 GB, none on a GPU with ECC faults, D-040). Every worker
# takes its round-robin shards of the first set, then of the next. Finished adapters are skipped, so the same command
# continues in the next job. Shard 0 of each set measures that set's base if it has no record yet.
cd /home/bjc75/other/finetuning
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True PYTHONUNBUFFERED=1 TOKENIZERS_PARALLELISM=false HF_HOME=/nfs/roberts/scratch/pi_skr2/bjc75/finetuning/hf_home
PY=/nfs/roberts/project/pi_skr2/bjc75/conda_envs/lorapop/bin/python; NSH=${NSH:-16}
IFS=, read -ra GIDS <<< "$CUDA_VISIBLE_DEVICES"; echo "allocated GPUs: ${GIDS[*]}"; nvidia-smi --query-gpu=name --format=csv,noheader
IFS=';' read -ra SET <<< "$SETS"
W=()
for g in 0 1; do
mem=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits | sed -n "$((g + 1))p")
ecc=$(nvidia-smi --query-gpu=ecc.errors.uncorrected.volatile.total --format=csv,noheader,nounits | sed -n "$((g + 1))p" | tr -d " ")
case "$ecc" in ""|0|"[N/A]"|"N/A") ;; *) echo "GPU $g has $ecc uncorrected ECC errors: no workers on it"; continue ;; esac
W+=(${GIDS[$g]}); [ "${mem:-0}" -ge 120000 ] && W+=(${GIDS[$g]})
done
nw=${#W[@]}; [ "$nw" -eq 0 ] && { echo "no usable GPU"; exit 1; }
for w in $(seq 0 $((nw - 1))); do
(
for st in "${SET[@]}"; do
IFS='|' read -r BASE AD OUT <<< "$st"; echo "== $BASE $AD -> $OUT"
for s in $(seq $w $nw $((NSH - 1))); do
X=""; [ "$s" = 0 ] && X="--include_base"
CUDA_VISIBLE_DEVICES=${W[$w]} $PY src/run/phenotype.py --base $BASE --adapters $AD --out $OUT --shard $s --nshards $NSH \
$X --sizes full --group 8 --bs 128 --gbs 256 2>&1 | grep -v -i warn | grep -v " ok " | tail -5
done
done
) > logs/phsets_${SLURM_JOB_ID}_w${w}.log 2>&1 &
sleep 20
done
( while sleep 600; do nvidia-smi --query-gpu=index,utilization.gpu,memory.used --format=csv,noheader | tr '\n' ' '; echo; done ) &
wait $(jobs -p | head -n $nw)
for st in "${SET[@]}"; do IFS='|' read -r BASE AD OUT <<< "$st"; echo "$OUT records: $(ls $OUT/*.json 2>/dev/null | wc -l)"; done
echo PHSETSDONE