close

[solved] PyTorch: RuntimeError: Input, output and indices must be on the current device

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error PyTorch: RuntimeError: Input, output and indices must be on the current device in Python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How PyTorch: RuntimeError: Input, output and indices must be on the current device Error Occurs?

Today I get the following error PyTorch: RuntimeError: Input, output and indices must be on the current device in Python.

How To Solve PyTorch: RuntimeError: Input, output and indices must be on the current device Error ?

  1. How To Solve PyTorch: RuntimeError: Input, output and indices must be on the current device Error ?

    To Solve PyTorch: RuntimeError: Input, output and indices must be on the current device Error You should put your model on the device, which is probably cuda: device = “cuda:0”
    model = model.to(device)

Solution 1

You should put your model on the device, which is probably cuda:

device = "cuda:0"
model = model.to(device)
 

Then make sure the inputs of the model(input) are on the same device as well:

input = input.to(device)

It should work!

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment