-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrunvw-yarn.sh
executable file
·112 lines (96 loc) · 2.52 KB
/
runvw-yarn.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env bash
set -e
dryrun=$1
# MR1 sets $mapred_map_tasks
# MR2/YARN sets $mapreduce_job_maps
nmappers=$mapreduce_job_maps
# MR1 sets $mapreduce_job_submithost
# MR2/YARN sets $mapreduce_job_submithostname
submit_host=$mapreduce_job_submithostname
# MR1 sets $mapred_output_dir
# MR2/YARN sets $mapreduce_output_fileoutputformat_outputdir
output_dir=$mapreduce_output_fileoutputformat_outputdir
set -u
# This works on both MR1 and MR2/YARN
mapper=`printenv mapred_task_id | cut -d "_" -f 5`
mapred_job_id=`echo "$mapred_job_id" | awk -F "_" '{print $NF}'`
# debug
echo $mapper > /dev/stderr
echo $nmappers > /dev/stderr
echo $output_dir > /dev/stderr
echo $submit_host > /dev/stderr
rm -f temp.cache || true
echo 'Starting training' > /dev/stderr
# SGD step
gdcmd="./vw -b 24 -q ad
--total $nmappers
--node $mapper
--unique_id $mapred_job_id
--passes 2
--save_per_pass
--readable_model sgd.rmodel
-d /dev/stdin
-f sgd.vwmodel
--cache_file temp.cache
--span_server $submit_host
--progress 100000
--loss_function=logistic"
# BFGS step
mapred_job_id=`expr $mapred_job_id \* 2` #create new nonce
bfgscmd="./vw
--total $nmappers
--node $mapper
--unique_id $mapred_job_id
--cache_file temp.cache
--bfgs
--mem 5
--passes 10
--save_per_pass
--readable_model bfgs.rmodel
--span_server $submit_host
-f bfgs.vwmodel
-i sgd.vwmodel
--progress 100000
--loss_function=logistic"
if [ "$mapper" == '000000' ]
then
if [ -z ${dryrun:-} ]
then
echo "SGD ..." > /dev/stderr
$gdcmd > >(tee vw.out) 2> >(tee vw.err >&2)
echo "BFGS ..." > /dev/stderr
$bfgscmd > >(tee -a vw.out) 2> >(tee -a vw.err >&2)
else
echo "Dryrrun"
echo $gdcmd
set
cat > /dev/null
fi
if [ $? -ne 0 ]
then
exit 5
fi
# store models and output in hdfs
hadoop fs -put -f sgd.vwmodel* $output_dir || true
hadoop fs -put -f sgd.rmodel* $output_dir || true
hadoop fs -put -f bfgs.vwmodel* $output_dir || true
hadoop fs -put -f bfgs.rmodel* $output_dir || true
hadoop fs -put -f vw.* $output_dir || true
else
if [ -z ${dryrun:-} ]
then
echo "SGD ..."
$gdcmd
echo "BFGS ..."
$bfgscmd
else
echo "Dryrrun"
echo $gdcmd
echo $bfgscmd
cat > /dev/null
fi
if [ $? -ne 0 ]
then
exit 6
fi
fi