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
Segfault upon calling torch.Tensor on a gpu tensor #33899
Comments
Backtrace for: import torch
a = torch.tensor(1, device='cuda')
b = torch.Tensor(a)
print(b)
It seems that the code tries to throw the EDIT: seems to be related to #25518 |
Have you tried the workaround you mentioned here? |
Marking as high priority since it can be reproduced, and leads to segmentation fault. |
…h#34019) Summary: Fixes pytorch#33899 In the issue, we have ``` TypeError("expected %s (got %s)", dispatch_key, toString(other.key_set()).c_str()); ``` which results in `dispatch_key` being interpreted as a c-string by `sprintf`. Adding `__attrbute__((format))` to the `TypeError` constructor allows gcc or clang to detect this at compile time. Then `-Werror=format` makes it a hard error at compile time. Pull Request resolved: pytorch#34019 Differential Revision: D20194842 Pulled By: ezyang fbshipit-source-id: fa4448916c309d91e3d949fa65bb3aa7cca5c6a8
similar issue encounter here |
@ptrblck Could you show how to solve the segmentation fault with your test code? |
@ChuanchuanZheng Which PyTorch version are you using? >>> torch.__version__
'1.7.0'
>>> a = torch.tensor(1, device='cuda')
>>> b = torch.Tensor(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: expected CPU (got CUDA) Trying to work around this error yields: >>> b = torch.Tensor(a, device='cuda')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: legacy constructor for device type: cpu was passed device type: cuda, but device type must be: cpu Using the suggested a = torch.tensor(1, device='cuda')
b = torch.Tensor(a, device='cpu')
print(b)
> tensor([8.9683e-44])
print(a)
> tensor(1, device='cuda:0') While the original error cannot be reproduced, we might face a new one. |
Thanks for digging in @ptrblck! Please open a new issue, this is different from original. |
🐛 Bug
I accidentally called
torch.Tensor
on a Tensor object, thinking it was a numpy array. Instead of doing nothing or throwing a warning, the program segfaulted.To Reproduce
Minimal code example:
Upon running the final line, python prints "Segmentation fault (core dumped)" and dies.
Expected behavior
I would have expected casting a Tensor to a Tensor to have to result
Environment
Collecting environment information...
PyTorch version: 1.3.1
Is debug build: No
CUDA used to build PyTorch: 10.1.243
OS: Ubuntu 18.04.4 LTS
GCC version: (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
CMake version: Could not collect
Python version: 3.7
Is CUDA available: Yes
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: GeForce RTX 2060
Nvidia driver version: 430.50
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
Versions of relevant libraries:
[pip] numpy==1.16.4
[pip] numpydoc==0.9.1
[pip] torch==1.3.1
[pip] torchfile==0.1.0
[pip] torchvision==0.4.2
[conda] blas 1.0 mkl
[conda] mkl 2019.4 243
[conda] mkl-service 2.0.2 py37h7b6447c_0
[conda] mkl_fft 1.0.12 py37ha843d7b_0
[conda] mkl_random 1.0.2 py37hd81dba3_0
[conda] torch 1.3.1 pypi_0 pypi
[conda] torchfile 0.1.0 pypi_0 pypi
[conda] torchvision 0.4.2 pypi_0 pypi
Additional context
I was able to reproduce the issue running on google CoLab, so I don't think the issue is specific to my computer
cc @ezyang @gchanan @zou3519 @bdhirsh @heitorschueroff @ngimel
The text was updated successfully, but these errors were encountered: