Skip to content

remove implicit conversion to cpu#10416

Closed
ailzhang wants to merge 3 commits intopytorch:masterfrom
ailzhang:fix_array
Closed

remove implicit conversion to cpu#10416
ailzhang wants to merge 3 commits intopytorch:masterfrom
ailzhang:fix_array

Conversation

@ailzhang
Copy link
Contributor

Fixes #9934

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ailzhang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ailzhang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@ssnl
Copy link
Collaborator

ssnl commented Aug 14, 2018

test seems broken

16:01:04 ======================================================================
16:01:04 ERROR: test_gamma_gpu_shape (__main__.TestDistributions)
16:01:04 ----------------------------------------------------------------------
16:01:04 Traceback (most recent call last):
16:01:04   File "/var/lib/jenkins/workspace/test/common.py", line 251, in wrapper
16:01:04     method(*args, **kwargs)
16:01:04   File "test_distributions.py", line 1897, in test_gamma_gpu_shape
16:01:04     self._check_log_prob(Gamma(alpha, beta), ref_log_prob)
16:01:04   File "test_distributions.py", line 664, in _check_log_prob
16:01:04     asset_fn(i, val.squeeze(), log_prob)
16:01:04   File "test_distributions.py", line 1894, in ref_log_prob
16:01:04     expected = scipy.stats.gamma.logpdf(x.cpu(), a, scale=1 / b)
16:01:04   File "/opt/conda/lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.py", line 1691, in logpdf
16:01:04     x, loc, scale = map(asarray, (x, loc, scale))
16:01:04   File "/opt/conda/lib/python2.7/site-packages/numpy/core/numeric.py", line 492, in asarray
16:01:04     return array(a, dtype, copy=False, order=order)
16:01:04   File "/opt/conda/lib/python2.7/site-packages/torch/tensor.py", line 398, in __array__
16:01:04     return self.numpy()
16:01:04 TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
16:01:04 

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ailzhang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ailzhang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@yf225
Copy link
Contributor

yf225 commented Aug 15, 2018

@pytorchbot retest this please

facebook-github-bot pushed a commit that referenced this pull request Aug 16, 2018
Summary:
Resubmit #10416 with fixed tests . This is to remove implicit conversion from gpu to cpu in when calling numpy to keep behavior match others.

It requires users to move the tensor back to cpu() before call numpy functions on it.
Pull Request resolved: #10553

Differential Revision: D9350212

Pulled By: ailzhang

fbshipit-source-id: 9317d8fea925d4b20ae3150e2c1b39ba5c9c9d0a
@ezyang ezyang added the merged label Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pytorch] Inconsistent automatic conversion of GPU tensors to NumPy arrays on CPU

7 participants