face-generator icon indicating copy to clipboard operation
face-generator copied to clipboard

cannot convert 'struct THDoubleTensor *' to 'struct THFloatTensor *

Open adam-hanna opened this issue 6 years ago • 2 comments

I'm getting a strange error. Do I have a wrong package version of something?

$ th train.lua
...
<dataset> Loaded 264660 filepaths
<dataset> loaded 1000 random examples
POST    /events
POST    /events
POST    /events
POST    /events
<trainer> Epoch #1 [batchSize = 32]
/root/torch/install/bin/luajit: /root/torch/install/share/lua/5.1/nn/THNN.lua:110: bad argument #3 to 'v' (cannot convert 'struct THDoubleTensor *' to 'struct THFloatTensor *')
stack traceback:
        [C]: in function 'v'
        /root/torch/install/share/lua/5.1/nn/THNN.lua:110: in function 'BCECriterion_updateOutput'
        /root/torch/install/share/lua/5.1/nn/BCECriterion.lua:33: in function 'forward'
        ./adversarial.lua:96: in function 'opfunc'
        ./interruptable_optimizers.lua:60: in function 'interruptableAdam'
        ./adversarial.lua:264: in function 'train'
        train.lua:207: in function 'main'
        train.lua:212: in main chunk
        [C]: in function 'dofile'
        /root/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
        [C]: at 0x00405d50

adam-hanna avatar Aug 23 '18 11:08 adam-hanna

In older versions of torch one could set the default tensor datatype to 32bit floats so that all newly created tensors were by default float tensors. At some point they seem to have changed that. If now the default tensor type is set, it only affects some created tensors and this can even change from one loop iteration to the other. That results in some tensors being created with datatype 64bit float (i.e. double) instead of the required 32bit float, which leads to that error. The solution is to either use a very old version of torch or to manually cast all created tensors to 32bit floats (I think that was done by adding :float() to each command that creates a tensor). The latter way would be the correct one, but currently I don't have the time for that, sorry.

aleju avatar Aug 24 '18 17:08 aleju

Cool, no worries! I'll see if I can't take a shot.

adam-hanna avatar Aug 24 '18 18:08 adam-hanna