Skip to content

Commit d691bac

Browse files
caic99pre-commit-ci[bot]
authored andcommitted
fix: no pinning memory on CPU (deepmodeling#4874)
This PR fixes the warning message when running on CPU: ``` torch/utils/data/dataloader.py:665: UserWarning: 'pin_memory' argument is set as true but no accelerator is found, then device pinned memory won't be used. warnings.warn(warn_msg) ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved memory handling by enabling memory pinning only when using non-CPU devices, which may enhance performance and stability when training on GPUs. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 780fba2 commit d691bac

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

deepmd/pt/train/training.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def get_dataloader_and_iter(_data, _params):
208208
else 0, # setting to 0 diverges the behavior of its iterator; should be >=1
209209
drop_last=False,
210210
collate_fn=lambda batch: batch, # prevent extra conversion
211-
pin_memory=True,
211+
pin_memory=(DEVICE != "cpu"), # pin memory only if not on CPU
212212
)
213213
_data_iter = cycle_iterator(_dataloader)
214214
return _dataloader, _data_iter

0 commit comments

Comments
 (0)