Skip to content

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

Open
cuicaihao wants to merge 1 commit intojalammar:masterfrom
cuicaihao:master
Open

Fix Runtime Error: Expected tensor for argument #1 'indices' to have scalar type Long. #11
cuicaihao wants to merge 1 commit intojalammar:masterfrom
cuicaihao:master

Conversation

@cuicaihao
Copy link
Copy Markdown

@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