{"action":"created","comment":{"url":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls/comments/208015380","pull_request_review_id":143743349,"id":208015380,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwODAxNTM4MA==","diff_hunk":"@@ -56,36 +61,46 @@ def _transpose_nonbatch(self):\n         return self\n \n     def _batch_get_indices(self, batch_indices, left_indices, right_indices):\n-        outer_size = batch_indices.size(0)\n-        inner_size = self.root.size(-1)\n-        inner_indices = Variable(right_indices.data.new(inner_size))\n-        torch.arange(0, inner_size, out=inner_indices.data)\n-\n-        left_vals = self.root._batch_get_indices(\n-            _outer_repeat(batch_indices, inner_size),\n-            _outer_repeat(left_indices, inner_size),\n-            _inner_repeat(inner_indices, outer_size),\n-        )\n-        right_vals = self.root.transpose(-1, -2)._batch_get_indices(\n-            _outer_repeat(batch_indices, inner_size),\n-            _inner_repeat(inner_indices, outer_size),\n-            _outer_repeat(right_indices, inner_size),\n-        )\n+        n_indices = left_indices.numel()\n+        if n_indices > self.size(-1) * self.size(-2) * self.size(-3):\n+            return self._evaluated[batch_indices, left_indices, right_indices]\n \n-        return (left_vals.view(-1, inner_size) * right_vals.view(-1, inner_size)).sum(-1)\n+        else:\n+            outer_size = batch_indices.size(0)\n+            inner_size = self.root.size(-1)\n+            inner_indices = right_indices.new(inner_size)\n+            torch.arange(0, inner_size, out=inner_indices.data)\n+\n+            left_vals = self.root._batch_get_indices(","path":"gpytorch/lazy/root_lazy_variable.py","position":51,"original_position":51,"commit_id":"f0eea66ce83fc59910c623aa4e50ddfdd1f3ae7b","original_commit_id":"f0eea66ce83fc59910c623aa4e50ddfdd1f3ae7b","user":{"login":"Balandat","id":1605878,"node_id":"MDQ6VXNlcjE2MDU4Nzg=","avatar_url":"https://avatars2.githubusercontent.com/u/1605878?v=4","gravatar_id":"","url":"https://api.github.com/users/Balandat","html_url":"https://github.com/Balandat","followers_url":"https://api.github.com/users/Balandat/followers","following_url":"https://api.github.com/users/Balandat/following{/other_user}","gists_url":"https://api.github.com/users/Balandat/gists{/gist_id}","starred_url":"https://api.github.com/users/Balandat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Balandat/subscriptions","organizations_url":"https://api.github.com/users/Balandat/orgs","repos_url":"https://api.github.com/users/Balandat/repos","events_url":"https://api.github.com/users/Balandat/events{/privacy}","received_events_url":"https://api.github.com/users/Balandat/received_events","type":"User","site_admin":false},"body":"again you can avoid re-doing computations here","created_at":"2018-08-06T20:15:27Z","updated_at":"2018-08-06T20:16:36Z","html_url":"https://github.com/cornellius-gp/gpytorch/pull/221#discussion_r208015380","pull_request_url":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls/221","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls/comments/208015380"},"html":{"href":"https://github.com/cornellius-gp/gpytorch/pull/221#discussion_r208015380"},"pull_request":{"href":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls/221"}}},"pull_request":{"url":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls/221","id":206487494,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA2NDg3NDk0","html_url":"https://github.com/cornellius-gp/gpytorch/pull/221","diff_url":"https://github.com/cornellius-gp/gpytorch/pull/221.diff","patch_url":"https://github.com/cornellius-gp/gpytorch/pull/221.patch","issue_url":"https://api.github.com/repos/cornellius-gp/gpytorch/issues/221","number":221,"state":"open","locked":false,"title":"Speed up Root/Matmul LV get_indices","user":{"login":"gpleiss","id":824157,"node_id":"MDQ6VXNlcjgyNDE1Nw==","avatar_url":"https://avatars0.githubusercontent.com/u/824157?v=4","gravatar_id":"","url":"https://api.github.com/users/gpleiss","html_url":"https://github.com/gpleiss","followers_url":"https://api.github.com/users/gpleiss/followers","following_url":"https://api.github.com/users/gpleiss/following{/other_user}","gists_url":"https://api.github.com/users/gpleiss/gists{/gist_id}","starred_url":"https://api.github.com/users/gpleiss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gpleiss/subscriptions","organizations_url":"https://api.github.com/users/gpleiss/orgs","repos_url":"https://api.github.com/users/gpleiss/repos","events_url":"https://api.github.com/users/gpleiss/events{/privacy}","received_events_url":"https://api.github.com/users/gpleiss/received_events","type":"User","site_admin":false},"body":"- When calling `get_indices` with many indices, explicitly evaluate the LazyVariable.\r\n- Remove old Variable references\r\n\r\n`_get_indices` is called during the diag method for variational inference. If we want `m` indices, and the RootLazyVariable is a `n x r` matrix, then the standard `_get_indices` call requires `m * r` memory. If `m` is large (which is usually the case for variational), then this will be extremely memory intensive.\r\n\r\nFix: do whatever requires the least amount of memory:\r\n- If `m * r` > `n x n`, then explicitly evaluate the LazyVariable and then call `_get_indices`.\r\n- Otherwise, use the original `_get_indices` routine.","created_at":"2018-08-06T18:59:30Z","updated_at":"2018-08-06T20:16:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"69afeb6a54aa80cbd0d64a0dc1464a036b01df87","assignee":null,"assignees":[],"requested_reviewers":[{"login":"jacobrgardner","id":4016393,"node_id":"MDQ6VXNlcjQwMTYzOTM=","avatar_url":"https://avatars0.githubusercontent.com/u/4016393?v=4","gravatar_id":"","url":"https://api.github.com/users/jacobrgardner","html_url":"https://github.com/jacobrgardner","followers_url":"https://api.github.com/users/jacobrgardner/followers","following_url":"https://api.github.com/users/jacobrgardner/following{/other_user}","gists_url":"https://api.github.com/users/jacobrgardner/gists{/gist_id}","starred_url":"https://api.github.com/users/jacobrgardner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacobrgardner/subscriptions","organizations_url":"https://api.github.com/users/jacobrgardner/orgs","repos_url":"https://api.github.com/users/jacobrgardner/repos","events_url":"https://api.github.com/users/jacobrgardner/events{/privacy}","received_events_url":"https://api.github.com/users/jacobrgardner/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":623304446,"node_id":"MDU6TGFiZWw2MjMzMDQ0NDY=","url":"https://api.github.com/repos/cornellius-gp/gpytorch/labels/bug","name":"bug","color":"ee0701","default":true}],"milestone":null,"commits_url":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls/221/commits","review_comments_url":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls/221/comments","review_comment_url":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cornellius-gp/gpytorch/issues/221/comments","statuses_url":"https://api.github.com/repos/cornellius-gp/gpytorch/statuses/f0eea66ce83fc59910c623aa4e50ddfdd1f3ae7b","head":{"label":"cornellius-gp:diag_fix","ref":"diag_fix","sha":"f0eea66ce83fc59910c623aa4e50ddfdd1f3ae7b","user":{"login":"cornellius-gp","id":36548216,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NTQ4MjE2","avatar_url":"https://avatars2.githubusercontent.com/u/36548216?v=4","gravatar_id":"","url":"https://api.github.com/users/cornellius-gp","html_url":"https://github.com/cornellius-gp","followers_url":"https://api.github.com/users/cornellius-gp/followers","following_url":"https://api.github.com/users/cornellius-gp/following{/other_user}","gists_url":"https://api.github.com/users/cornellius-gp/gists{/gist_id}","starred_url":"https://api.github.com/users/cornellius-gp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cornellius-gp/subscriptions","organizations_url":"https://api.github.com/users/cornellius-gp/orgs","repos_url":"https://api.github.com/users/cornellius-gp/repos","events_url":"https://api.github.com/users/cornellius-gp/events{/privacy}","received_events_url":"https://api.github.com/users/cornellius-gp/received_events","type":"Organization","site_admin":false},"repo":{"id":93868719,"node_id":"MDEwOlJlcG9zaXRvcnk5Mzg2ODcxOQ==","name":"gpytorch","full_name":"cornellius-gp/gpytorch","owner":{"login":"cornellius-gp","id":36548216,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NTQ4MjE2","avatar_url":"https://avatars2.githubusercontent.com/u/36548216?v=4","gravatar_id":"","url":"https://api.github.com/users/cornellius-gp","html_url":"https://github.com/cornellius-gp","followers_url":"https://api.github.com/users/cornellius-gp/followers","following_url":"https://api.github.com/users/cornellius-gp/following{/other_user}","gists_url":"https://api.github.com/users/cornellius-gp/gists{/gist_id}","starred_url":"https://api.github.com/users/cornellius-gp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cornellius-gp/subscriptions","organizations_url":"https://api.github.com/users/cornellius-gp/orgs","repos_url":"https://api.github.com/users/cornellius-gp/repos","events_url":"https://api.github.com/users/cornellius-gp/events{/privacy}","received_events_url":"https://api.github.com/users/cornellius-gp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cornellius-gp/gpytorch","description":"A highly efficient and modular implementation of Gaussian Processes in PyTorch","fork":false,"url":"https://api.github.com/repos/cornellius-gp/gpytorch","forks_url":"https://api.github.com/repos/cornellius-gp/gpytorch/forks","keys_url":"https://api.github.com/repos/cornellius-gp/gpytorch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cornellius-gp/gpytorch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cornellius-gp/gpytorch/teams","hooks_url":"https://api.github.com/repos/cornellius-gp/gpytorch/hooks","issue_events_url":"https://api.github.com/repos/cornellius-gp/gpytorch/issues/events{/number}","events_url":"https://api.github.com/repos/cornellius-gp/gpytorch/events","assignees_url":"https://api.github.com/repos/cornellius-gp/gpytorch/assignees{/user}","branches_url":"https://api.github.com/repos/cornellius-gp/gpytorch/branches{/branch}","tags_url":"https://api.github.com/repos/cornellius-gp/gpytorch/tags","blobs_url":"https://api.github.com/repos/cornellius-gp/gpytorch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cornellius-gp/gpytorch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cornellius-gp/gpytorch/git/refs{/sha}","trees_url":"https://api.github.com/repos/cornellius-gp/gpytorch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cornellius-gp/gpytorch/statuses/{sha}","languages_url":"https://api.github.com/repos/cornellius-gp/gpytorch/languages","stargazers_url":"https://api.github.com/repos/cornellius-gp/gpytorch/stargazers","contributors_url":"https://api.github.com/repos/cornellius-gp/gpytorch/contributors","subscribers_url":"https://api.github.com/repos/cornellius-gp/gpytorch/subscribers","subscription_url":"https://api.github.com/repos/cornellius-gp/gpytorch/subscription","commits_url":"https://api.github.com/repos/cornellius-gp/gpytorch/commits{/sha}","git_commits_url":"https://api.github.com/repos/cornellius-gp/gpytorch/git/commits{/sha}","comments_url":"https://api.github.com/repos/cornellius-gp/gpytorch/comments{/number}","issue_comment_url":"https://api.github.com/repos/cornellius-gp/gpytorch/issues/comments{/number}","contents_url":"https://api.github.com/repos/cornellius-gp/gpytorch/contents/{+path}","compare_url":"https://api.github.com/repos/cornellius-gp/gpytorch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cornellius-gp/gpytorch/merges","archive_url":"https://api.github.com/repos/cornellius-gp/gpytorch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cornellius-gp/gpytorch/downloads","issues_url":"https://api.github.com/repos/cornellius-gp/gpytorch/issues{/number}","pulls_url":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls{/number}","milestones_url":"https://api.github.com/repos/cornellius-gp/gpytorch/milestones{/number}","notifications_url":"https://api.github.com/repos/cornellius-gp/gpytorch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cornellius-gp/gpytorch/labels{/name}","releases_url":"https://api.github.com/repos/cornellius-gp/gpytorch/releases{/id}","deployments_url":"https://api.github.com/repos/cornellius-gp/gpytorch/deployments","created_at":"2017-06-09T14:48:20Z","updated_at":"2018-08-04T18:15:59Z","pushed_at":"2018-08-06T19:19:43Z","git_url":"git://github.com/cornellius-gp/gpytorch.git","ssh_url":"git@github.com:cornellius-gp/gpytorch.git","clone_url":"https://github.com/cornellius-gp/gpytorch.git","svn_url":"https://github.com/cornellius-gp/gpytorch","homepage":"","size":6362,"stargazers_count":484,"watchers_count":484,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":58,"mirror_url":null,"archived":false,"open_issues_count":33,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":58,"open_issues":33,"watchers":484,"default_branch":"master"}},"base":{"label":"cornellius-gp:master","ref":"master","sha":"1c8f891981a3d50e57017c7d53f25f7992f000a3","user":{"login":"cornellius-gp","id":36548216,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NTQ4MjE2","avatar_url":"https://avatars2.githubusercontent.com/u/36548216?v=4","gravatar_id":"","url":"https://api.github.com/users/cornellius-gp","html_url":"https://github.com/cornellius-gp","followers_url":"https://api.github.com/users/cornellius-gp/followers","following_url":"https://api.github.com/users/cornellius-gp/following{/other_user}","gists_url":"https://api.github.com/users/cornellius-gp/gists{/gist_id}","starred_url":"https://api.github.com/users/cornellius-gp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cornellius-gp/subscriptions","organizations_url":"https://api.github.com/users/cornellius-gp/orgs","repos_url":"https://api.github.com/users/cornellius-gp/repos","events_url":"https://api.github.com/users/cornellius-gp/events{/privacy}","received_events_url":"https://api.github.com/users/cornellius-gp/received_events","type":"Organization","site_admin":false},"repo":{"id":93868719,"node_id":"MDEwOlJlcG9zaXRvcnk5Mzg2ODcxOQ==","name":"gpytorch","full_name":"cornellius-gp/gpytorch","owner":{"login":"cornellius-gp","id":36548216,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NTQ4MjE2","avatar_url":"https://avatars2.githubusercontent.com/u/36548216?v=4","gravatar_id":"","url":"https://api.github.com/users/cornellius-gp","html_url":"https://github.com/cornellius-gp","followers_url":"https://api.github.com/users/cornellius-gp/followers","following_url":"https://api.github.com/users/cornellius-gp/following{/other_user}","gists_url":"https://api.github.com/users/cornellius-gp/gists{/gist_id}","starred_url":"https://api.github.com/users/cornellius-gp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cornellius-gp/subscriptions","organizations_url":"https://api.github.com/users/cornellius-gp/orgs","repos_url":"https://api.github.com/users/cornellius-gp/repos","events_url":"https://api.github.com/users/cornellius-gp/events{/privacy}","received_events_url":"https://api.github.com/users/cornellius-gp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cornellius-gp/gpytorch","description":"A highly efficient and modular implementation of Gaussian Processes in PyTorch","fork":false,"url":"https://api.github.com/repos/cornellius-gp/gpytorch","forks_url":"https://api.github.com/repos/cornellius-gp/gpytorch/forks","keys_url":"https://api.github.com/repos/cornellius-gp/gpytorch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cornellius-gp/gpytorch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cornellius-gp/gpytorch/teams","hooks_url":"https://api.github.com/repos/cornellius-gp/gpytorch/hooks","issue_events_url":"https://api.github.com/repos/cornellius-gp/gpytorch/issues/events{/number}","events_url":"https://api.github.com/repos/cornellius-gp/gpytorch/events","assignees_url":"https://api.github.com/repos/cornellius-gp/gpytorch/assignees{/user}","branches_url":"https://api.github.com/repos/cornellius-gp/gpytorch/branches{/branch}","tags_url":"https://api.github.com/repos/cornellius-gp/gpytorch/tags","blobs_url":"https://api.github.com/repos/cornellius-gp/gpytorch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cornellius-gp/gpytorch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cornellius-gp/gpytorch/git/refs{/sha}","trees_url":"https://api.github.com/repos/cornellius-gp/gpytorch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cornellius-gp/gpytorch/statuses/{sha}","languages_url":"https://api.github.com/repos/cornellius-gp/gpytorch/languages","stargazers_url":"https://api.github.com/repos/cornellius-gp/gpytorch/stargazers","contributors_url":"https://api.github.com/repos/cornellius-gp/gpytorch/contributors","subscribers_url":"https://api.github.com/repos/cornellius-gp/gpytorch/subscribers","subscription_url":"https://api.github.com/repos/cornellius-gp/gpytorch/subscription","commits_url":"https://api.github.com/repos/cornellius-gp/gpytorch/commits{/sha}","git_commits_url":"https://api.github.com/repos/cornellius-gp/gpytorch/git/commits{/sha}","comments_url":"https://api.github.com/repos/cornellius-gp/gpytorch/comments{/number}","issue_comment_url":"https://api.github.com/repos/cornellius-gp/gpytorch/issues/comments{/number}","contents_url":"https://api.github.com/repos/cornellius-gp/gpytorch/contents/{+path}","compare_url":"https://api.github.com/repos/cornellius-gp/gpytorch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cornellius-gp/gpytorch/merges","archive_url":"https://api.github.com/repos/cornellius-gp/gpytorch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cornellius-gp/gpytorch/downloads","issues_url":"https://api.github.com/repos/cornellius-gp/gpytorch/issues{/number}","pulls_url":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls{/number}","milestones_url":"https://api.github.com/repos/cornellius-gp/gpytorch/milestones{/number}","notifications_url":"https://api.github.com/repos/cornellius-gp/gpytorch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cornellius-gp/gpytorch/labels{/name}","releases_url":"https://api.github.com/repos/cornellius-gp/gpytorch/releases{/id}","deployments_url":"https://api.github.com/repos/cornellius-gp/gpytorch/deployments","created_at":"2017-06-09T14:48:20Z","updated_at":"2018-08-04T18:15:59Z","pushed_at":"2018-08-06T19:19:43Z","git_url":"git://github.com/cornellius-gp/gpytorch.git","ssh_url":"git@github.com:cornellius-gp/gpytorch.git","clone_url":"https://github.com/cornellius-gp/gpytorch.git","svn_url":"https://github.com/cornellius-gp/gpytorch","homepage":"","size":6362,"stargazers_count":484,"watchers_count":484,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":58,"mirror_url":null,"archived":false,"open_issues_count":33,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":58,"open_issues":33,"watchers":484,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls/221"},"html":{"href":"https://github.com/cornellius-gp/gpytorch/pull/221"},"issue":{"href":"https://api.github.com/repos/cornellius-gp/gpytorch/issues/221"},"comments":{"href":"https://api.github.com/repos/cornellius-gp/gpytorch/issues/221/comments"},"review_comments":{"href":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls/221/comments"},"review_comment":{"href":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cornellius-gp/gpytorch/pulls/221/commits"},"statuses":{"href":"https://api.github.com/repos/cornellius-gp/gpytorch/statuses/f0eea66ce83fc59910c623aa4e50ddfdd1f3ae7b"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"Balandat"}}