forked from VowpalWabbit/vowpal_wabbit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.lua
46 lines (37 loc) · 933 Bytes
/
test.lua
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
import 'torch'
require 'sys'
require 'allreduce'
torch.setdefaulttensortype('torch.FloatTensor')
dname,fname = sys.fpath()
cmd = torch.CmdLine()
cmd:text()
cmd:text('AllReduce test script')
cmd:text()
cmd:text('Options:')
cmd:option('-id', 1, 'job\s unique ID')
cmd:option('-total', 1, 'total number of jobs')
cmd:option('-server', 'localhost', 'job server address')
cmd:option('-type', 'average', 'reduce type: average | accumulate | best')
cmd:text()
opt = cmd:parse(arg)
jobid = opt.id
jobtotal = opt.total
server = opt.server
if jobid == 1 then
x = zeros(10)
else
x = ones(10)
end
allreduce.init(server, jobid, jobtotal)
print('job ' .. jobid .. ' - sending vector:')
print(x)
if opt.type == 'average' then
allreduce.average(x)
elseif opt.type == 'accumulate' then
allreduce.accumulate(x)
else
score = random.uniform(0,1)
allreduce.best(x, score)
end
print('job ' .. jobid .. ' - reduced vector is:')
print(x)