Enable non-blocking for gpu device transfer (#1843)

* Update distrib_parts.py

* Update CHANGELOG.md
This commit is contained in:
Justus Schock
2020-05-14 17:56:40 -04:00
committed by GitHub
parent bee0392c37
commit c05077fae3
2 changed files with 8 additions and 2 deletions
+2
View File
@@ -28,6 +28,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
### Changed
- Enable `non-blocking` for device transfers to GPU ([#1843](https://github.com/PyTorchLightning/pytorch-lightning/pull/1843))
- Replace mata_tags.csv with hparams.yaml ([#1271](https://github.com/PyTorchLightning/pytorch-lightning/pull/1271))
- Reduction when `batch_size < num_gpus` ([#1609](https://github.com/PyTorchLightning/pytorch-lightning/pull/1609))
+6 -2
View File
@@ -449,10 +449,14 @@ class TrainerDPMixin(ABC):
if device == 'gpu':
# base case: object can be directly moved using `cuda` or `to`
if callable(getattr(batch, 'cuda', None)):
return batch.cuda(gpu_id)
# non_blocking will be ignored if tensor is not pinned.
# so we can always set it to True
return batch.cuda(gpu_id, non_blocking=True)
if callable(getattr(batch, 'to', None)):
return batch.to(torch.device('cuda', gpu_id))
# non_blocking will be ignored if tensor is not pinned.
# so we can always set it to True
return batch.to(torch.device('cuda', gpu_id), non_blocking=True)
# when list
if isinstance(batch, list):