mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-09 11:32:07 +08:00
Enable non-blocking for gpu device transfer (#1843)
* Update distrib_parts.py * Update CHANGELOG.md
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user