forked from harvardnlp/seq2seq-attn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_to_cpu.lua
More file actions
34 lines (29 loc) · 762 Bytes
/
Copy pathconvert_to_cpu.lua
File metadata and controls
34 lines (29 loc) · 762 Bytes
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
require 'nn'
require 'string'
require 'hdf5'
require 'nngraph'
require 'cunn'
require 'cutorch'
require 's2sa.models'
require 's2sa.data'
cmd = torch.CmdLine()
-- file location
cmd:option('-gpu_file', 'gpu_model.t7','gpu model file')
cmd:option('-cpu_file', 'cpu_model.t7', 'cpu output file')
cmd:option('-gpuid', 2, 'which gpuid to use')
opt = cmd:parse(arg)
function main()
print('loading gpu model ' .. opt.gpu_file)
checkpoint = torch.load(opt.gpu_file)
model, model_opt = checkpoint[1], checkpoint[2]
if model_opt.cudnn == 1 then
require 'cudnn'
end
cutorch.setDevice(opt.gpuid)
for i = 1, #model do
model[i]:double()
end
print('saving cpu model to ' .. opt.cpu_file)
torch.save(opt.cpu_file, {model, model_opt})
end
main()