2

I'm very newbie on pytorch and deep learning, and I got some error while running a sample code from deep learning class.

When I run the code I attached below, There comes an errors like,

text = torch.from_numpy(data['text']).long().cuda(0)

# feature extraction
mel_gt = get_mel(audio)

# shift mel spectrogram -> the input of the network
mel_shift = torch.cat((torch.zeros_like(mel_gt)[:,:,:1], mel_gt[:,:,:-1]) ,axis=-1)

# inference
mel_est, attention = model(mel_shift, text)

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

I can hardly understand because I also check whether the tensors are on cuba with these code, they all return true..

print(mel_shift.is_cuda)    
print(mel_gt.is_cuda)
print(text.is_cuda)

Can you guys figure out what's the problem?? I need big big help,,

3
  • 1
    did you do "model.cuda()"? Commented Jan 17, 2022 at 9:10
  • yes i did , before I start training. Commented Jan 18, 2022 at 1:31
  • show us your model, and the exact line that you wrote that throws the error inside your model class Commented Jan 18, 2022 at 9:13

1 Answer 1

1

Check if your model is loaded on cuda by running next(model.parameters()).is_cuda. If it returns False, load the model on CUDA using

device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model.to(device)
Sign up to request clarification or add additional context in comments.

Comments

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.