mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-09 11:32:07 +08:00
Implement correct transfer to GPU for batches (#200)
This commit is contained in:
committed by
William Falcon
parent
62252cee58
commit
34b824a9d3
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user