export NCCL_IB_DISABLE=1
export NCCL_P2P_DISABLE=1
NCCL_DEBUG=INFO

export CUDA_VISIBLE_DEVICES="0,1,2,3,4,5,6,7"
MAIN_PORT=25030

IFS=', ' read -r -a devices <<< "$CUDA_VISIBLE_DEVICES"
num_devices=${#devices[@]}
DIST_ARGS="
    --mixed_precision bf16 \
    --num_cpu_threads_per_process 2 \
    --num_processes $num_devices \
    --num_machines 1 \
    --dynamo_backend no \
    --main_process_port $MAIN_PORT \
"
if [ $num_devices -gt 1 ]; then DIST_ARGS+=" --multi_gpu"; fi

accelerate launch $DIST_ARGS \
  scripts/wan2.1_fun/my_train_dmd_control.py \
  --config_path="config/wan2.1/wan_causal_control_dmd_5.yaml"