Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Colab : GPU Error #6

Open
sorghosh opened this issue Dec 2, 2020 · 1 comment
Open

Google Colab : GPU Error #6

sorghosh opened this issue Dec 2, 2020 · 1 comment

Comments

@sorghosh
Copy link

sorghosh commented Dec 2, 2020

Hi Ben..fanstactic repo.. quick one while running the same code - BiLSTM for PoS Tagging , I am getting the error in google colab :

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

Please suggest

@FelixJuch
Copy link

Adding a .cuda() in the return statement in categorical_accuracy fixed it for me:

def categorical_accuracy(preds, y, tag_pad_idx):
"""
Returns accuracy per batch, i.e. if you get 8/10 right, this returns 0.8, NOT 8
"""
max_preds = preds.argmax(dim = 1, keepdim = True) # get the index of the max probability
non_pad_elements = (y != tag_pad_idx).nonzero()
correct = max_preds[non_pad_elements].squeeze(1).eq(y[non_pad_elements])
return correct.sum() / torch.FloatTensor([y[non_pad_elements].shape[0]]).cuda()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants