Cuda ISSUE(LookupTable.lua:75: bad argument #3 to 'index' (Tensor | LongTensor expected, got torch.)

92 views
Skip to first unread message

Badri Narayana Patro

unread,
Aug 23, 2016, 5:00:01 PM8/23/16
to torch7

Error detail analysis:


$th train.lua -gpuid 0


using CUDA on GPU 0...
Loading data files...
Loading train fc7 features from data/train_fc7.t7
Loading val fc7 features from data/val_fc7.t7
Parameters: 6813673
Batches: 1076
Max iterations: 53800
/home/cse/torch/install/bin/luajit:
/home/cse/torch/install/share/lua/5.1/nn/Container.lua:67:
In 1 module of nn.Sequential:
/home/cse/torch/install/share/lua/5.1/nn/LookupTable.lua:75: bad argument
#3 to 'index' (Tensor | LongTensor expected, got torch.CudaLongTensor)
stack traceback:
[C]: in function 'index'
/home/cse/torch/install/share/lua/5.1/nn/LookupTable.lua:75: in
function
[C]: in function 'xpcall'
/home/cse/torch/install/share/lua/5.1/nn/Container.lua:63: in function
'rethrowErrors'
/home/cse/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function
'forward'
train.lua:375: in function 'opfunc'
/home/cse/torch/install/share/lua/5.1/optim/adam.lua:37: in function
'adam'
train.lua:476: in main chunk
[C]: in function 'dofile'
.../cse/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in
main chunk
[C]: at 0x00405970

WARNING: If you see a stack trace below, it doesn't point to the place
where this error occurred. Please use only the one above.
stack traceback:
[C]: in function 'error'
/home/cse/torch/install/share/lua/5.1/nn/Container.lua:67: in function
'rethrowErrors'
/home/cse/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function
'forward'
train.lua:375: in function 'opfunc'
/home/cse/torch/install/share/lua/5.1/optim/adam.lua:37: in function
'adam'
train.lua:476: in main chunk
[C]: in function 'dofile'
.../cse/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in
main chunk
[C]: at 0x00405970


Reffered : I have searched this problem and found following link :


https://groups.google.com/forum/#!topic/torch7/6igs4XdoSW4
jcjohnson/neural-style#210
jcjohnson/torch-rnn#56
https://groups.google.com/forum/#!topic/torch7/uEeBWwkyDPU


Solution : After ,I referred those link, i have re-installed following packages

luarocks install nn
luarocks install cunn
luarocks install cunn 1.0-0
luarocks install torch
luarocks install cutorch
luarocks install cutorch 1.0-0


But, I got same error. Please let me know how do i solve this issue.

Xin Rong

unread,
Aug 28, 2016, 4:29:30 PM8/28/16
to torch7
I had the same error and I solved it! I was new to torch and was working with a code-to-NL library (https://github.com/sriniiyer/codenn). My error was like:

~/torch/install/bin/luajit: /home/ronxin/torch/install/share/lua/5.1/nn/LookupTable.lua:75: bad argument #3 to 'index' (Tensor | LongTensor expected, got torch.CudaLongTensor)
stack traceback:
[C]: in function 'index'
.../torch/install/share/lua/5.1/nn/LookupTable.lua:75: in function 'func'
.../torch/install/share/lua/5.1/nngraph/gmodule.lua:345: in function 'neteval'
.../torch/install/share/lua/5.1/nngraph/gmodule.lua:380: in function 'forward'
main.lua:13: in function 'fp'
main.lua:160: in function 'main'
main.lua:215: in main chunk
[C]: in function 'dofile'
.../torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
[C]: at 0x004064f0

Based on the error message, it seemed that some library was trying to use typed tensor type, but other libraries wouldn't accept it. I googled around and confirmed that there was indeed a recent switch. So keeping all the libraries up-to-date will seem to likely solve the problem.

So I solved the problem by having a clean installation by following the instructions in http://torch.ch/docs/getting-started.html. That distribution has already bundled cunn and cutorch. So you don't have to reinstall them using luarocks. After a long wait (building cutorch seems to take a very long time), the installation finished and I tried running the codenn program again and it worked.

Also note that the version of cutorch that comes with the above torch distribution is cutorch scm-1, instead of 1.0-0. Previously I had 1.0-0 and I think that might be part of the reason causing the version inconsistency.
Reply all
Reply to author
Forward
0 new messages