Expected tensor for argument #1 'input' to have the same device as tensor for argument #2 'weight';

Solved the problem described in the title.
The complete error message is:
RuntimeError: Expected tensor for argument #1'input' to have the same device as tensor for argument #2'weight'; but device 1 does not equal 0 (while checking arguments for cudnn_convolution)

There are not many errors found on the Internet. The basic reason is that the input data and model parameters are not on the same GPU when using pytorch to load the model training. This is also the meaning of the error message. Some big guys analyzed the reason carefully, and I couldn't understand what was broadcast.
Looking at their situation, it seems that when the method is defined, there is an extra layer of nesting, and then an error is reported. Just simplify the extra layer of nested calls.
But my situation is like this:
Error: The
Insert picture description here
Insert picture description here
decoder part uses torch.cat(), and the t64, t128, and t256 are defined in the front. After commenting it out, no error will be reported. You can be sure that the error is in the call of the three variables.

Comment out global and succeed:
Insert picture description here
adding global is because the original program enclosed the self method in the encoder and decoder methods, so that global variables can be used in different methods. For trial and error, I moved them all out and found this problem.

Guess you like

Origin blog.csdn.net/qq_41872271/article/details/105701128