{"action":"created","issue":{"url":"https://api.github.com/repos/torch/nn/issues/427","labels_url":"https://api.github.com/repos/torch/nn/issues/427/labels{/name}","comments_url":"https://api.github.com/repos/torch/nn/issues/427/comments","events_url":"https://api.github.com/repos/torch/nn/issues/427/events","html_url":"https://github.com/torch/nn/issues/427","id":110886151,"number":427,"title":"inputs changing in the middle of `updateOutput` of `JoinTable`","user":{"login":"eulerreich","id":4183609,"avatar_url":"https://avatars.githubusercontent.com/u/4183609?v=3","gravatar_id":"","url":"https://api.github.com/users/eulerreich","html_url":"https://github.com/eulerreich","followers_url":"https://api.github.com/users/eulerreich/followers","following_url":"https://api.github.com/users/eulerreich/following{/other_user}","gists_url":"https://api.github.com/users/eulerreich/gists{/gist_id}","starred_url":"https://api.github.com/users/eulerreich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eulerreich/subscriptions","organizations_url":"https://api.github.com/users/eulerreich/orgs","repos_url":"https://api.github.com/users/eulerreich/repos","events_url":"https://api.github.com/users/eulerreich/events{/privacy}","received_events_url":"https://api.github.com/users/eulerreich/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-10-11T22:23:06Z","updated_at":"2015-10-12T09:27:10Z","closed_at":null,"body":"I'm not sure if I'm using it wrong, but this sure is a weird bug. Possibly something to do with threading?\r\n\r\nIf I run the following\r\n```lua\r\nrequire 'nn'\r\nrequire 'nngraph'\r\n\r\nx = nn.Identity()()\r\ny = nn.Identity()()\r\nz = nn.JoinTable(1){x, y}\r\ng = nn.gModule({x, y}, {z})\r\n\r\nxx = torch.rand(4, 5)\r\nyy = torch.rand(6, 5)\r\nzz = g:forward{xx, yy}\r\nzz2 = g:forward{zz, yy}\r\n```\r\nI get an error \r\n```\r\n/home/greg/torch/install/share/lua/5.1/nn/JoinTable.lua:39: bad argument #2 to 'narrow' (out of range at /home/greg/torch/pkg/torch/lib/TH/generic/THTensor.c:350)\r\nstack traceback:\r\n\t[C]: in function 'narrow'\r\n\t/home/greg/torch/install/share/lua/5.1/nn/JoinTable.lua:39: in function 'func'\r\n\t/home/greg/torch/install/share/lua/5.1/nngraph/gmodule.lua:253: in function 'neteval'\r\n\t/home/greg/torch/install/share/lua/5.1/nngraph/gmodule.lua:288: in function 'forward'\r\n\t[string \"xx = torch.rand(4, 5)...\"]:4: in main chunk\r\n\t[C]: in function 'xpcall'\r\n\t/home/greg/torch/install/share/lua/5.1/itorch/main.lua:179: in function </home/greg/torch/install/share/lua/5.1/itorch/main.lua:143>\r\n\t/home/greg/torch/install/share/lua/5.1/lzmq/poller.lua:75: in function 'poll'\r\n\t/home/greg/torch/install/share/lua/5.1/lzmq/impl/loop.lua:307: in function 'poll'\r\n\t/home/greg/torch/install/share/lua/5.1/lzmq/impl/loop.lua:325: in function 'sleep_ex'\r\n\t/home/greg/torch/install/share/lua/5.1/lzmq/impl/loop.lua:370: in function 'start'\r\n\t/home/greg/torch/install/share/lua/5.1/itorch/main.lua:350: in main chunk\r\n\t[C]: in function 'require'\r\n\t[string \"arg={'/run/user/1000/jupyter/kernel-92e69483-...\"]:1: in main chunk\r\n```\r\n\r\nI then added print statements to `JoinTable.lua` so that it looks like this\r\n```lua\r\nfunction JoinTable:updateOutput(input)                                                                                                          \r\n   local dimension = self.dimension                                                                                                             \r\n   if self.nInputDims and input[1]:dim()==(self.nInputDims+1) then                                                                              \r\n       dimension = dimension + 1                                                                                                                \r\n   end                                                                                                                                          \r\n                                                                                                                                                \r\n   print('dimension is', dimension)                                                                                                             \r\n   print('input is', input)                                                                                                                     \r\n   for i=1,#input do                                                                                                                            \r\n      local currentOutput = input[i]                                                                                                            \r\n      print('input', i, 'size is', input[i]:size())                                                                                             \r\n      if i == 1 then                                                                                                                            \r\n         self.size:resize(currentOutput:dim()):copy(currentOutput:size())                                                                       \r\n      else                                                                                                                                      \r\n         self.size[dimension] = self.size[dimension]                                                                                            \r\n            + currentOutput:size(dimension)                                                                                                     \r\n      end                                                                                                                                       \r\n   end                                                                                                                                          \r\n   self.output:resize(self.size)                                                                                                                \r\n                                                                                                                                                \r\n   print('input is now', input)                                                                                                                 \r\n   print(self.size)                                                                                                                             \r\n   print(self.output:size())                                                                                                                    \r\n   local offset = 1                                                                                                                             \r\n   for i=1,#input do                                                                                                                            \r\n      print('offset is', offset)                                                                                                                \r\n      local currentOutput = input[i]                                                                                                            \r\n      print('size of narrow is', currentOutput:size(dimension))                                                                                 \r\n      self.output:narrow(dimension, offset,                                                                                                     \r\n         currentOutput:size(dimension)):copy(currentOutput)                                                                                     \r\n      offset = offset + currentOutput:size(dimension)                                                                                           \r\n   end                                                                                                                                          \r\n   return self.output                                                                                                                           \r\nend\r\n```\r\n\r\nThe output I got is \r\n```\r\ndimension is\t1\t\r\ninput is\t{\r\n  1 : DoubleTensor - size: 4x5\r\n  2 : DoubleTensor - size: 6x5\r\n}\r\ninput\t1\tsize is\t\r\n 4\r\n 5\r\n[torch.LongStorage of size 2]\r\n\r\ninput\t2\tsize is\t\r\n 6\r\n 5\r\n[torch.LongStorage of size 2]\r\n\r\ninput is now\t{\r\n  1 : DoubleTensor - size: 4x5\r\n  2 : DoubleTensor - size: 6x5\r\n}\r\n\r\n 10\r\n  5\r\n[torch.LongStorage of size 2]\r\n\r\n\r\n 10\r\n  5\r\n[torch.LongStorage of size 2]\r\n\r\noffset is\t1\t\r\nsize of narrow is\t4\t\r\noffset is\t5\t\r\nsize of narrow is\t6\t\r\ndimension is\t1\t\r\ninput is\t{\r\n  1 : DoubleTensor - size: 10x5\r\n  2 : DoubleTensor - size: 6x5\r\n}\r\ninput\t1\tsize is\t\r\n 10\r\n  5\r\n[torch.LongStorage of size 2]\r\n\r\ninput\t2\tsize is\t\r\n 6\r\n 5\r\n[torch.LongStorage of size 2]\r\n\r\ninput is now\t{\r\n  1 : DoubleTensor - size: 16x5\r\n  2 : DoubleTensor - size: 6x5\r\n}\r\n\r\n 16\r\n  5\r\n[torch.LongStorage of size 2]\r\n\r\n\r\n 16\r\n  5\r\n[torch.LongStorage of size 2]\r\n\r\noffset is\t1\t\r\nsize of narrow is\t16\t\r\noffset is\t17\t\r\nsize of narrow is\t6\t\r\n/home/greg/torch/install/share/lua/5.1/nn/JoinTable.lua:39: bad argument #2 to 'narrow' (out of range at /home/greg/torch/pkg/torch/lib/TH/generic/THTensor.c:350)\r\nstack traceback:\r\n\t[C]: in function 'narrow'\r\n\t/home/greg/torch/install/share/lua/5.1/nn/JoinTable.lua:39: in function 'func'\r\n\t/home/greg/torch/install/share/lua/5.1/nngraph/gmodule.lua:253: in function 'neteval'\r\n\t/home/greg/torch/install/share/lua/5.1/nngraph/gmodule.lua:288: in function 'forward'\r\n\t[string \"xx = torch.rand(4, 5)...\"]:4: in main chunk\r\n\t[C]: in function 'xpcall'\r\n\t/home/greg/torch/install/share/lua/5.1/itorch/main.lua:179: in function </home/greg/torch/install/share/lua/5.1/itorch/main.lua:143>\r\n\t/home/greg/torch/install/share/lua/5.1/lzmq/poller.lua:75: in function 'poll'\r\n\t/home/greg/torch/install/share/lua/5.1/lzmq/impl/loop.lua:307: in function 'poll'\r\n\t/home/greg/torch/install/share/lua/5.1/lzmq/impl/loop.lua:325: in function 'sleep_ex'\r\n\t/home/greg/torch/install/share/lua/5.1/lzmq/impl/loop.lua:370: in function 'start'\r\n\t/home/greg/torch/install/share/lua/5.1/itorch/main.lua:350: in main chunk\r\n\t[C]: in function 'require'\r\n\t[string \"arg={'/run/user/1000/jupyter/kernel-92e69483-...\"]:1: in main chunk\r\n```\r\n\r\nNote especially that inside the same second call to `updateOutput`, \r\n```\r\ninput is\t{\r\n  1 : DoubleTensor - size: 10x5\r\n  2 : DoubleTensor - size: 6x5\r\n}\r\n```\r\nthen soon after \r\n```\r\ninput is now\t{\r\n  1 : DoubleTensor - size: 16x5\r\n  2 : DoubleTensor - size: 6x5\r\n}\r\n```\r\n\r\nThe expected behavior is that `input` should be \r\n```\r\n{\r\n  1 : DoubleTensor - size: 16x5\r\n  2 : DoubleTensor - size: 6x5\r\n}\r\n```\r\nthe whole time (during the second call to `updateOutput`)."},"comment":{"url":"https://api.github.com/repos/torch/nn/issues/comments/147346868","html_url":"https://github.com/torch/nn/issues/427#issuecomment-147346868","issue_url":"https://api.github.com/repos/torch/nn/issues/427","id":147346868,"user":{"login":"eulerreich","id":4183609,"avatar_url":"https://avatars.githubusercontent.com/u/4183609?v=3","gravatar_id":"","url":"https://api.github.com/users/eulerreich","html_url":"https://github.com/eulerreich","followers_url":"https://api.github.com/users/eulerreich/followers","following_url":"https://api.github.com/users/eulerreich/following{/other_user}","gists_url":"https://api.github.com/users/eulerreich/gists{/gist_id}","starred_url":"https://api.github.com/users/eulerreich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eulerreich/subscriptions","organizations_url":"https://api.github.com/users/eulerreich/orgs","repos_url":"https://api.github.com/users/eulerreich/repos","events_url":"https://api.github.com/users/eulerreich/events{/privacy}","received_events_url":"https://api.github.com/users/eulerreich/received_events","type":"User","site_admin":false},"created_at":"2015-10-12T09:27:10Z","updated_at":"2015-10-12T09:27:10Z","body":"@albanD OK that makes a lot of sense. However, the actual problem I had was slightly different, where it's not 2 consecutive JoinTables, but an rnn taking in inputs and previous states across time. The rnn has a JoinTable where this kind of problem occurred, and the input sizes were wrong in the first part of `updateOutput` but then correct during the second part. \r\n\r\nSo this still doesn't wave away the issue. I'll see if I can spin up another snippet showing the problem."}}