-
Notifications
You must be signed in to change notification settings - Fork 384
Expand file tree
/
Copy pathtrain_multi_worker.sh
More file actions
82 lines (70 loc) · 1.95 KB
/
Copy pathtrain_multi_worker.sh
File metadata and controls
82 lines (70 loc) · 1.95 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# distributed train script, train on one machine with 2gpus
EXP="multi_worker"
LOG_DIR="logs/"
PIPELINE_CONFIG=$1
shift 1
if [ -z "$PIPELINE_CONFIG" ]
then
echo "usage: sh $0 pipeline_config_path ... "
exit 1
fi
if [ ! -e $PIPELINE_CONFIG ]
then
echo "config file: $PIPELINE_CONFIG does not exits"
exit 1
fi
if [ ! -e $LOG_DIR ]
then
mkdir $LOG_DIR
fi
WAIT_DONE=$1
if [ "$WAIT_DONE" == "WAIT_DONE" ]
then
echo "wait for process done"
shift 1
fi
worker_hosts="localhost:2224,localhost:2223"
gpus="4,5"
echo "worker_hosts=${worker_hosts}"
echo "gpus=${gpus}"
worker_hosts=`echo $worker_hosts | awk -v FS=',' '{ a=""; for(i = 1; i <= NF; i++) { if (a!="") a = a","; a = a"\""$i"\"" } print a }'`
worker_num=`echo $worker_hosts | awk -v FS="," '{ print NF }'`
for worker_id in `seq 0 $((worker_num-1))`
do
# Worker Process
export TF_CONFIG="{
\"cluster\":
{
\"worker\": [$worker_hosts]
},
\"task\":
{
\"type\": \"worker\",
\"index\": $worker_id
}
}"
gpu_id=`echo $gpus | awk -v FS=',' -v worker_id=$((worker_id+1)) '{ print $worker_id }'`
echo "start worker=$worker_id gpu_id=$gpu_id"
CUDA_VISIBLE_DEVICES=$gpu_id nohup python -m easy_rec.python.train_eval \
--pipeline_config_path $PIPELINE_CONFIG $@\
> $LOG_DIR/log_${EXP}_worker_${worker_id}.txt 2>&1 &
worker_pids[$worker_id]=$!
echo " pid=$!"
done
echo "logs:"
ls -lh ${LOG_DIR}/log_${EXP}_*.txt
if [ "$WAIT_DONE" == "WAIT_DONE" ]
then
for worker_id in `seq 0 $((worker_num-1))`
do
wait ${worker_pids[$worker_id]}
error_code=$?
if [ $error_code -ne 0 ]
then
echo "worker $worker_id ${worker_pids[$worker_id]} failed[error_code=$error_code]"
exit $error_code
else
echo "worker $worker_id done"
fi
done
fi