---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[270], line 3
1 x, y = next(iter(train_loader))
----> 3 o, h = encoder(x)
5 print(o.shape, h.shape)
6 # output : (batch_size, sequence_length, hidden_size(32) x bidirectional(1))
7 # hidden_state: (Bidirectional(1) x number of layers(1), batch_size, hidden_size(32))
File /opt/conda/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py:1102, in Module._call_impl(self, *input, **kwargs)
1098 # If we don't have any hooks, we want to skip the rest of the logic in
1099 # this function, and just call forward.
1100 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1101 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1102 return forward_call(*input, **kwargs)
1103 # Do not call functions when jit is used
1104 full_backward_hooks, non_full_backward_hooks = [], []
Cell In[236], line 16, in Encoder.forward(self, x)
15 def forward(self, x):
---> 16 x = self.embedding(x).permute(1, 0, 2)
17 output, hidden = self.gru(x)
18 return output, hidden
File /opt/conda/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py:1102, in Module._call_impl(self, *input, **kwargs)
1098 # If we don't have any hooks, we want to skip the rest of the logic in
1099 # this function, and just call forward.
1100 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1101 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1102 return forward_call(*input, **kwargs)
1103 # Do not call functions when jit is used
1104 full_backward_hooks, non_full_backward_hooks = [], []
File /opt/conda/envs/py38/lib/python3.8/site-packages/torch/nn/modules/sparse.py:158, in Embedding.forward(self, input)
157 def forward(self, input: Tensor) -> Tensor:
--> 158 return F.embedding(
159 input, self.weight, self.padding_idx, self.max_norm,
160 self.norm_type, self.scale_grad_by_freq, self.sparse)
File /opt/conda/envs/py38/lib/python3.8/site-packages/torch/nn/functional.py:2044, in embedding(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq, sparse)
2038 # Note [embedding_renorm set_grad_enabled]
2039 # XXX: equivalent to
2040 # with torch.no_grad():
2041 # torch.embedding_renorm_
2042 # remove once script supports set_grad_enabled
2043 _no_grad_embedding_renorm_(weight, input, max_norm, norm_type)
-> 2044 return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument index in method wrapper__index_select)