I am working on a CNN autoencoder for text with an architecture and loss function like this:

def computeCrossEntropy(log_prob, target):
    loss = [F.nll_loss(sentence_emb_matrix, word_ids, size_average=False) for sentence_emb_matrix, word_ids in zip(log_prob, target)]
    average_loss = sum([torch.sum(l) for l in loss]) / log_prob.size()[0]
    return average_loss

I understand the embedding is huge and I can only have a batch size of 8. Otherwise, I would have memory issue (when loss.backward() is called). Apparently, the line below in the loss function occupies 60% of computation time:
[torch.sum(l) for l in loss]

are there any ways I can deal with this memory issue so I can increase my batch size? Like having the embedding layer processed somewhere else, assuming I have multiple GPUs? Sorry for my ignorance as I am pretty new to this. I would like to know the best practice in handling such situation to improve training time. Thanks a lot for the guidance in advance