{"action":"closed","issue":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/1450","repository_url":"https://api.github.com/repos/pytorch/pytorch","labels_url":"https://api.github.com/repos/pytorch/pytorch/issues/1450/labels{/name}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/1450/comments","events_url":"https://api.github.com/repos/pytorch/pytorch/issues/1450/events","html_url":"https://github.com/pytorch/pytorch/issues/1450","id":225878212,"number":1450,"title":"Bug in new autograd backward (with LSTM Cell)","user":{"login":"ChenRocks","id":6073275,"avatar_url":"https://avatars0.githubusercontent.com/u/6073275?v=3","gravatar_id":"","url":"https://api.github.com/users/ChenRocks","html_url":"https://github.com/ChenRocks","followers_url":"https://api.github.com/users/ChenRocks/followers","following_url":"https://api.github.com/users/ChenRocks/following{/other_user}","gists_url":"https://api.github.com/users/ChenRocks/gists{/gist_id}","starred_url":"https://api.github.com/users/ChenRocks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChenRocks/subscriptions","organizations_url":"https://api.github.com/users/ChenRocks/orgs","repos_url":"https://api.github.com/users/ChenRocks/repos","events_url":"https://api.github.com/users/ChenRocks/events{/privacy}","received_events_url":"https://api.github.com/users/ChenRocks/received_events","type":"User","site_admin":false},"labels":[{"id":424131847,"url":"https://api.github.com/repos/pytorch/pytorch/labels/bug","name":"bug","color":"b60205","default":true},{"id":443484135,"url":"https://api.github.com/repos/pytorch/pytorch/labels/high%20priority","name":"high priority","color":"F22613","default":false}],"state":"closed","locked":false,"assignee":{"login":"apaszke","id":4583066,"avatar_url":"https://avatars0.githubusercontent.com/u/4583066?v=3","gravatar_id":"","url":"https://api.github.com/users/apaszke","html_url":"https://github.com/apaszke","followers_url":"https://api.github.com/users/apaszke/followers","following_url":"https://api.github.com/users/apaszke/following{/other_user}","gists_url":"https://api.github.com/users/apaszke/gists{/gist_id}","starred_url":"https://api.github.com/users/apaszke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apaszke/subscriptions","organizations_url":"https://api.github.com/users/apaszke/orgs","repos_url":"https://api.github.com/users/apaszke/repos","events_url":"https://api.github.com/users/apaszke/events{/privacy}","received_events_url":"https://api.github.com/users/apaszke/received_events","type":"User","site_admin":false},"assignees":[{"login":"apaszke","id":4583066,"avatar_url":"https://avatars0.githubusercontent.com/u/4583066?v=3","gravatar_id":"","url":"https://api.github.com/users/apaszke","html_url":"https://github.com/apaszke","followers_url":"https://api.github.com/users/apaszke/followers","following_url":"https://api.github.com/users/apaszke/following{/other_user}","gists_url":"https://api.github.com/users/apaszke/gists{/gist_id}","starred_url":"https://api.github.com/users/apaszke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apaszke/subscriptions","organizations_url":"https://api.github.com/users/apaszke/orgs","repos_url":"https://api.github.com/users/apaszke/repos","events_url":"https://api.github.com/users/apaszke/events{/privacy}","received_events_url":"https://api.github.com/users/apaszke/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2017-05-03T03:47:37Z","updated_at":"2017-05-03T12:15:37Z","closed_at":"2017-05-03T12:15:37Z","body":"This is how I implement the decoder of a sequence to sequence model\r\n```python\r\nimport torch\r\nfrom torch import nn\r\nfrom torch.autograd import Variable\r\nfrom torch.nn import functional as F\r\n\r\ndef decoder(input_, embedding, lstm, projection, states):\r\n    \"\"\" unroll the LSTM Cell, returns the flattened logits\"\"\"\r\n    emb = embedding(input_.t())\r\n    hs = []\r\n    for i in range(input_.size(1)):\r\n        h, c = lstm(emb[i], states)\r\n        hs.append(h)\r\n        states = (h, c)\r\n    lstm_out = torch.stack(hs, dim=0)\r\n    logit = projection(lstm_out.contiguous().view(-1, lstm.hidden_size))\r\n    return logit\r\n\r\nembedding = nn.Embedding(4, 64, padding_idx=0).cuda()\r\nlstm = nn.LSTMCell(64, 64).cuda()\r\nprojection = nn.Linear(64, 4).cuda()\r\n\r\ninput_ = Variable(torch.LongTensor([[1, 2, 3], [3, 2, 1]])).cuda()\r\nstates = (Variable(torch.zeros(2, 64)).cuda(), Variable(torch.zeros(2, 64)).cuda())\r\ntarget = Variable(torch.LongTensor([[3, 2, 1], [2, 3, 1]])).cuda()\r\n\r\nlogit = decoder(input_, embedding, lstm, projection, states)\r\nloss = F.cross_entropy(logit, target.t().contiguous().view(-1))\r\nloss.backward()  #  RuntimeError: No grad accumulator for a saved leaf!\r\n\r\n```\r\nI'm not sure about the new autograd mechanics but this worked in the previous version.\r\nIf I didn't make the unrolling codes a function it will work. It will also work with CPU.\r\nI compiled from source [(699755e)](https://github.com/pytorch/pytorch/commit/699755e04f8bbb4378a70f03dfe0849094fd0255) with Python 2.7, CUDA 8.0 and Cudnn 6"}}
{"actor":{"display_login":"soumith"}}