{"action":"created","issue":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/1605","repository_url":"https://api.github.com/repos/pytorch/pytorch","labels_url":"https://api.github.com/repos/pytorch/pytorch/issues/1605/labels{/name}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/1605/comments","events_url":"https://api.github.com/repos/pytorch/pytorch/issues/1605/events","html_url":"https://github.com/pytorch/pytorch/issues/1605","id":230239542,"number":1605,"title":"torch.autograd.backward does not handle dependent Variables correctly","user":{"login":"soumith","id":1310570,"avatar_url":"https://avatars3.githubusercontent.com/u/1310570?v=3","gravatar_id":"","url":"https://api.github.com/users/soumith","html_url":"https://github.com/soumith","followers_url":"https://api.github.com/users/soumith/followers","following_url":"https://api.github.com/users/soumith/following{/other_user}","gists_url":"https://api.github.com/users/soumith/gists{/gist_id}","starred_url":"https://api.github.com/users/soumith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soumith/subscriptions","organizations_url":"https://api.github.com/users/soumith/orgs","repos_url":"https://api.github.com/users/soumith/repos","events_url":"https://api.github.com/users/soumith/events{/privacy}","received_events_url":"https://api.github.com/users/soumith/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":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-05-21T18:44:09Z","updated_at":"2017-05-22T14:50:47Z","closed_at":null,"body":"Here's a failure case on master:\r\n\r\n```python\r\nimport torch\r\nfrom torch.autograd import Variable\r\n\r\nx = Variable(torch.randn(10), requires_grad=True)\r\ny = x ** 2\r\nz = y ** 3\r\n\r\ntorch.autograd.backward([y, z], [torch.randn(10), torch.randn(10)])\r\n```\r\n\r\nand here's the stack-trace:\r\n```\r\nTraceback (most recent call last):\r\n  File \"foo.py\", line 10, in <module>\r\n    torch.autograd.backward([y, z], [torch.randn(10), torch.randn(10)])\r\n  File \"/home/soumith/code/pytorch/torch/autograd/__init__.py\", line 98, in backward\r\n    variables, grad_variables, retain_graph)\r\n  File \"/home/soumith/code/pytorch/torch/autograd/function.py\", line 90, in apply\r\n    return self._forward_cls.backward(self, *args)\r\n  File \"/home/soumith/code/pytorch/torch/autograd/_functions/basic_ops.py\", line 209, in backward\r\n    var, = ctx.saved_variables\r\nRuntimeError: Trying to backward through the graph second time, but the buffers have already been freed. Please specify retain_variables=True when calling backward for the first time.\r\n```"},"comment":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/comments/303123155","html_url":"https://github.com/pytorch/pytorch/issues/1605#issuecomment-303123155","issue_url":"https://api.github.com/repos/pytorch/pytorch/issues/1605","id":303123155,"user":{"login":"ezyang","id":13564,"avatar_url":"https://avatars3.githubusercontent.com/u/13564?v=3","gravatar_id":"","url":"https://api.github.com/users/ezyang","html_url":"https://github.com/ezyang","followers_url":"https://api.github.com/users/ezyang/followers","following_url":"https://api.github.com/users/ezyang/following{/other_user}","gists_url":"https://api.github.com/users/ezyang/gists{/gist_id}","starred_url":"https://api.github.com/users/ezyang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezyang/subscriptions","organizations_url":"https://api.github.com/users/ezyang/orgs","repos_url":"https://api.github.com/users/ezyang/repos","events_url":"https://api.github.com/users/ezyang/events{/privacy}","received_events_url":"https://api.github.com/users/ezyang/received_events","type":"User","site_admin":false},"created_at":"2017-05-22T14:50:47Z","updated_at":"2017-05-22T14:50:47Z","body":"@zym1010 I think it is clearer to think about the meaning of multiple parameters to `backward` as introducing an on-the-fly loss function operating on the parameters which has a gradient equal the arguments you pass. So, your example is equivalent to this:\r\n\r\n```\r\nloss = f(y, y, y)\r\ntorch.autograd.backward(loss)\r\n# where df/dloss = [torch.randn(10), torch.randn(10), torch.randn(10)]\r\n```\r\n\r\nNow it should be pretty clear what the intended semantics of your example above should be."}}
{"actor":{"display_login":"ezyang"}}