RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.cuda.IntTensor instead (while checking arguments for embedding)
See original GitHub issue🐛 Bug
File "C:\Users\temp\Aida\aida\agents\bertbot\Bert\bert_intent_classifier_pytorch.py", line 298, in process
logits = self.model(prediction_inputs, token_type_ids=None, attention_mask=prediction_masks)
File "C:\Users\temp\Anaconda3\envs\fresh\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\temp\Anaconda3\envs\fresh\lib\site-packages\transformers\modeling_bert.py", line 897, in forward
head_mask=head_mask)
File "C:\Users\temp\Anaconda3\envs\fresh\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\temp\Anaconda3\envs\fresh\lib\site-packages\transformers\modeling_bert.py", line 624, in forward
embedding_output = self.embeddings(input_ids, position_ids=position_ids, token_type_ids=token_type_ids)
File "C:\Users\temp\Anaconda3\envs\fresh\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\temp\Anaconda3\envs\fresh\lib\site-packages\transformers\modeling_bert.py", line 167, in forward
words_embeddings = self.word_embeddings(input_ids)
File "C:\Users\temp\Anaconda3\envs\fresh\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\temp\Anaconda3\envs\fresh\lib\site-packages\torch\nn\modules\sparse.py", line 114, in forward
self.norm_type, self.scale_grad_by_freq, self.sparse)
File "C:\Users\temp\Anaconda3\envs\fresh\lib\site-packages\torch\nn\functional.py", line 1484, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.cuda.IntTensor instead (while checking arguments for embedding)
Issue
Hi everyone when I run the line:
outputs = model(input_ids = b_input_ids, attention_mask=b_input_mask, labels=b_labels)
with model defined as,
model = BertForSequenceClassification.from_pretrained("bert-base-uncased", num_labels=numlabels)
It returns the stated error. However this only happens when I am on my windows computer. When I run the exact same code with the same python version and libraries it works perfectly fine. I have the most up to date version of pytorch (1.4) and transformers installed.
Any help would be greatly appreciated
Information
Using the latest version of pytorch and transformers Model I am using (Bert, XLNet …): BertForSequenceClassification Language I am using the model on (English, Chinese …): English
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Expected tensor for argument #1 'indices' to have scalar type ...
Runtime Error : Expected tensor for argument #1 'indices' to have scalar type Long; but got CUDAType instead (while checking arguments for ...
Read more >Expected tensor for argument #1 'indices' to ... - PyTorch Forums
Expected tensor for argument #1 'indices' to have scalar type Long; but got CPUFloatTensor instead (while checking arguments for embedding).
Read more >Expected tensor for argument #1 'indices' to have scalar type ...
I am trying to re-execute a GitHub project on my computer for recommendation using embedding, the goal is to first embed the user...
Read more >"Expected tensor for argument #1 'indices' to have scalar type ...
Error message: RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.FloatTensor instead (while ...
Read more >runtimeerror: expected scalar type long but found float - You.com
PyTorch essentially defines nine CPU tensor types and nine GPU tensor types: ... IntTensor ║ ║ 64-bit integer (signed) ║ torch.int64 or torch.long...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Had similar issue: Young Sheldon’s solution on below stackoverflow thread worked well.
https://stackoverflow.com/questions/56360644/pytorch-runtimeerror-expected-tensor-for-argument-1-indices-to-have-scalar-t
Having the same issue, funny thing is the whole model worked for training, but while running inference on test data the error automatically showed up