Skip to content

Commit

Permalink
fixing a bug introduced in previous commit. We have to use doubles no…
Browse files Browse the repository at this point in the history
…t floats when we convert GPU models to CPU, because CPU trained models use doubles. This introduced an error where a CPU checkpoint could not be loaded and used on CPU because the initial state was of float type. Anyone who has converted a model with the old script must rerun the conversion script so that double() CPU models are saved instead of float().
  • Loading branch information
karpathy committed Aug 8, 2015
1 parent 86a8edd commit 0fb9a77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion convert_gpu_cpu_checkpoint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protos = checkpoint.protos
-- convert the networks to be CPU models
for k,v in pairs(protos) do
print('converting ' .. k .. ' to CPU')
protos[k]:float()
protos[k]:double()
end

local savefile = opt.model .. '_cpu.t7' -- append "cpu.t7" to filename
Expand Down
6 changes: 4 additions & 2 deletions sample.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ if opt.gpuid >= 0 and opt.opencl == 0 then
if not ok2 then gprint('package cutorch not found!') end
if ok and ok2 then
gprint('using CUDA on GPU ' .. opt.gpuid .. '...')
gprint('Make sure that your saved checkpoint was also trained with GPU. If it was trained with CPU use -gpuid -1 for sampling as well')
cutorch.setDevice(opt.gpuid + 1) -- note +1 to make it 0 indexed! sigh lua
cutorch.manualSeed(opt.seed)
else
Expand All @@ -66,7 +67,8 @@ if opt.gpuid >= 0 and opt.opencl == 1 then
if not ok then print('package clnn not found!') end
if not ok2 then print('package cltorch not found!') end
if ok and ok2 then
print('using OpenCL on GPU ' .. opt.gpuid .. '...')
gprint('using OpenCL on GPU ' .. opt.gpuid .. '...')
gprint('Make sure that your saved checkpoint was also trained with GPU. If it was trained with CPU use -gpuid -1 for sampling as well')
cltorch.setDevice(opt.gpuid + 1) -- note +1 to make it 0 indexed! sigh lua
torch.manualSeed(opt.seed)
else
Expand Down Expand Up @@ -96,7 +98,7 @@ local current_state
current_state = {}
for L = 1,checkpoint.opt.num_layers do
-- c and h for all layers
local h_init = torch.zeros(1, checkpoint.opt.rnn_size):float()
local h_init = torch.zeros(1, checkpoint.opt.rnn_size):double()
if opt.gpuid >= 0 and opt.opencl == 0 then h_init = h_init:cuda() end
if opt.gpuid >= 0 and opt.opencl == 1 then h_init = h_init:cl() end
table.insert(current_state, h_init:clone())
Expand Down

0 comments on commit 0fb9a77

Please sign in to comment.