{"action":"closed","number":5021,"pull_request":{"url":"https://api.github.com/repos/pytorch/pytorch/pulls/5021","id":166894117,"html_url":"https://github.com/pytorch/pytorch/pull/5021","diff_url":"https://github.com/pytorch/pytorch/pull/5021.diff","patch_url":"https://github.com/pytorch/pytorch/pull/5021.patch","issue_url":"https://api.github.com/repos/pytorch/pytorch/issues/5021","number":5021,"state":"closed","locked":false,"title":"[WIP] Add XPU abstraction (Input Requested)","user":{"login":"Erotemic","id":3186211,"avatar_url":"https://avatars3.githubusercontent.com/u/3186211?v=4","gravatar_id":"","url":"https://api.github.com/users/Erotemic","html_url":"https://github.com/Erotemic","followers_url":"https://api.github.com/users/Erotemic/followers","following_url":"https://api.github.com/users/Erotemic/following{/other_user}","gists_url":"https://api.github.com/users/Erotemic/gists{/gist_id}","starred_url":"https://api.github.com/users/Erotemic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Erotemic/subscriptions","organizations_url":"https://api.github.com/users/Erotemic/orgs","repos_url":"https://api.github.com/users/Erotemic/repos","events_url":"https://api.github.com/users/Erotemic/events{/privacy}","received_events_url":"https://api.github.com/users/Erotemic/received_events","type":"User","site_admin":false},"body":"### Overview\r\n\r\nThis PR is a proposal to add the class `XPU` to pytorch. Currently the APIs used to write CPU and GPU code are different. It is tricky to parameterize them via a function argument. This creates unnecessarily branches in the code and increases the difficulty of testing and writing robust code. To solve this I've developed the class XPU that creates a common interface allowing seamless switching between using a CPU, GPU, or even multiple GPUs. \r\n\r\nThe basic idea is that when constructing a XPU you give it either None to represent CPU mode and an integer or list of integers to support GPU mode. The classmethod `cast('auto')` attempts to be smart and respects command line args if they are given, otherwise it choose sthe GPU with the lowest amount of memory if one exists, or the CPU.  \r\n\r\n```python\r\n>>> xpu = XPU('auto')\r\n```\r\n\r\nThen to move data onto either the cpu or gpu you run:\r\n\r\n```python\r\n>>> xpu.move(data)\r\n```\r\n\r\nInstead of one of the following:\r\n \r\n```python\r\n>>> data.cpu()\r\n>>> data.gpu(0)\r\n```\r\n\r\nFurthemore, `XPU` provides a convenience method for creating variables\r\n\r\n```python \r\n>>> var1 = xpu.variable(data1)\r\n>>> # I've also found it helpful to have a wrapper that processes more than one at a time (but maybe that design isn't clean, it could be removed)\r\n>>> var2, var3, *varsN = xpu.variables(data2, data3, *datasN)\r\n```\r\n\r\nLastly, to seamlessly support multiple GPUs, instead of calling `xpu.move` on a model, we mount it.\r\n\r\n```python\r\nmodel = xpu.mount(model)\r\n```\r\n\r\nThis is effectively the same as move unless the XPU is multiple GPUs, in which case it wraps model with a `DataParallel` object. (This requires the creation of a DataSerial wrapper to provide a consistent API). \r\n\r\n### Status\r\n\r\nCurrently, I've just dumped the `xpu_device.py` file that I use in my scripts into the torch module. I put a few unit tests in that same file, but its by no means fully tested. I want to see what other people have to say and hear comments, criticisms, and suggestions before I work on integration. ","created_at":"2018-02-02T20:17:33Z","updated_at":"2018-05-18T13:13:02Z","closed_at":"2018-05-18T13:13:01Z","merged_at":null,"merge_commit_sha":"a9ed7d5bdd5f5f14fa89cff094a94677f0451978","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/pytorch/pytorch/pulls/5021/commits","review_comments_url":"https://api.github.com/repos/pytorch/pytorch/pulls/5021/comments","review_comment_url":"https://api.github.com/repos/pytorch/pytorch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/5021/comments","statuses_url":"https://api.github.com/repos/pytorch/pytorch/statuses/3f9c2c1735e8955ecaf8f058b720c436890b0f87","head":{"label":"Erotemic:xpu","ref":"xpu","sha":"3f9c2c1735e8955ecaf8f058b720c436890b0f87","user":{"login":"Erotemic","id":3186211,"avatar_url":"https://avatars3.githubusercontent.com/u/3186211?v=4","gravatar_id":"","url":"https://api.github.com/users/Erotemic","html_url":"https://github.com/Erotemic","followers_url":"https://api.github.com/users/Erotemic/followers","following_url":"https://api.github.com/users/Erotemic/following{/other_user}","gists_url":"https://api.github.com/users/Erotemic/gists{/gist_id}","starred_url":"https://api.github.com/users/Erotemic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Erotemic/subscriptions","organizations_url":"https://api.github.com/users/Erotemic/orgs","repos_url":"https://api.github.com/users/Erotemic/repos","events_url":"https://api.github.com/users/Erotemic/events{/privacy}","received_events_url":"https://api.github.com/users/Erotemic/received_events","type":"User","site_admin":false},"repo":{"id":108485506,"name":"pytorch","full_name":"Erotemic/pytorch","owner":{"login":"Erotemic","id":3186211,"avatar_url":"https://avatars3.githubusercontent.com/u/3186211?v=4","gravatar_id":"","url":"https://api.github.com/users/Erotemic","html_url":"https://github.com/Erotemic","followers_url":"https://api.github.com/users/Erotemic/followers","following_url":"https://api.github.com/users/Erotemic/following{/other_user}","gists_url":"https://api.github.com/users/Erotemic/gists{/gist_id}","starred_url":"https://api.github.com/users/Erotemic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Erotemic/subscriptions","organizations_url":"https://api.github.com/users/Erotemic/orgs","repos_url":"https://api.github.com/users/Erotemic/repos","events_url":"https://api.github.com/users/Erotemic/events{/privacy}","received_events_url":"https://api.github.com/users/Erotemic/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Erotemic/pytorch","description":"Tensors and Dynamic neural networks in Python  with strong GPU acceleration","fork":true,"url":"https://api.github.com/repos/Erotemic/pytorch","forks_url":"https://api.github.com/repos/Erotemic/pytorch/forks","keys_url":"https://api.github.com/repos/Erotemic/pytorch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Erotemic/pytorch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Erotemic/pytorch/teams","hooks_url":"https://api.github.com/repos/Erotemic/pytorch/hooks","issue_events_url":"https://api.github.com/repos/Erotemic/pytorch/issues/events{/number}","events_url":"https://api.github.com/repos/Erotemic/pytorch/events","assignees_url":"https://api.github.com/repos/Erotemic/pytorch/assignees{/user}","branches_url":"https://api.github.com/repos/Erotemic/pytorch/branches{/branch}","tags_url":"https://api.github.com/repos/Erotemic/pytorch/tags","blobs_url":"https://api.github.com/repos/Erotemic/pytorch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Erotemic/pytorch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Erotemic/pytorch/git/refs{/sha}","trees_url":"https://api.github.com/repos/Erotemic/pytorch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Erotemic/pytorch/statuses/{sha}","languages_url":"https://api.github.com/repos/Erotemic/pytorch/languages","stargazers_url":"https://api.github.com/repos/Erotemic/pytorch/stargazers","contributors_url":"https://api.github.com/repos/Erotemic/pytorch/contributors","subscribers_url":"https://api.github.com/repos/Erotemic/pytorch/subscribers","subscription_url":"https://api.github.com/repos/Erotemic/pytorch/subscription","commits_url":"https://api.github.com/repos/Erotemic/pytorch/commits{/sha}","git_commits_url":"https://api.github.com/repos/Erotemic/pytorch/git/commits{/sha}","comments_url":"https://api.github.com/repos/Erotemic/pytorch/comments{/number}","issue_comment_url":"https://api.github.com/repos/Erotemic/pytorch/issues/comments{/number}","contents_url":"https://api.github.com/repos/Erotemic/pytorch/contents/{+path}","compare_url":"https://api.github.com/repos/Erotemic/pytorch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Erotemic/pytorch/merges","archive_url":"https://api.github.com/repos/Erotemic/pytorch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Erotemic/pytorch/downloads","issues_url":"https://api.github.com/repos/Erotemic/pytorch/issues{/number}","pulls_url":"https://api.github.com/repos/Erotemic/pytorch/pulls{/number}","milestones_url":"https://api.github.com/repos/Erotemic/pytorch/milestones{/number}","notifications_url":"https://api.github.com/repos/Erotemic/pytorch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Erotemic/pytorch/labels{/name}","releases_url":"https://api.github.com/repos/Erotemic/pytorch/releases{/id}","deployments_url":"https://api.github.com/repos/Erotemic/pytorch/deployments","created_at":"2017-10-27T01:44:21Z","updated_at":"2017-10-27T01:44:27Z","pushed_at":"2018-02-21T02:40:20Z","git_url":"git://github.com/Erotemic/pytorch.git","ssh_url":"git@github.com:Erotemic/pytorch.git","clone_url":"https://github.com/Erotemic/pytorch.git","svn_url":"https://github.com/Erotemic/pytorch","homepage":"http://pytorch.org","size":21884,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pytorch:master","ref":"master","sha":"56112cbafd6286fc85c0540d57eac2b6d225ed7b","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":"2018-05-18T13:10:27Z","pushed_at":"2018-05-18T13:09:58Z","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":55264,"stargazers_count":15595,"watchers_count":15595,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3505,"mirror_url":null,"archived":false,"open_issues_count":1100,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":3505,"open_issues":1100,"watchers":15595,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/5021"},"html":{"href":"https://github.com/pytorch/pytorch/pull/5021"},"issue":{"href":"https://api.github.com/repos/pytorch/pytorch/issues/5021"},"comments":{"href":"https://api.github.com/repos/pytorch/pytorch/issues/5021/comments"},"review_comments":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/5021/comments"},"review_comment":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/5021/commits"},"statuses":{"href":"https://api.github.com/repos/pytorch/pytorch/statuses/3f9c2c1735e8955ecaf8f058b720c436890b0f87"}},"author_association":"CONTRIBUTOR","merged":false,"mergeable":false,"rebaseable":false,"mergeable_state":"dirty","merged_by":null,"comments":8,"review_comments":0,"maintainer_can_modify":false,"commits":3,"additions":507,"deletions":1,"changed_files":2}}
{"actor":{"display_login":"Erotemic"}}