
#!/bin/bash
GPU_ID=1
THRESHOLD=50000 


function get_free_memory() {
	nvidia-smi --query-gpu=memory.free --format=csv,nounits,noheader | sed -n "$((GPU_ID+1))p"
}


while true; do
	FREE_MEM=$(get_free_memory)
	echo "GPU $GPU_ID free memory: ${FREE_MEM}MB"
	if [ "$FREE_MEM" -gt "$THRESHOLD" ]; then
		echo "Free memory is greater than 40GB. Running your script...."

		nohup python vllm_target_all.py --size 400 --gpus 2 --interval 0.01 & 
		# nohup bash examples/qwen2_5_vl_3b_gui_grpo_H100_Base.sh &

		break
	fi
      	# 设定检查间隔，例如每隔5分钟检查一次
	sleep 10
done

