When running the "# Prediction on test set" cell in HW 8 (before I get to the first exercise), I get the following error:
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.IntTensor instead (while checking arguments for embedding)
A number of people (example) suggest this error has to do with Windows 10 or different versions of huggingface/transformers, and I can successfully run this code on the Google Collab server, just not my local machine.
Any tips?
Full error:
Predicting labels for 516 test sentences...
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-63-6b924c3d5378> in <module>
21 with torch.no_grad():
22 # Forward pass, calculate logit predictions
---> 23 outputs = model(b_input_ids, token_type_ids=None,
24 attention_mask=b_input_mask)
25
C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
C:\ProgramData\Anaconda3\lib\site-packages\transformers\models\bert\modeling_bert.py in forward(self, input_ids, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, labels, output_attentions, output_hidden_states, return_dict)
1494 return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1495
-> 1496 outputs = self.bert(
1497 input_ids,
1498 attention_mask=attention_mask,
C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
C:\ProgramData\Anaconda3\lib\site-packages\transformers\models\bert\modeling_bert.py in forward(self, input_ids, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, encoder_hidden_states, encoder_attention_mask, past_key_values, use_cache, output_attentions, output_hidden_states, return_dict)
957 head_mask = self.get_head_mask(head_mask, self.config.num_hidden_layers)
958
--> 959 embedding_output = self.embeddings(
960 input_ids=input_ids,
961 position_ids=position_ids,
C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
C:\ProgramData\Anaconda3\lib\site-packages\transformers\models\bert\modeling_bert.py in forward(self, input_ids, token_type_ids, position_ids, inputs_embeds, past_key_values_length)
198
199 if inputs_embeds is None:
--> 200 inputs_embeds = self.word_embeddings(input_ids)
201 token_type_embeddings = self.token_type_embeddings(token_type_ids)
202
C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\sparse.py in forward(self, input)
122
123 def forward(self, input: Tensor) -> Tensor:
--> 124 return F.embedding(
125 input, self.weight, self.padding_idx, self.max_norm,
126 self.norm_type, self.scale_grad_by_freq, self.sparse)
C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\functional.py in embedding(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq, sparse)
1850 # remove once script supports set_grad_enabled
1851 _no_grad_embedding_renorm_(weight, input, max_norm, norm_type)
-> 1852 return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
1853
1854
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.IntTensor instead (while checking arguments for embedding)
Hmm, is your data quite different from the sample training data available? Are you using Windows? What happens when you use an older version of Transformers?
When running the "# Prediction on test set" cell in HW 8 (before I get to the first exercise), I get the following error:
A number of people (example) suggest this error has to do with Windows 10 or different versions of
huggingface/transformers
, and I can successfully run this code on the Google Collab server, just not my local machine.Any tips?
Full error: