#!/bin/bash -l

# SLURM SUBMIT SCRIPT
#SBATCH --job-name=embed
#SBATCH --nodes=1             # This needs to match Trainer(num_nodes=...)
#SBATCH --gres=gpu:8
#SBATCH --ntasks-per-node=8   # This needs to match Trainer(devices=...)
#SBATCH --cpus-per-task=8    # Number of cores per tasks


# ACTIVATE ANACONDA
eval "$(conda shell.bash hook)"

# activate conda env
conda activate suno_env

# debugging flags (optional)
export NCCL_DEBUG=INFO
export PYTHONFAULTHANDLER=1

# testing
export CUDA_LAUNCH_BLOCKING=0
export NCCL_DEBUG=WARN
export TORCH_DISTRIBUTED_DEBUG=INFO

export HOSTNAMES=`scontrol show hostnames "$SLURM_JOB_NODELIST"`
export MASTER_ADDR=$(scontrol show hostnames "$SLURM_JOB_NODELIST" | head -n 1)
export MASTER_PORT=12802
export COUNT_NODE=`scontrol show hostnames "$SLURM_JOB_NODELIST" | wc -l`

# on your cluster you might need these:
# set the network interface
# export NCCL_SOCKET_IFNAME=^docker0,lo

# might need the latest CUDA
#module load NCCL/2.4.7-1-cuda.10.0

# conda install libaio
export CFLAGS="-I$CONDA_PREFIX/include/"
export LDFLAGS="-L$CONDA_PREFIX/lib/"

# run script from above
torchrun --nproc_per_node 8 scripts/embed_big.py