{"action":"created","comment":{"url":"https://api.github.com/repos/pytorch/pytorch/pulls/comments/153102106","pull_request_review_id":79059036,"id":153102106,"diff_hunk":"@@ -20,19 +20,53 @@ using operator_constructor = std::function<TensorOp(jit::Node*)>;\n \n namespace {\n \n-void pack_list(std::vector<Tensor> & outputs, Tensor v) { outputs.push_back(v); }\n-void pack_list(std::vector<Tensor> & outputs, Scalar v) { outputs.push_back(v.toTensor()); }\n-void pack_list(std::vector<Tensor> & outputs, const std::vector<Tensor> & t) {\n-  outputs.insert(outputs.end(), t.begin(), t.end());\n+// a temporary Tensor that does not alter the refcount of impl on\n+// acquisition or release, avoids any refcounting in dispatch functions\n+struct TensorTemporary : public at::Tensor {\n+  explicit TensorTemporary(at::RefCounted * impl)\n+  : at::Tensor(static_cast<at::TensorImpl*>(impl), false /* do not retain*/) {}\n+  ~TensorTemporary() {\n+    detach(); // reset\n+  }\n+};\n+\n+// same thing but creates a tensor list, only used rarely (e.g. for cat)\n+struct TensorTemporaryList {","path":"tools/jit/templates/aten_dispatch.cpp","position":19,"original_position":19,"commit_id":"1c5a385c904352750860eb388e46801d8de5d803","original_commit_id":"1c5a385c904352750860eb388e46801d8de5d803","user":{"login":"ezyang","id":13564,"avatar_url":"https://avatars0.githubusercontent.com/u/13564?v=4","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},"body":"I had to do some mental work to convince myself this was safe, it might be worth writing down: the key is that a `TensorTemporaryList` only exposes a `TensorList`, not its underlying `std::vector<at::Tensor>`. This ArrayRef has the desired semantics: if you get out an `at::Tensor` from it, the refcount is bumped; if you take a reference, it is only guaranteed to stay live as long as the ArrayRef is live, which is exactly the guarantee you need to use this safely.","created_at":"2017-11-27T03:50:28Z","updated_at":"2017-11-27T03:50:28Z","html_url":"https://github.com/pytorch/pytorch/pull/3866#discussion_r153102106","pull_request_url":"https://api.github.com/repos/pytorch/pytorch/pulls/3866","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/comments/153102106"},"html":{"href":"https://github.com/pytorch/pytorch/pull/3866#discussion_r153102106"},"pull_request":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/3866"}}},"pull_request":{"url":"https://api.github.com/repos/pytorch/pytorch/pulls/3866","id":154622093,"html_url":"https://github.com/pytorch/pytorch/pull/3866","diff_url":"https://github.com/pytorch/pytorch/pull/3866.diff","patch_url":"https://github.com/pytorch/pytorch/pull/3866.patch","issue_url":"https://api.github.com/repos/pytorch/pytorch/issues/3866","number":3866,"state":"open","locked":false,"title":"Add interpreter support for Handles/PythonOp/CppOp","user":{"login":"zdevito","id":370202,"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},"body":"This treats Handles as a first-class type in the interpreter\r\nsince this turned out to be conceptually simpler than treating\r\nthem as a separate concept, which requires a second channel for\r\nregister allocating and moving data from one op to the next.\r\n\r\nNotes:\r\n* The refcounting nature of tensors is factored into its own base type\r\nso that it can be shared with other refcounted types such as handle.\r\n* Some methods redundant with TensorBase have been deleted from Tensor\r\n* The interpreter uses raw refcounted handles. In addition to being\r\nable to treat Tensors and Handles as the same base object, it removes\r\na lot of redundant refcounting as objects moved from tensors to input/\r\noutput lists.\r\n* aten_dispatch has been updated to work directly on the raw refcounted\r\nlists to avoid refcounting and duplicate lists.\r\n* PythonOp and CppOp gain VariableFlags lists so that the interpreter knows how the bodies of those operators should be executed.","created_at":"2017-11-25T03:17:35Z","updated_at":"2017-11-27T03:50:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8d5bba822d5ebaaa043c97461c2f722af771c2df","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/pytorch/pytorch/pulls/3866/commits","review_comments_url":"https://api.github.com/repos/pytorch/pytorch/pulls/3866/comments","review_comment_url":"https://api.github.com/repos/pytorch/pytorch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/3866/comments","statuses_url":"https://api.github.com/repos/pytorch/pytorch/statuses/1c5a385c904352750860eb388e46801d8de5d803","head":{"label":"zdevito:pr/interp_pythonops","ref":"pr/interp_pythonops","sha":"1c5a385c904352750860eb388e46801d8de5d803","user":{"login":"zdevito","id":370202,"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},"repo":{"id":93195556,"name":"pytorch","full_name":"zdevito/pytorch","owner":{"login":"zdevito","id":370202,"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},"private":false,"html_url":"https://github.com/zdevito/pytorch","description":"Tensors and Dynamic neural networks in Python  with strong GPU acceleration","fork":true,"url":"https://api.github.com/repos/zdevito/pytorch","forks_url":"https://api.github.com/repos/zdevito/pytorch/forks","keys_url":"https://api.github.com/repos/zdevito/pytorch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zdevito/pytorch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zdevito/pytorch/teams","hooks_url":"https://api.github.com/repos/zdevito/pytorch/hooks","issue_events_url":"https://api.github.com/repos/zdevito/pytorch/issues/events{/number}","events_url":"https://api.github.com/repos/zdevito/pytorch/events","assignees_url":"https://api.github.com/repos/zdevito/pytorch/assignees{/user}","branches_url":"https://api.github.com/repos/zdevito/pytorch/branches{/branch}","tags_url":"https://api.github.com/repos/zdevito/pytorch/tags","blobs_url":"https://api.github.com/repos/zdevito/pytorch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zdevito/pytorch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zdevito/pytorch/git/refs{/sha}","trees_url":"https://api.github.com/repos/zdevito/pytorch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zdevito/pytorch/statuses/{sha}","languages_url":"https://api.github.com/repos/zdevito/pytorch/languages","stargazers_url":"https://api.github.com/repos/zdevito/pytorch/stargazers","contributors_url":"https://api.github.com/repos/zdevito/pytorch/contributors","subscribers_url":"https://api.github.com/repos/zdevito/pytorch/subscribers","subscription_url":"https://api.github.com/repos/zdevito/pytorch/subscription","commits_url":"https://api.github.com/repos/zdevito/pytorch/commits{/sha}","git_commits_url":"https://api.github.com/repos/zdevito/pytorch/git/commits{/sha}","comments_url":"https://api.github.com/repos/zdevito/pytorch/comments{/number}","issue_comment_url":"https://api.github.com/repos/zdevito/pytorch/issues/comments{/number}","contents_url":"https://api.github.com/repos/zdevito/pytorch/contents/{+path}","compare_url":"https://api.github.com/repos/zdevito/pytorch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zdevito/pytorch/merges","archive_url":"https://api.github.com/repos/zdevito/pytorch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zdevito/pytorch/downloads","issues_url":"https://api.github.com/repos/zdevito/pytorch/issues{/number}","pulls_url":"https://api.github.com/repos/zdevito/pytorch/pulls{/number}","milestones_url":"https://api.github.com/repos/zdevito/pytorch/milestones{/number}","notifications_url":"https://api.github.com/repos/zdevito/pytorch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zdevito/pytorch/labels{/name}","releases_url":"https://api.github.com/repos/zdevito/pytorch/releases{/id}","deployments_url":"https://api.github.com/repos/zdevito/pytorch/deployments","created_at":"2017-06-02T19:00:07Z","updated_at":"2017-06-06T13:45:11Z","pushed_at":"2017-11-26T22:10:19Z","git_url":"git://github.com/zdevito/pytorch.git","ssh_url":"git@github.com:zdevito/pytorch.git","clone_url":"https://github.com/zdevito/pytorch.git","svn_url":"https://github.com/zdevito/pytorch","homepage":"http://pytorch.org","size":18591,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":0,"default_branch":"master"}},"base":{"label":"pytorch:master","ref":"master","sha":"ed640010ce5fa675c42c22ce189a11b418a48d43","user":{"login":"pytorch","id":21003710,"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,"name":"pytorch","full_name":"pytorch/pytorch","owner":{"login":"pytorch","id":21003710,"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},"private":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":"2017-11-27T03:50:26Z","pushed_at":"2017-11-27T00:09:41Z","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":18551,"stargazers_count":9524,"watchers_count":9524,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2016,"mirror_url":null,"archived":false,"open_issues_count":526,"forks":2016,"open_issues":526,"watchers":9524,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/3866"},"html":{"href":"https://github.com/pytorch/pytorch/pull/3866"},"issue":{"href":"https://api.github.com/repos/pytorch/pytorch/issues/3866"},"comments":{"href":"https://api.github.com/repos/pytorch/pytorch/issues/3866/comments"},"review_comments":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/3866/comments"},"review_comment":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/3866/commits"},"statuses":{"href":"https://api.github.com/repos/pytorch/pytorch/statuses/1c5a385c904352750860eb388e46801d8de5d803"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"ezyang"}}