7

All I do is,

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
torch.tensor([123,123]).to(device)

And I get:

RuntimeError: CUDA error: device-side assert triggered

I really cannot see why.

Edit: Weirdly enough, I see that this happens only I after I run some code before hand. Restarting the kernel solves it. But why, some code can cause a problem like this? I cannot share the code because it's not mine but I still welcome any guesses. Thanks!

2

1 Answer 1

-1

device is a string, not a tensor. change your code to

device = "cuda" if torch.cuda.is_available() else "cpu"

now your code will work fine. enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

torch.device doesn't return a tensor so the code in the question is valid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.