-
Notifications
You must be signed in to change notification settings - Fork 3
/
calcInfo.lua
197 lines (178 loc) · 5.23 KB
/
calcInfo.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/opt/share/torch-7.0/bin/th
require 'rnn'
dofile('AddConstantNeg.lua')
dofile('options.lua')
local stringx = require 'pl.stringx'
local optmap = {}
local skip = {}
skip["modelSize"]=true
skip['modelElemNum']=true
skip['onGPU']=true
skip['testOnGPU']=true
skip['testFreq']=true
skip['psOmpThdNum']=true
skip['optLevel']=true
skip['ockfree']=true
skip['psAddLevel']=true
skip['numEpochs']=true
skip['mbSize']=true
skip['totalUpdateTimes']=true
for line in io.lines("configure") do
local option = stringx.split(line, '=')
if skip[option[1]] then
print("Delete previous " .. option[1] .. " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
else
optmap[option[1]] = option[2]
end
end
fp = io.open("configure", "w+" )
for k,v in pairs(optmap) do
fp:write(string.format("%s=%s\n", k,v ))
end
fp:close()
if io.open("configure", "r") then
for line in io.lines("configure") do
local option = stringx.split(line, '=')
if type(opt[option[1]]) == 'number' then
opt[option[1]] = tonumber(option[2])
elseif type(opt[option[1]]) == 'boolean' then
if option[2] == "true" then
opt[option[1]] = true
elseif option[2] == "false" then
opt[option[1]] = false
end
elseif type(opt[option[1]]) == 'string' then
opt[option[1]] = option[2]
end
end
end
print(opt)
--opt.rundir = cmd:string('experiment', opt, {dir=true})
--paths.mkdir(opt.rundir)
--cmd:log(opt.rundir .. '/log', params)
if opt.type == 'cuda' then
fbok,_ = pcall(require, 'fbcunn')
if fbok then
require 'fbcunn'
end
cudnnok,_ = pcall(require, 'cudnn')
if cudnnok then
require 'cudnn'
cudnn.fastest = true
cudnn.benchmark = true
cudnn.verbose = true
end
else
fbok = false
cudnnok = false
end
if opt.usefbcunn == false then
fbok = false
elseif opt.usefbcunn == true and fbok == true then
fbok = true
else
print("Error: fbcunn is not available to use.")
fbok = false
end
if opt.usecudnn == false then
cudnnok = false
elseif opt.usecudnn == true and cudnnok == true then
cudnnok = true
else
print("Error: cudnn is not available to use.")
cudnnok = false
end
if opt.type == 'float' then
print('==> switching to floats')
require 'torch'
require 'nn'
require 'optim'
torch.setdefaulttensortype('torch.FloatTensor')
elseif opt.type == 'cuda' then
print('==> switching to CUDA')
require 'cutorch'
require 'cunn'
require 'optim'
torch.setdefaulttensortype('torch.FloatTensor')
cutorch.setDevice(opt.gpuID)
print('GPU DEVICE ID = ' .. cutorch.getDevice())
end
print("####")
print("default tensor type" .. torch.getdefaulttensortype())
torch.setnumthreads(opt.threads)
torch.manualSeed(opt.seed)
math.randomseed(opt.seed)
mapWordIdx2Vector = torch.Tensor()
mapWordStr2WordIdx = {}
mapWordIdx2WordStr = {}
trainDataSet = {}
validDataSet = {}
testDataSet = {}
trainDataTensor = torch.Tensor()
trainDataTensor_y = torch.Tensor()
trainDataTensor_lstm_fwd = torch.Tensor()
trainDataTensor_lstm_bwd = torch.Tensor()
validDataTensor = torch.Tensor()
validDataTensor_lstm_fwd = torch.Tensor()
validDataTensor_lstm_bwd = torch.Tensor()
validDataTensor_y = {}
testDataTensor = torch.Tensor()
testDataTensor_lstm_fwd = torch.Tensor()
testDataTensor_lstm_bwd = torch.Tensor()
testDataTensor_y = {}
dofile 'prepareData.lua'
if opt.type == 'cuda' then
trainDataTensor = trainDataTensor:cuda()
trainDataTensor_y = trainDataTensor_y:cuda()
trainDataTensor_lstm_fwd = trainDataTensor_lstm_fwd:cuda()
trainDataTensor_lstm_bwd = trainDataTensor_lstm_bwd:cuda()
validDataTensor_lstm_fwd = validDataTensor_lstm_fwd:cuda()
validDataTensor_lstm_bwd = validDataTensor_lstm_bwd:cuda()
testDataTensor_lstm_fwd = testDataTensor_lstm_fwd:cuda()
testDataTensor_lstm_bwd = testDataTensor_lstm_bwd:cuda()
validDataTensor = validDataTensor:cuda()
testDataTensor = testDataTensor:cuda()
end
if opt.model == 1 then
dofile 'model_parallel_cnn_bilstm.lua'
elseif opt.model == 2 then
dofile 'model_bilstm.lua'
elseif opt.model == 3 then
dofile 'model_stack_cnn_bilstm.lua'
elseif opt.model == 4 then
dofile 'model_stack_bilstm_cnn.lua'
elseif opt.model == 5 then
dofile 'model_cnn.lua'
elseif opt.model == 6 then
dofile 'model_birnn.lua'
elseif opt.model == 7 then
dofile 'model_bigru.lua'
end
collectgarbage()
collectgarbage()
modelSize = 4*parameters:size()[1]
modelElemNum = parameters:size()[1]
onGPU=1
testOnGPU=1
testFreq=1
psOmpThdNum=4
optLevel=2
lockfree=true
psAddLevel=0
numEpochs=opt.epoch
mbSize=opt.batchSize
totalUpdateTimes = (trainDataTensor:size()[1]/opt.batchSize) * opt.epoch
fp = io.open("configure", "a+" )
fp:write(string.format("modelSize=%s\n", modelSize))
fp:write(string.format("modelElemNum=%s\n", modelElemNum))
fp:write(string.format("onGPU=%s\n", onGPU))
fp:write(string.format("testOnGPU=%s\n", testOnGPU))
fp:write(string.format("testFreq=%s\n", testFreq))
fp:write(string.format("psOmpThdNum=%s\n", psOmpThdNum))
fp:write(string.format("optLevel=%s\n", optLevel))
fp:write(string.format("lockfree=%s\n", lockfree))
fp:write(string.format("psAddLevel=%s\n", psAddLevel))
fp:write(string.format("numEpochs=%s\n", numEpochs))
fp:write(string.format("mbSize=%s\n", mbSize))
fp:write(string.format("totalUpdateTimes=%s\n", totalUpdateTimes))
fp:close()