torch / nngraph

Graph Computation for nn

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

type casting?

clementfarabet opened this issue · comments

How do you guys do type casting? The current :type() method seems very partial; running the following code prints out lots of DoubleTensors.

setprintlevel(20)

require 'nngraph'

local i1 = nn.Identity()()
local i2 = nn.Identity()()

local o1 = nn.Tanh()( nn.Linear(10,10)(i1) )
local o2 = nn.Tanh()( nn.Linear(10,10)(i2) )

local m = nn.gModule({i1,i2}, {o1,o2})

m:forward({torch.randn(10), torch.randn(10)})
m:backward({torch.randn(10), torch.randn(10)}, {torch.randn(10), torch.randn(10)})

m:float()

print{m}

from my understanding, adam's open PR #56 should fix this.

As far as I can see, all the double's are input and gradoutput variables. They are goign to be reset at the next forward and backward. They are just pointers to module.output from previous run and since the module.output is now a new tensor, these references remain. But at every forward these are reset.

https://github.com/torch/nngraph/blob/master/gmodule.lua#L300
https://github.com/torch/nngraph/blob/master/gmodule.lua#L379

I think the type casting is actually fine, I guess ;) But I will go through Adam's and couple other PRs today.

This unfortunately does not seem to be completely fixed. clementfarabet's example still gives doubles.

Personally I use it on a model that I convert from cuda to float, and then clone. The input and gradOutput take up a lot of memory in my case and therefore I get cuda memory errors.

Edit: Actually calling :clearState() solves my immediate problem.