a-PyTorch-Tutorial-to-Image-Captioning
a-PyTorch-Tutorial-to-Image-Captioning copied to clipboard
GPU issues
When I use muti-gpu in training, there is an issue:
Some of weight/gradient/input tensors are located on different GPUs
When I revise the following code, the question is resolved! I add '.to(device)'.
# Remove timesteps that we didn't decode at, or are pads
# pack_padded_sequence is an easy trick to do this
scores, _ = pack_padded_sequence(scores, decode_lengths, batch_first=True)**.to(device)**
targets, _ = pack_padded_sequence(targets, decode_lengths, batch_first=True)**.to(device)**
# Calculate loss
loss = criterion(scores, targets)
# Add doubly stochastic attention regularization
loss += alpha_c * ((1. - alphas.sum(dim=1)) ** 2).mean()**.to(device)**
Does anyone know what happened? Is this a bug?