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

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

Open
amir-tagh opened this issue Jun 22, 2022 · 2 comments

Comments

@amir-tagh
Copy link

Hello,

I am using the finetune_generator.py and I am getting the following error. does anybody know how to solve this.

Thanks,

Loading from checkpoint ckpt/inforna-pretrained/model.ckpt.5000
After pruning 257 -> 257
Epoch 0 training...
0%| | 0/13 [00:25<?, ?it/s]
Traceback (most recent call last):
File "/apps/hgraph2graph/20210428/hgraph2graph/finetune_generator.py", line 152, in
meters = meters + np.array([kl_div, loss.item(), wacc * 100, iacc * 100, tacc * 100, sacc * 100])
File "/apps/hgraph2graph/20210428/lib/python3.7/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.

@dbhaskar92
Copy link

In train_generator.py, change line 96 to:

meters = meters + np.array([kl_div, loss.item(), wacc.cpu() * 100, iacc.cpu() * 100, tacc.cpu() * 100, sacc.cpu() * 100])

@amir-tagh
Copy link
Author

Thanks.

bsaldivaremc2 added a commit to bsaldivaremc2/hgraph2graph that referenced this issue Jul 13, 2023
…e tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first
Updated with the solution:
wengong-jin#40
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

2 participants