forked from VowpalWabbit/vowpal_wabbit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
82 lines (75 loc) · 2.79 KB
/
init.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
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
----------------------------------------------------------------------
-- This is a simple Lua interface to John Langford's allreduce
-- implementation.
--
-- To use it, you simply neet to start a server on some arbitrary
-- machine:
-- $ ssh mymachine
-- $ torch -lallreduce -e "allreduce.startserver()"
--
-- Once this daemon is running, you can run as many jobs as you
-- like, on any machine, provided that you point to 'mymachine'.
-- From Lua:
-- -- script 1:
-- > allreduce.init('mymachine', 1, 2) -- job 1/2
-- > allreduce.average(somevector)
--
-- -- script 2:
-- > allreduce.init('mymachine', 2, 2) -- job 2/2
-- > allreduce.average(somevector)
--
-- After these calls, both scripts will have the same 'somevector'.
--
-- Author: Clement Farabet
----------------------------------------------------------------------
require 'torch'
require 'liballreduce'
require 'paths'
allreduce = {}
local parameters = {}
function allreduce.startserver()
print('<allreduce> (re)starting server on local machine')
os.execute('killall allserver > /dev/null')
os.execute(paths.concat(paths.install_bin,'allserver'))
end
function allreduce.init(master_location, node, total, unique_id)
parameters.master_location = master_location or 'localhost'
parameters.unique_id = unique_id or 0
parameters.total = total or 1
parameters.node = (node or 1) - 1
end
function allreduce.accumulate(data)
if data:type() ~= 'torch.FloatTensor' then
error('<allreduce> only supporting FloatTensor type for now')
end
local time = data.allreduce.accumulate(data,
parameters.master_location,
parameters.unique_id,
parameters.total,
parameters.node)
return time
end
function allreduce.average(data)
if data:type() ~= 'torch.FloatTensor' then
error('<allreduce> only supporting FloatTensor type for now')
end
local time = data.allreduce.accumulate(data,
parameters.master_location,
parameters.unique_id,
parameters.total,
parameters.node)
data:div(parameters.total)
return time
end
function allreduce.best(data, score)
if data:type() ~= 'torch.FloatTensor' then
error('<allreduce> only supporting FloatTensor type for now')
end
local time = data.allreduce.best(data,
parameters.master_location,
parameters.unique_id,
parameters.total,
parameters.node,
score)
return time
end