{"action":"created","issue":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/6990","repository_url":"https://api.github.com/repos/pytorch/pytorch","labels_url":"https://api.github.com/repos/pytorch/pytorch/issues/6990/labels{/name}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/6990/comments","events_url":"https://api.github.com/repos/pytorch/pytorch/issues/6990/events","html_url":"https://github.com/pytorch/pytorch/issues/6990","id":318036876,"number":6990,"title":"Differences between .data and .detach ","user":{"login":"jay960702","id":23382139,"avatar_url":"https://avatars3.githubusercontent.com/u/23382139?v=4","gravatar_id":"","url":"https://api.github.com/users/jay960702","html_url":"https://github.com/jay960702","followers_url":"https://api.github.com/users/jay960702/followers","following_url":"https://api.github.com/users/jay960702/following{/other_user}","gists_url":"https://api.github.com/users/jay960702/gists{/gist_id}","starred_url":"https://api.github.com/users/jay960702/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jay960702/subscriptions","organizations_url":"https://api.github.com/users/jay960702/orgs","repos_url":"https://api.github.com/users/jay960702/repos","events_url":"https://api.github.com/users/jay960702/events{/privacy}","received_events_url":"https://api.github.com/users/jay960702/received_events","type":"User","site_admin":false},"labels":[{"id":897287230,"url":"https://api.github.com/repos/pytorch/pytorch/labels/documentation","name":"documentation","color":"f9d0c4","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-04-26T13:45:48Z","updated_at":"2018-04-26T16:33:31Z","closed_at":"2018-04-26T16:33:31Z","author_association":"NONE","body":"## Issue description\r\n\r\nHi all,\r\n\r\nI am not very clear about the differences between .data and .detach() in the latest pytorch 0.4.\r\nFor example:\r\n\r\n__a = torch.tensor([1,2,3], requires_grad = True)\r\nb = a.data\r\nc = a.detach()__\r\n\r\nso _b_ is not as the same as the _c_? \r\n\r\nHere is a part of the 'PyTorch 0.4.0 Migration Guide':\r\n\r\n*\"However, .data can be unsafe in some cases. Any changes on x.data wouldn’t be tracked by autograd, and the computed gradients would be incorrect if x is needed in a backward pass. A safer alternative is to use x.detach(), which also returns a Tensor that shares data with requires_grad=False, but will have its in-place changes reported by autograd if x is needed in backward.\"*\r\n\r\nCan anyone give me more explanations about this sentence:  \"but will have its in-place changes reported by autograd if x is needed in backward\"？ Thanks！\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/comments/384706714","html_url":"https://github.com/pytorch/pytorch/issues/6990#issuecomment-384706714","issue_url":"https://api.github.com/repos/pytorch/pytorch/issues/6990","id":384706714,"user":{"login":"jay960702","id":23382139,"avatar_url":"https://avatars3.githubusercontent.com/u/23382139?v=4","gravatar_id":"","url":"https://api.github.com/users/jay960702","html_url":"https://github.com/jay960702","followers_url":"https://api.github.com/users/jay960702/followers","following_url":"https://api.github.com/users/jay960702/following{/other_user}","gists_url":"https://api.github.com/users/jay960702/gists{/gist_id}","starred_url":"https://api.github.com/users/jay960702/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jay960702/subscriptions","organizations_url":"https://api.github.com/users/jay960702/orgs","repos_url":"https://api.github.com/users/jay960702/repos","events_url":"https://api.github.com/users/jay960702/events{/privacy}","received_events_url":"https://api.github.com/users/jay960702/received_events","type":"User","site_admin":false},"created_at":"2018-04-26T16:33:31Z","updated_at":"2018-04-26T16:33:31Z","author_association":"NONE","body":"Hi Richard @zou3519 \r\n\r\nThanks for your reply!\r\nYour example is good. Any in-place change on x.detach() will cause errors when x is needed in backward, so .detach() is a safer way for the exclusion of subgraphs from gradient computation."}}
{"actor":{"display_login":"jay960702"}}