Skip to content

Commit 3be0755

Browse files
fix: no pinning memory on CPU (#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 bcc267e commit 3be0755

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

deepmd/pt/train/training.py

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

0 commit comments

Comments
 (0)