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

Fix Runtime Error: Expected tensor for argument #1 'indices' to have scalar type Long. #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cuicaihao
Copy link

@cuicaihao cuicaihao commented Jun 13, 2020

The following cells will cause runtime issues:

input_ids = torch.tensor(padded)
attention_mask = torch.tensor(attention_mask)
with torch.no_grad():
    last_hidden_states = model(input_ids, attention_mask=attention_mask)` 
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-24-17a214174eeb> in <module>
      4 attention_mask = torch.tensor(attention_mask)
      5 with torch.no_grad():
----> 6     last_hidden_states = model(input_ids, attention_mask=attention_mask)
.... ... 
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.IntTensor instead (while checking arguments for embedding)

It can be solved by changing the input_ids and attention_mask type to torch.int64

input_ids = torch.tensor(padded).to(torch.int64)
attention_mask = torch.tensor(attention_mask).to(torch.int64)

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

Successfully merging this pull request may close these issues.

1 participant