Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first. #21

Closed
BasinChen opened this issue Sep 11, 2022 · 8 comments

Comments

@BasinChen
Copy link

PS C:\Users\Lyc\Downloads\PyPOTS-main\PyPOTS-main> & C:/Users/Lyc/AppData/Local/Programs/Python/Python39/python.exe c:/Users/Lyc/Downloads/PyPOTS-main/PyPOTS-main/pypots/tests/test_imputation.py
Running test cases for BRITS...
Model initialized successfully. Number of the trainable parameters: 580976
epoch 0: training loss 1.2366, validating loss 0.4201
epoch 1: training loss 0.8974, validating loss 0.3540
epoch 2: training loss 0.7426, validating loss 0.2919
epoch 3: training loss 0.6147, validating loss 0.2414
epoch 4: training loss 0.5411, validating loss 0.2157
ERunning test cases for BRITS...
Model initialized successfully. Number of the trainable parameters: 580976
epoch 0: training loss 1.2054, validating loss 0.4022
epoch 1: training loss 0.8631, validating loss 0.3399
epoch 2: training loss 0.7204, validating loss 0.2863
epoch 3: training loss 0.5995, validating loss 0.2399
epoch 4: training loss 0.5325, validating loss 0.2123
ERunning test cases for LOCF...
LOCF test_MAE: 0.17510570872656786
.Running test cases for LOCF...
.Running test cases for SAITS...
Model initialized successfully. Number of the trainable parameters: 1332704
epoch 0: training loss 0.9181, validating loss 0.2936
epoch 1: training loss 0.6287, validating loss 0.2303
epoch 2: training loss 0.5345, validating loss 0.2086
epoch 3: training loss 0.4735, validating loss 0.1895
epoch 4: training loss 0.4224, validating loss 0.1744
ERunning test cases for SAITS...
Model initialized successfully. Number of the trainable parameters: 1332704
epoch 0: training loss 0.7823, validating loss 0.2779
epoch 1: training loss 0.5015, validating loss 0.2250
epoch 2: training loss 0.4418, validating loss 0.2097
epoch 3: training loss 0.4119, validating loss 0.1994
epoch 4: training loss 0.3866, validating loss 0.1815
ERunning test cases for Transformer...
Model initialized successfully. Number of the trainable parameters: 666122
epoch 0: training loss 0.7715, validating loss 0.2843
epoch 1: training loss 0.4861, validating loss 0.2271
epoch 2: training loss 0.4176, validating loss 0.2077
epoch 3: training loss 0.3822, validating loss 0.2005
epoch 4: training loss 0.3592, validating loss 0.1961
ERunning test cases for Transformer...
Model initialized successfully. Number of the trainable parameters: 666122
epoch 0: training loss 0.8033, validating loss 0.2910
epoch 1: training loss 0.4856, validating loss 0.2345
epoch 2: training loss 0.4282, validating loss 0.2157
epoch 3: training loss 0.3882, validating loss 0.2051
epoch 4: training loss 0.3599, validating loss 0.1942
E

ERROR: test_impute (main.TestBRITS)

Traceback (most recent call last):
File "c:\Users\Lyc\Downloads\PyPOTS-main\PyPOTS-main\pypots\tests\test_imputation.py", line 125, in setUp
self.brits.fit(self.train_X, self.val_X)
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\pypots\imputation\brits.py", line 504, in fit
self._train_model(training_loader, val_loader, val_X_intact, val_X_indicating_mask)
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\pypots\imputation\base.py", line 142, in _train_model
if np.equal(self.best_loss, float('inf')):
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\torch_tensor.py", line 732, in array
return self.numpy()
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

======================================================================
ERROR: test_parameters (main.TestBRITS)

Traceback (most recent call last):
File "c:\Users\Lyc\Downloads\PyPOTS-main\PyPOTS-main\pypots\tests\test_imputation.py", line 125, in setUp
self.brits.fit(self.train_X, self.val_X)
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\pypots\imputation\brits.py", line 504, in fit
self._train_model(training_loader, val_loader, val_X_intact, val_X_indicating_mask)
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\pypots\imputation\base.py", line 142, in _train_model
if np.equal(self.best_loss, float('inf')):
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\torch_tensor.py", line 732, in array
return self.numpy()
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

======================================================================
ERROR: test_impute (main.TestSAITS)

Traceback (most recent call last):
File "c:\Users\Lyc\Downloads\PyPOTS-main\PyPOTS-main\pypots\tests\test_imputation.py", line 45, in setUp
self.saits.fit(self.train_X, self.val_X)
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\pypots\imputation\saits.py", line 170, in fit
self._train_model(training_loader, val_loader, val_X_intact, val_X_indicating_mask)
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\pypots\imputation\base.py", line 142, in _train_model
if np.equal(self.best_loss, float('inf')):
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\torch_tensor.py", line 732, in array
return self.numpy()
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

======================================================================
ERROR: test_parameters (main.TestSAITS)

Traceback (most recent call last):
File "c:\Users\Lyc\Downloads\PyPOTS-main\PyPOTS-main\pypots\tests\test_imputation.py", line 45, in setUp
self.saits.fit(self.train_X, self.val_X)
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\pypots\imputation\saits.py", line 170, in fit
self._train_model(training_loader, val_loader, val_X_intact, val_X_indicating_mask)
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\pypots\imputation\base.py", line 142, in _train_model
if np.equal(self.best_loss, float('inf')):
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\torch_tensor.py", line 732, in array
return self.numpy()
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

======================================================================
ERROR: test_impute (main.TestTransformer)

Traceback (most recent call last):
File "c:\Users\Lyc\Downloads\PyPOTS-main\PyPOTS-main\pypots\tests\test_imputation.py", line 89, in setUp
self.transformer.fit(self.train_X, self.val_X)
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\pypots\imputation\transformer.py", line 256, in fit
self._train_model(training_loader, val_loader, val_X_intact, val_X_indicating_mask)
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\pypots\imputation\base.py", line 142, in _train_model
if np.equal(self.best_loss, float('inf')):
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\torch_tensor.py", line 732, in array
return self.numpy()
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

======================================================================
ERROR: test_parameters (main.TestTransformer)

Traceback (most recent call last):
File "c:\Users\Lyc\Downloads\PyPOTS-main\PyPOTS-main\pypots\tests\test_imputation.py", line 89, in setUp
self.transformer.fit(self.train_X, self.val_X)
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\pypots\imputation\transformer.py", line 256, in fit
self._train_model(training_loader, val_loader, val_X_intact, val_X_indicating_mask)
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\pypots\imputation\base.py", line 142, in _train_model
if np.equal(self.best_loss, float('inf')):
File "C:\Users\Lyc\AppData\Local\Programs\Python\Python39\lib\site-packages\torch_tensor.py", line 732, in array
return self.numpy()
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.


Ran 8 tests in 176.311s

FAILED (errors=6)

@WenjieDu
Copy link
Owner

Hi there,

Thank you so much for your attention to PyPOTS! If you find PyPOTS helpful to your work, please star⭐️ this repository. Your star is your recognition, which can help more people notice PyPOTS and grow PyPOTS community. It matters and is definitely a kind of contribution.

I have received your message and will respond ASAP. Thank you for your patience! 😃

Best,
Wenjie

@MaciejSkrabski
Copy link
Contributor

It seems you are using an old version of pypots. Exactly this bug has been handled here #11

Please upgrade to the newest version.

@BasinChen
Copy link
Author

I'm sorry to disturb you, I upgrade my pypots, it is the latest version 0.0.7
What should I do?
C:\Users\Lyc>pip install --upgrade pypots Requirement already satisfied: pypots in c:\users\lyc\appdata\local\programs\python\python39\lib\site-packages (0.0.7)

@MaciejSkrabski
Copy link
Contributor

No disturbance at all, I am not even the author, just a user 😄 You have a valid issue that needs a valid solution.
Well, it seems you do have the newest version. Perhaps the packaged version hasn't incorporated the changes yet. Please let me do some reading, i will come back to you as soon as i find something.

@MaciejSkrabski
Copy link
Contributor

MaciejSkrabski commented Sep 11, 2022

Sorry, I am unable to help you today (I don't have a cuda capable machine on me right now).
However, upon examining main branch, the code that is at fault here is no longer a part of the current codebase. I suspect the package not being updated yet.

Until the package is updated by Wenjie Du himself, I am afraid there isn't much we can do with this cuda-tensor-to-numpy problem using pip-install.

As a workaround I suggest building the package from the most recent source and installing it afterwards.

Please take my advice with a grain of salt as today I am unable to verify it myself.

@WenjieDu
Copy link
Owner

WenjieDu commented Sep 11, 2022

Thank you for your patience @BasinChen, and many thanks for your help and assistance @MaciejSkrabski.

I'm sorry for my delayed response. The fixed code in #11 has not been released yet with the upcoming version 0.0.8 (I'll release it in the following days together with some other bugs solved). So far, you can install from github with command pip install https://github.com/WenjieDu/PyPOTS/archive/main.zip to have your mentioned issues fixed.

Thank you again @BasinChen for your important feedback. I'll run tests with machines having CUDA devices before releasing code or merging into the main branch in the future. I'm sorry for your inconvenience. If you have further questions, please let me know.

@BasinChen
Copy link
Author

Thank you for your reply, after run your command, the code run successfully, and I hope that the code can plot the result in the next version.
Thank you very much again, I'll close this issue.

@WenjieDu
Copy link
Owner

My pleasure, @BasinChen. I'll add plotting functions in the future. You can watch this repository so that you'll receive notifications once PyPOTS has any progress.

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

No branches or pull requests

3 participants