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

Expected object of device type cuda but got device type cpu for argument #3 'index' in call to _th_index_selec #15

Closed
keherri opened this issue Jan 28, 2020 · 1 comment

Comments

@keherri
Copy link

keherri commented Jan 28, 2020

Running into this error when trying to use a ml.p2.xlarge ec2 instance on aws for the Finetuning tutorial. It seems the tensors aren't automatically moved to the GPU.

RuntimeError                              Traceback (most recent call last)
<ipython-input-32-0bf1915c8e43> in <module>
----> 1 prediction = finder.get_answers(question=question, top_k_retriever=2, top_k_reader=5)

~/SageMaker/haystack/haystack/__init__.py in get_answers(self, question, top_k_reader, top_k_retriever, filters)
     49                                       paragrahps=paragraphs,
     50                                       meta_data_paragraphs=meta_data,
---> 51                                       top_k=top_k_reader)
     52 
     53         return results

~/SageMaker/haystack/haystack/reader/farm.py in predict(self, question, paragrahps, meta_data_paragraphs, top_k, max_processes)
    186         # get answers from QA model (Top 5 per input paragraph)
    187         predictions = self.inferencer.inference_from_dicts(
--> 188             dicts=input_dicts, rest_api_schema=True, max_processes=max_processes
    189         )
    190 

~/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/farm/infer.py in inference_from_dicts(self, dicts, rest_api_schema, max_processes)

~/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/farm/infer.py in _get_predictions(self, dataset, tensor_names, baskets, rest_api_schema)

~/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/farm/modeling/adaptive_model.py in forward(self, **kwargs)

~/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    530             result = self._slow_forward(*input, **kwargs)
    531         else:
--> 532             result = self.forward(*input, **kwargs)
    533         for hook in self._forward_hooks.values():
    534             hook_result = hook(self, input, result)

~/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/farm/modeling/language_model.py in forward(self, input_ids, padding_mask, **kwargs)

~/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    530             result = self._slow_forward(*input, **kwargs)
    531         else:
--> 532             result = self.forward(*input, **kwargs)
    533         for hook in self._forward_hooks.values():
    534             hook_result = hook(self, input, result)

~/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/transformers/modeling_distilbert.py in forward(self, input_ids, attention_mask, head_mask, inputs_embeds)
    481 
    482         if inputs_embeds is None:
--> 483             inputs_embeds = self.embeddings(input_ids)  # (bs, seq_length, dim)
    484         tfmr_output = self.transformer(x=inputs_embeds, attn_mask=attention_mask, head_mask=head_mask)
    485         hidden_state = tfmr_output[0]

~/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    530             result = self._slow_forward(*input, **kwargs)
    531         else:
--> 532             result = self.forward(*input, **kwargs)
    533         for hook in self._forward_hooks.values():
    534             hook_result = hook(self, input, result)

~/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/transformers/modeling_distilbert.py in forward(self, input_ids)
     87         position_ids = position_ids.unsqueeze(0).expand_as(input_ids)  # (bs, max_seq_length)
     88 
---> 89         word_embeddings = self.word_embeddings(input_ids)  # (bs, max_seq_length, dim)
     90         position_embeddings = self.position_embeddings(position_ids)  # (bs, max_seq_length, dim)
     91 

~/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    530             result = self._slow_forward(*input, **kwargs)
    531         else:
--> 532             result = self.forward(*input, **kwargs)
    533         for hook in self._forward_hooks.values():
    534             hook_result = hook(self, input, result)

~/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/torch/nn/modules/sparse.py in forward(self, input)
    112         return F.embedding(
    113             input, self.weight, self.padding_idx, self.max_norm,
--> 114             self.norm_type, self.scale_grad_by_freq, self.sparse)
    115 
    116     def extra_repr(self):

~/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/torch/nn/functional.py in embedding(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq, sparse)
   1482         # remove once script supports set_grad_enabled
   1483         _no_grad_embedding_renorm_(weight, input, max_norm, norm_type)
-> 1484     return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
   1485 
   1486 

RuntimeError: Expected object of device type cuda but got device type cpu for argument #3 'index' in call to _th_index_select
@keherri
Copy link
Author

keherri commented Jan 28, 2020

Retrained the model and now I can call finder.get_answers()

@keherri keherri closed this as completed Jan 28, 2020
masci pushed a commit that referenced this issue Nov 27, 2023
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

1 participant