多个显卡同时跑多个实验 - 脚本模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 所有可用显卡
export CUDA_VISIBLE_DEVICES=$1
# 转成了数组形式
all_cuda_devices=($(echo $CUDA_VISIBLE_DEVICES | sed 's/,/ /g'))

# 你要跑的任务(我这里以GLUE的几个任务为例)
if (($# > 1));then tasks=$2;else tasks='qnli qqp mnli sst2' ;fi

task_nums=$(echo $tasks | awk -F ' ' '{print NF}')

if ((${#all_cuda_devices[*]} < $task_nums));then
echo 显卡比任务少
exit 1
fi


now_use=0
for task_name in $tasks
do
export CUDA_VISIBLE_DEVICES=${all_cuda_devices[${now_use}]}
now_use=$((${now_use}+1))

python -u train.py $task_name ..... 2>&1 > $task_name.log &
echo start $task_name on GPU: $CUDA_VISIBLE_DEVICES
done

执行:

1
bash run.sh 0,1,2,3 ....


多个显卡同时跑多个实验 - 脚本模板
https://jcdu.top/2022/12/01/多个显卡同时跑多个实验 - 脚本模板/
作者
horizon86
发布于
2022年12月1日
许可协议