22

I am using Pytorch. I got this RuntimeError while evaluating a model. Any idea how to solve this?

1

3 Answers 3

28

SOLUTION: Just replace the view() function with reshape() function as suggested in the error and it works.

I guess this has to do with how the tensor is stored in memory.

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

Comments

19

SOLUTION2: change the .view(...) to .contiguous().view(...).

Actually, 'reshape()' does a similar job as contiguous() under the hood, if it needs.

Comments

0

In my case, I got the error when calling loss.backward() and calling reshape didn't work. Possibly, because I couldn't find the correct tensor.

A temporary workaround was running on CPU instead of MPs. I definitely cannot recommend this as solution, because the code will then run on CPU, but it did remove the error message for now and might be useful for people's debugging:

I used:

device = torch.device("cpu")

The workaround:

device = torch.device("mps")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.