Implement correct transfer to GPU for batches (#200)

This commit is contained in:
Anton Konstantinov
2019-09-05 07:13:06 -04:00
committed by William Falcon
parent 62252cee58
commit 34b824a9d3
+5 -2
View File
@@ -995,10 +995,13 @@ class Trainer(TrainerIO):
return blacklist
def transfer_batch_to_gpu(self, batch, gpu_id):
# base case
if isinstance(batch, torch.Tensor):
# base case: object can be directly moved using `cuda` or `to`
if callable(getattr(batch, 'cuda', None)):
return batch.cuda(gpu_id)
elif callable(getattr(batch, 'to', None)):
return batch.to(torch.device('cuda', gpu_id))
# when list
elif isinstance(batch, list):
for i, x in enumerate(batch):