sometimes problem got same known error. But i’ve implemented all right
I was implementing siamese network and here is my model
class Siamese(nn.Module):
    def __init__(self, vocab_size, embed_dim, hidden_dim):
        super().__init__()
        self.vocab_size = vocab_size
        self.embed_dim = embed_dim
        self.hidden_dim = hidden_dim
        
        self.fc = nn.Sequential(
            nn.Linear(self.hidden_dim, self.hidden_dim)
        )
        
    def forward(self, x1, x2):
        #n1
        lstm_out_1, _ = self.build_net(x1)
        lstm_out_1 = lstm_out_1.contiguous().view(-1, self.hidden_dim)
        l1 = self.fc(lstm_out_1)
        #n2
        lstm_out_2, _ = self.build_net(x2)
        lstm_out_2 = lstm_out_2.contiguous().view(-1, self.hidden_dim)
        l2 = self.fc(lstm_out_2)
        
        return f.normalize(l1), f.normalize(l2)
    
    def build_net(self, x):
        net = self.build_model(self.vocab_size,self.embed_dim, self.hidden_dim)(x)
        return net
        
    def build_model(self, vocab_size, embed_dim, hidden_dim):
        layers = []
        layers.append(nn.Embedding(vocab_size, embed_dim))
        layers.append(nn.LSTM(embed_dim, hidden_dim))
        return  nn.Sequential(*layers)

and i was experimenting if it will work for random values and did like this
after taking all to cuda device = torch.device('cuda')
build a random tensor asinput = torch.LongTensor([[2,4,12,13]]).to(device) and passed to model as
Siamese(200,128, 32).to(device).forward(input,input)
got same
RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 'self' in call to _th_index_select
but when removing all cuda things it works like perfectly
input = torch.LongTensor([[2,4,12,13]])
Siamese(200,128, 128).forward(input,input)


also please dont mine but my yesterday normalize function, couldnt be passed giving error LongTensor not supported for torch.div  so i sticked  to standard f.normalize to do operations.  that Embedding dim not support for FloatTensor if passed.