{"action":"created","comment":{"url":"https://api.github.com/repos/pytorch/pytorch/pulls/comments/218488153","pull_request_review_id":156437592,"id":218488153,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxODQ4ODE1Mw==","diff_hunk":"@@ -216,8 +220,11 @@ Tensor internal_new_from_data(const Type & type, at::optional<Device> device_opt\n                                                        *torch::getLayout(type.backend()),\n                                                        type_inference_device_type);\n       const auto& type_to_use = type_inference ? type_inference_type : type;\n-      return copy_variables ? new_with_tensor_copy(type_to_use, var, device_index) :\n+      auto new_tensor = copy_variables ? new_with_tensor_copy(type_to_use, var, device_index) :\n                               new_with_type_conversion(type_to_use, var, device_index);\n+      new_tensor.detach_(); // making copy constructed tensor a leaf node","path":"torch/csrc/utils/tensor_new.cpp","position":27,"original_position":27,"commit_id":"9c413bb5467a7c4b4ab376bc3abc4aa0d1077f62","original_commit_id":"9c413bb5467a7c4b4ab376bc3abc4aa0d1077f62","user":{"login":"apaszke","id":4583066,"node_id":"MDQ6VXNlcjQ1ODMwNjY=","avatar_url":"https://avatars3.githubusercontent.com/u/4583066?v=4","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},"body":"I'm pretty sure the `new_with_type_conversion` branch doesn't guarantee that it won't return the exact same variable (this is why we have the `copy_variables` flag!!), so this code is incorrect, and can modify the input to e.g. `torch.as_tensor`.","created_at":"2018-09-18T15:45:25Z","updated_at":"2018-09-18T15:45:46Z","html_url":"https://github.com/pytorch/pytorch/pull/11061#discussion_r218488153","pull_request_url":"https://api.github.com/repos/pytorch/pytorch/pulls/11061","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/comments/218488153"},"html":{"href":"https://github.com/pytorch/pytorch/pull/11061#discussion_r218488153"},"pull_request":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/11061"}}},"pull_request":{"url":"https://api.github.com/repos/pytorch/pytorch/pulls/11061","id":211941183,"node_id":"MDExOlB1bGxSZXF1ZXN0MjExOTQxMTgz","html_url":"https://github.com/pytorch/pytorch/pull/11061","diff_url":"https://github.com/pytorch/pytorch/pull/11061.diff","patch_url":"https://github.com/pytorch/pytorch/pull/11061.patch","issue_url":"https://api.github.com/repos/pytorch/pytorch/issues/11061","number":11061,"state":"closed","locked":false,"title":"[Easy] make copy constructed tensor a leaf variable when using torch.tensor(sourceTensor)","user":{"login":"weiyangfb","id":38509346,"node_id":"MDQ6VXNlcjM4NTA5MzQ2","avatar_url":"https://avatars1.githubusercontent.com/u/38509346?v=4","gravatar_id":"","url":"https://api.github.com/users/weiyangfb","html_url":"https://github.com/weiyangfb","followers_url":"https://api.github.com/users/weiyangfb/followers","following_url":"https://api.github.com/users/weiyangfb/following{/other_user}","gists_url":"https://api.github.com/users/weiyangfb/gists{/gist_id}","starred_url":"https://api.github.com/users/weiyangfb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weiyangfb/subscriptions","organizations_url":"https://api.github.com/users/weiyangfb/orgs","repos_url":"https://api.github.com/users/weiyangfb/repos","events_url":"https://api.github.com/users/weiyangfb/events{/privacy}","received_events_url":"https://api.github.com/users/weiyangfb/received_events","type":"User","site_admin":false},"body":"- fix https://github.com/pytorch/pytorch/issues/10876\r\n- the cause of the bug is because copy constructor cannot distinguish between default value of requires_grad and requires_grad=False, thus it makes a copy from source tensor along with its grad_fn if requires_grad=True at source\r\n- with this fix, the behavior becomes\r\n```\r\n>>> source = torch.randn(2, 2, requires_grad=True)\r\n>>> copy = torch.tensor(source, requires_grad=True)\r\n>>> print(copy)\r\ntensor([[-1.2001,  1.9869],\r\n        [-1.0134,  1.3096]], grad_fn=<CopyBackwards>)\r\n\r\n>>> source = torch.randn(2, 2, requires_grad=True)\r\n>>> copy = torch.tensor(source, requires_grad=False)\r\n>>> print(copy)\r\ntensor([[-0.7402,  0.0467],\r\n        [ 0.4344, -0.0420]])\r\n\r\n>>> source = torch.randn(2, 2, requires_grad=True)\r\n>>> copy = torch.tensor(source)\r\n>>> print(copy)\r\ntensor([[-0.7402,  0.0467],\r\n        [ 0.4344, -0.0420]])\r\n```","created_at":"2018-08-30T02:55:05Z","updated_at":"2018-09-18T15:45:46Z","closed_at":"2018-09-18T06:30:26Z","merged_at":null,"merge_commit_sha":"8e93c249e147e302e265e689e992311bf12e2eed","assignee":null,"assignees":[],"requested_reviewers":[{"login":"zdevito","id":370202,"node_id":"MDQ6VXNlcjM3MDIwMg==","avatar_url":"https://avatars0.githubusercontent.com/u/370202?v=4","gravatar_id":"","url":"https://api.github.com/users/zdevito","html_url":"https://github.com/zdevito","followers_url":"https://api.github.com/users/zdevito/followers","following_url":"https://api.github.com/users/zdevito/following{/other_user}","gists_url":"https://api.github.com/users/zdevito/gists{/gist_id}","starred_url":"https://api.github.com/users/zdevito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zdevito/subscriptions","organizations_url":"https://api.github.com/users/zdevito/orgs","repos_url":"https://api.github.com/users/zdevito/repos","events_url":"https://api.github.com/users/zdevito/events{/privacy}","received_events_url":"https://api.github.com/users/zdevito/received_events","type":"User","site_admin":false},{"login":"colesbury","id":655866,"node_id":"MDQ6VXNlcjY1NTg2Ng==","avatar_url":"https://avatars1.githubusercontent.com/u/655866?v=4","gravatar_id":"","url":"https://api.github.com/users/colesbury","html_url":"https://github.com/colesbury","followers_url":"https://api.github.com/users/colesbury/followers","following_url":"https://api.github.com/users/colesbury/following{/other_user}","gists_url":"https://api.github.com/users/colesbury/gists{/gist_id}","starred_url":"https://api.github.com/users/colesbury/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colesbury/subscriptions","organizations_url":"https://api.github.com/users/colesbury/orgs","repos_url":"https://api.github.com/users/colesbury/repos","events_url":"https://api.github.com/users/colesbury/events{/privacy}","received_events_url":"https://api.github.com/users/colesbury/received_events","type":"User","site_admin":false},{"login":"soumith","id":1310570,"node_id":"MDQ6VXNlcjEzMTA1NzA=","avatar_url":"https://avatars0.githubusercontent.com/u/1310570?v=4","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},{"login":"gchanan","id":3768583,"node_id":"MDQ6VXNlcjM3Njg1ODM=","avatar_url":"https://avatars2.githubusercontent.com/u/3768583?v=4","gravatar_id":"","url":"https://api.github.com/users/gchanan","html_url":"https://github.com/gchanan","followers_url":"https://api.github.com/users/gchanan/followers","following_url":"https://api.github.com/users/gchanan/following{/other_user}","gists_url":"https://api.github.com/users/gchanan/gists{/gist_id}","starred_url":"https://api.github.com/users/gchanan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gchanan/subscriptions","organizations_url":"https://api.github.com/users/gchanan/orgs","repos_url":"https://api.github.com/users/gchanan/repos","events_url":"https://api.github.com/users/gchanan/events{/privacy}","received_events_url":"https://api.github.com/users/gchanan/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":559719279,"node_id":"MDU6TGFiZWw1NTk3MTkyNzk=","url":"https://api.github.com/repos/pytorch/pytorch/labels/ready%20for%20review","name":"ready for review","color":"b60205","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/pytorch/pytorch/pulls/11061/commits","review_comments_url":"https://api.github.com/repos/pytorch/pytorch/pulls/11061/comments","review_comment_url":"https://api.github.com/repos/pytorch/pytorch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/11061/comments","statuses_url":"https://api.github.com/repos/pytorch/pytorch/statuses/9c413bb5467a7c4b4ab376bc3abc4aa0d1077f62","head":{"label":"weiyangfb:create_tensor_requires_grad_false","ref":"create_tensor_requires_grad_false","sha":"9c413bb5467a7c4b4ab376bc3abc4aa0d1077f62","user":{"login":"weiyangfb","id":38509346,"node_id":"MDQ6VXNlcjM4NTA5MzQ2","avatar_url":"https://avatars1.githubusercontent.com/u/38509346?v=4","gravatar_id":"","url":"https://api.github.com/users/weiyangfb","html_url":"https://github.com/weiyangfb","followers_url":"https://api.github.com/users/weiyangfb/followers","following_url":"https://api.github.com/users/weiyangfb/following{/other_user}","gists_url":"https://api.github.com/users/weiyangfb/gists{/gist_id}","starred_url":"https://api.github.com/users/weiyangfb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weiyangfb/subscriptions","organizations_url":"https://api.github.com/users/weiyangfb/orgs","repos_url":"https://api.github.com/users/weiyangfb/repos","events_url":"https://api.github.com/users/weiyangfb/events{/privacy}","received_events_url":"https://api.github.com/users/weiyangfb/received_events","type":"User","site_admin":false},"repo":{"id":130120335,"node_id":"MDEwOlJlcG9zaXRvcnkxMzAxMjAzMzU=","name":"pytorch","full_name":"weiyangfb/pytorch","private":false,"owner":{"login":"weiyangfb","id":38509346,"node_id":"MDQ6VXNlcjM4NTA5MzQ2","avatar_url":"https://avatars1.githubusercontent.com/u/38509346?v=4","gravatar_id":"","url":"https://api.github.com/users/weiyangfb","html_url":"https://github.com/weiyangfb","followers_url":"https://api.github.com/users/weiyangfb/followers","following_url":"https://api.github.com/users/weiyangfb/following{/other_user}","gists_url":"https://api.github.com/users/weiyangfb/gists{/gist_id}","starred_url":"https://api.github.com/users/weiyangfb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weiyangfb/subscriptions","organizations_url":"https://api.github.com/users/weiyangfb/orgs","repos_url":"https://api.github.com/users/weiyangfb/repos","events_url":"https://api.github.com/users/weiyangfb/events{/privacy}","received_events_url":"https://api.github.com/users/weiyangfb/received_events","type":"User","site_admin":false},"html_url":"https://github.com/weiyangfb/pytorch","description":"Tensors and Dynamic neural networks in Python  with strong GPU acceleration","fork":true,"url":"https://api.github.com/repos/weiyangfb/pytorch","forks_url":"https://api.github.com/repos/weiyangfb/pytorch/forks","keys_url":"https://api.github.com/repos/weiyangfb/pytorch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/weiyangfb/pytorch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/weiyangfb/pytorch/teams","hooks_url":"https://api.github.com/repos/weiyangfb/pytorch/hooks","issue_events_url":"https://api.github.com/repos/weiyangfb/pytorch/issues/events{/number}","events_url":"https://api.github.com/repos/weiyangfb/pytorch/events","assignees_url":"https://api.github.com/repos/weiyangfb/pytorch/assignees{/user}","branches_url":"https://api.github.com/repos/weiyangfb/pytorch/branches{/branch}","tags_url":"https://api.github.com/repos/weiyangfb/pytorch/tags","blobs_url":"https://api.github.com/repos/weiyangfb/pytorch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/weiyangfb/pytorch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/weiyangfb/pytorch/git/refs{/sha}","trees_url":"https://api.github.com/repos/weiyangfb/pytorch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/weiyangfb/pytorch/statuses/{sha}","languages_url":"https://api.github.com/repos/weiyangfb/pytorch/languages","stargazers_url":"https://api.github.com/repos/weiyangfb/pytorch/stargazers","contributors_url":"https://api.github.com/repos/weiyangfb/pytorch/contributors","subscribers_url":"https://api.github.com/repos/weiyangfb/pytorch/subscribers","subscription_url":"https://api.github.com/repos/weiyangfb/pytorch/subscription","commits_url":"https://api.github.com/repos/weiyangfb/pytorch/commits{/sha}","git_commits_url":"https://api.github.com/repos/weiyangfb/pytorch/git/commits{/sha}","comments_url":"https://api.github.com/repos/weiyangfb/pytorch/comments{/number}","issue_comment_url":"https://api.github.com/repos/weiyangfb/pytorch/issues/comments{/number}","contents_url":"https://api.github.com/repos/weiyangfb/pytorch/contents/{+path}","compare_url":"https://api.github.com/repos/weiyangfb/pytorch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/weiyangfb/pytorch/merges","archive_url":"https://api.github.com/repos/weiyangfb/pytorch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/weiyangfb/pytorch/downloads","issues_url":"https://api.github.com/repos/weiyangfb/pytorch/issues{/number}","pulls_url":"https://api.github.com/repos/weiyangfb/pytorch/pulls{/number}","milestones_url":"https://api.github.com/repos/weiyangfb/pytorch/milestones{/number}","notifications_url":"https://api.github.com/repos/weiyangfb/pytorch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/weiyangfb/pytorch/labels{/name}","releases_url":"https://api.github.com/repos/weiyangfb/pytorch/releases{/id}","deployments_url":"https://api.github.com/repos/weiyangfb/pytorch/deployments","created_at":"2018-04-18T20:49:19Z","updated_at":"2018-09-17T18:25:09Z","pushed_at":"2018-09-18T05:53:07Z","git_url":"git://github.com/weiyangfb/pytorch.git","ssh_url":"git@github.com:weiyangfb/pytorch.git","clone_url":"https://github.com/weiyangfb/pytorch.git","svn_url":"https://github.com/weiyangfb/pytorch","homepage":"http://pytorch.org","size":74127,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pytorch:master","ref":"master","sha":"a7cbcb1bb9f1b8244f2441a0fcc8d491677c988b","user":{"login":"pytorch","id":21003710,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMDAzNzEw","avatar_url":"https://avatars3.githubusercontent.com/u/21003710?v=4","gravatar_id":"","url":"https://api.github.com/users/pytorch","html_url":"https://github.com/pytorch","followers_url":"https://api.github.com/users/pytorch/followers","following_url":"https://api.github.com/users/pytorch/following{/other_user}","gists_url":"https://api.github.com/users/pytorch/gists{/gist_id}","starred_url":"https://api.github.com/users/pytorch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pytorch/subscriptions","organizations_url":"https://api.github.com/users/pytorch/orgs","repos_url":"https://api.github.com/users/pytorch/repos","events_url":"https://api.github.com/users/pytorch/events{/privacy}","received_events_url":"https://api.github.com/users/pytorch/received_events","type":"Organization","site_admin":false},"repo":{"id":65600975,"node_id":"MDEwOlJlcG9zaXRvcnk2NTYwMDk3NQ==","name":"pytorch","full_name":"pytorch/pytorch","private":false,"owner":{"login":"pytorch","id":21003710,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMDAzNzEw","avatar_url":"https://avatars3.githubusercontent.com/u/21003710?v=4","gravatar_id":"","url":"https://api.github.com/users/pytorch","html_url":"https://github.com/pytorch","followers_url":"https://api.github.com/users/pytorch/followers","following_url":"https://api.github.com/users/pytorch/following{/other_user}","gists_url":"https://api.github.com/users/pytorch/gists{/gist_id}","starred_url":"https://api.github.com/users/pytorch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pytorch/subscriptions","organizations_url":"https://api.github.com/users/pytorch/orgs","repos_url":"https://api.github.com/users/pytorch/repos","events_url":"https://api.github.com/users/pytorch/events{/privacy}","received_events_url":"https://api.github.com/users/pytorch/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/pytorch/pytorch","description":"Tensors and Dynamic neural networks in Python  with strong GPU acceleration","fork":false,"url":"https://api.github.com/repos/pytorch/pytorch","forks_url":"https://api.github.com/repos/pytorch/pytorch/forks","keys_url":"https://api.github.com/repos/pytorch/pytorch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pytorch/pytorch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pytorch/pytorch/teams","hooks_url":"https://api.github.com/repos/pytorch/pytorch/hooks","issue_events_url":"https://api.github.com/repos/pytorch/pytorch/issues/events{/number}","events_url":"https://api.github.com/repos/pytorch/pytorch/events","assignees_url":"https://api.github.com/repos/pytorch/pytorch/assignees{/user}","branches_url":"https://api.github.com/repos/pytorch/pytorch/branches{/branch}","tags_url":"https://api.github.com/repos/pytorch/pytorch/tags","blobs_url":"https://api.github.com/repos/pytorch/pytorch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pytorch/pytorch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pytorch/pytorch/git/refs{/sha}","trees_url":"https://api.github.com/repos/pytorch/pytorch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pytorch/pytorch/statuses/{sha}","languages_url":"https://api.github.com/repos/pytorch/pytorch/languages","stargazers_url":"https://api.github.com/repos/pytorch/pytorch/stargazers","contributors_url":"https://api.github.com/repos/pytorch/pytorch/contributors","subscribers_url":"https://api.github.com/repos/pytorch/pytorch/subscribers","subscription_url":"https://api.github.com/repos/pytorch/pytorch/subscription","commits_url":"https://api.github.com/repos/pytorch/pytorch/commits{/sha}","git_commits_url":"https://api.github.com/repos/pytorch/pytorch/git/commits{/sha}","comments_url":"https://api.github.com/repos/pytorch/pytorch/comments{/number}","issue_comment_url":"https://api.github.com/repos/pytorch/pytorch/issues/comments{/number}","contents_url":"https://api.github.com/repos/pytorch/pytorch/contents/{+path}","compare_url":"https://api.github.com/repos/pytorch/pytorch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pytorch/pytorch/merges","archive_url":"https://api.github.com/repos/pytorch/pytorch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pytorch/pytorch/downloads","issues_url":"https://api.github.com/repos/pytorch/pytorch/issues{/number}","pulls_url":"https://api.github.com/repos/pytorch/pytorch/pulls{/number}","milestones_url":"https://api.github.com/repos/pytorch/pytorch/milestones{/number}","notifications_url":"https://api.github.com/repos/pytorch/pytorch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pytorch/pytorch/labels{/name}","releases_url":"https://api.github.com/repos/pytorch/pytorch/releases{/id}","deployments_url":"https://api.github.com/repos/pytorch/pytorch/deployments","created_at":"2016-08-13T05:26:41Z","updated_at":"2018-09-18T15:45:43Z","pushed_at":"2018-09-18T15:37:39Z","git_url":"git://github.com/pytorch/pytorch.git","ssh_url":"git@github.com:pytorch/pytorch.git","clone_url":"https://github.com/pytorch/pytorch.git","svn_url":"https://github.com/pytorch/pytorch","homepage":"http://pytorch.org","size":75089,"stargazers_count":18769,"watchers_count":18769,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4490,"mirror_url":null,"archived":false,"open_issues_count":1737,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":4490,"open_issues":1737,"watchers":18769,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/11061"},"html":{"href":"https://github.com/pytorch/pytorch/pull/11061"},"issue":{"href":"https://api.github.com/repos/pytorch/pytorch/issues/11061"},"comments":{"href":"https://api.github.com/repos/pytorch/pytorch/issues/11061/comments"},"review_comments":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/11061/comments"},"review_comment":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/11061/commits"},"statuses":{"href":"https://api.github.com/repos/pytorch/pytorch/statuses/9c413bb5467a7c4b4ab376bc3abc4aa0d1077f62"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"apaszke"}}