I am using nn.DataParallel and I have an error inside the embedding layer that said “RuntimeError: arguments are located on different GPUs  at /pytorch/aten/src/THC/generic/THCTensorIndex.cu:403”. My network architecture is the following
class WordEmbeddingNetwork(nn.Module):

    def __init__(self, word_embeddings_path, word2id, pad_token, unk_token, freeze=False):

        super(WordEmbeddingNetwork, self).__init__()
        self.pad_token = pad_token
        self.unk_token = unk_token
        self.word2id = word2id
        self.embedding_file = word_embeddings_path.split('/')[-1]
        self.load_embeddings_from_file(word_embeddings_path)

        embedding_weights = self.get_embeddings_weights(OOV_corrections)

        num_embeddings, self.embedding_dim = embedding_weights.shape
        self.embedding_layer = nn.Embedding(num_embeddings, self.embedding_dim)
        self.embedding_layer.load_state_dict({'weight': embedding_weights})
        if freeze:
            for p in self.embedding_layer.parameters():
                p.requires_grad = False


    def forward(self, batch):
        print(batch.device)
        print(self.embedding_layer.weight.device)
        emb = self.embedding_layer(batch)
        return emb


class MyNet(nn.Module):

    _HIDDEN_SIZE = 300

    def __init__(self, word_embeddings_path, word2id, pad_token, unk_token, seed, device='cpu'):
        torch.manual_seed(seed)
        super(MyNet, self).__init__()

        self.device = device
        self.word_embeddings_layer = WordEmbeddingNetwork(word_embeddings_path=word_embeddings_path, 
                                                        word2id=word2id, 
                                                        pad_token=pad_token, 
                                                        unk_token=unk_token)

    def __init__(self, utterances, ...):
        self.word_embedding_layer(utterances)
        ....

I don’t understand why embedding layer and the given input are on different gpus. Can you help me?