Skip to content

Commit 7f25e16

Browse files
authored
perf: accelerate data loading in training (#5023)
Accelerate data loading in training phase. Up to 40x acceleration for small descriptors with lower CPU usage. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Single-frame loading API and improved mixed-type atomic system support. * Platform-aware cache size exposed for tuning. * **Performance Improvements** * Memory-mapped data access with cached file handles. * Concurrent loading of frame data for better multi-core utilization. * **Bug Fixes** * Standardized frame keys and reshaping for consistent downstream behavior. * **Tests** * Updated tests to include polarizability in batch key handling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 25fa707 commit 7f25e16

File tree

3 files changed

+320
-32
lines changed

3 files changed

+320
-32
lines changed

deepmd/env.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import logging
33
import os
4+
import platform
45
from configparser import (
56
ConfigParser,
67
)
@@ -16,6 +17,7 @@
1617
"GLOBAL_CONFIG",
1718
"GLOBAL_ENER_FLOAT_PRECISION",
1819
"GLOBAL_NP_FLOAT_PRECISION",
20+
"LRU_CACHE_SIZE",
1921
"SHARED_LIB_DIR",
2022
"SHARED_LIB_MODULE",
2123
"global_float_prec",
@@ -47,6 +49,20 @@
4749
"DP_INTERFACE_PREC."
4850
)
4951

52+
# Dynamic calculation of cache size
53+
_default_lru_cache_size = 512
54+
LRU_CACHE_SIZE = _default_lru_cache_size
55+
56+
if platform.system() != "Windows":
57+
import resource
58+
59+
soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
60+
safe_buffer = 128
61+
if soft_limit > safe_buffer + _default_lru_cache_size:
62+
LRU_CACHE_SIZE = soft_limit - safe_buffer
63+
else:
64+
LRU_CACHE_SIZE = soft_limit // 2
65+
5066

5167
def set_env_if_empty(key: str, value: str, verbose: bool = True) -> None:
5268
"""Set environment variable only if it is empty.

0 commit comments

Comments
 (0)