工作中需要在shell脚本里循环启动nohup后台执行程序,在指定CUDA_VISIBLE_DEVICES后,出现报错:CUDA out of memory. Tried to allocate 14.00 MiB (GPU 0; 23.70 GiB total capacity; 2.01 GiB already allocated; 9.31 MiB free...。此时脚本如下(错误示范):
devices=0
for subfile in `ls $current/$dt`
do
cd $current
CUDA_VISIBLE_DEVICES=$devices echo "nohup /data/private/zhangsirui/anaconda3/bin/python3 test_detect_subtitle_whisper3.py $dt/$subfile result/$subfile > log/log_$subfile.log 2>&1 &"|bash;
devices=$((${devices}+1))
done
实际上nvidia-smi看到有足够空间,
解决办法:
devices=0
for subfile in `ls $current/$dt`
do
cd $current
echo "CUDA_VISIBLE_DEVICES=$devices nohup /data/private/zhangsirui/anaconda3/bin/python3 test_detect_subtitle_whisper3.py $dt/$subfile result/$subfile > log/log_$subfile.log 2>&1 &"|bash;
devices=$((${devices}+1))
done
亲测可用