{"action":"created","issue":{"url":"https://api.github.com/repos/twitter/torch-autograd/issues/73","labels_url":"https://api.github.com/repos/twitter/torch-autograd/issues/73/labels{/name}","comments_url":"https://api.github.com/repos/twitter/torch-autograd/issues/73/comments","events_url":"https://api.github.com/repos/twitter/torch-autograd/issues/73/events","html_url":"https://github.com/twitter/torch-autograd/issues/73","id":124200843,"number":73,"title":"Error when loss contains scalar multiplication (eg. L2 regularization)","user":{"login":"alex-weaver","id":11133789,"avatar_url":"https://avatars.githubusercontent.com/u/11133789?v=3","gravatar_id":"","url":"https://api.github.com/users/alex-weaver","html_url":"https://github.com/alex-weaver","followers_url":"https://api.github.com/users/alex-weaver/followers","following_url":"https://api.github.com/users/alex-weaver/following{/other_user}","gists_url":"https://api.github.com/users/alex-weaver/gists{/gist_id}","starred_url":"https://api.github.com/users/alex-weaver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex-weaver/subscriptions","organizations_url":"https://api.github.com/users/alex-weaver/orgs","repos_url":"https://api.github.com/users/alex-weaver/repos","events_url":"https://api.github.com/users/alex-weaver/events{/privacy}","received_events_url":"https://api.github.com/users/alex-weaver/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-12-29T11:55:08Z","updated_at":"2015-12-29T20:10:41Z","closed_at":null,"body":"I ran across an issue trying to implement a sparsity-inducing term in the cost function, and in trying to put together a minimal repro case, it turned out that the example train-mnist-autoencoder.lua fails with the following output:\r\n\r\n```\r\nTraining Epoch #1\t\r\n/home/alex/torch/install/bin/luajit: invalid arguments: number \r\nexpected arguments: DoubleTensor | [*DoubleTensor*] DoubleTensor index\r\nstack traceback:\r\n\t[C]: at 0x7f6b925e2940\r\n\t[C]: in function 'gf'\r\n\t...all/share/lua/5.1/autograd/runtime/direct/DirectTape.lua:58: in function 'gradOnly'\r\n\t...all/share/lua/5.1/autograd/runtime/direct/DirectTape.lua:124: in function 'df'\r\n\ttrain-mnist-autoencoder.lua:90: in main chunk\r\n\t[C]: in function 'dofile'\r\n\t...alex/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk\r\n\t[C]: at 0x00406670\r\n```\r\nnote to get this to run I had to remove the line\r\n    `local Value = require 'autograd.Value'`\r\nand change the following:\r\n```lua\r\n--for i=1,Value.len(params.W) do\r\nfor i=1,#params.W do\r\n```\r\nHopefully these modifications don't break the example.\r\n\r\n\r\nThere seems to be an issue around the scalar multiplication of the summed square weights with the l2Lambda parameter. If the l2Lambda term is removed from the loss calculation, but the sum of squares of weights is left in, then the above error does not occur:\r\n```lua\r\n--loss = loss + l2Lambda * torch.sum(torch.pow(params.W[i],2))\r\n  loss = loss + torch.sum(torch.pow(params.W[i],2))\r\n```\r\n\r\nThe same behaviour happens both with and without optimization enabled. If I set a debugHook, it is never triggered (presumably because this issue doesn't involve `nan` or `inf`). I've also tried rebuilding torch with Lua 5.1 instead of LuaJIT, and a similar error occurs."},"comment":{"url":"https://api.github.com/repos/twitter/torch-autograd/issues/comments/167866560","html_url":"https://github.com/twitter/torch-autograd/issues/73#issuecomment-167866560","issue_url":"https://api.github.com/repos/twitter/torch-autograd/issues/73","id":167866560,"user":{"login":"alexbw","id":161935,"avatar_url":"https://avatars.githubusercontent.com/u/161935?v=3","gravatar_id":"","url":"https://api.github.com/users/alexbw","html_url":"https://github.com/alexbw","followers_url":"https://api.github.com/users/alexbw/followers","following_url":"https://api.github.com/users/alexbw/following{/other_user}","gists_url":"https://api.github.com/users/alexbw/gists{/gist_id}","starred_url":"https://api.github.com/users/alexbw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexbw/subscriptions","organizations_url":"https://api.github.com/users/alexbw/orgs","repos_url":"https://api.github.com/users/alexbw/repos","events_url":"https://api.github.com/users/alexbw/events{/privacy}","received_events_url":"https://api.github.com/users/alexbw/received_events","type":"User","site_admin":false},"created_at":"2015-12-29T20:10:41Z","updated_at":"2015-12-29T20:10:41Z","body":"Interesting. Thanks for your work on this. Could you reduce this even further into a self-contained test case? That way, we can incorporate it into our unit tests."}}