Skip to content

Commit 633f536

Browse files
committed
warn if current device doesn't support
1 parent d407728 commit 633f536

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

paddlenlp/utils/memory_utils.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,25 @@
1515

1616
import paddle
1717

18+
from .log import logger
19+
from .tools import get_env_device
20+
1821
__all__ = [
1922
"empty_device_cache",
2023
]
2124

2225

2326
def empty_device_cache():
24-
if paddle.device.is_compiled_with_cuda():
27+
device = get_env_device()
28+
if device == "gpu":
2529
paddle.device.cuda.empty_cache()
26-
elif paddle.device.is_compiled_with_xpu():
30+
elif device == "xpu":
2731
paddle.device.xpu.empty_cache()
2832
else:
29-
pass
33+
if not getattr(empty_device_cache, "has_warned", False):
34+
logger.warning(
35+
"The current device ({}) does not support empty cache, calling empty_device_cache() will have no effect.".format(
36+
device
37+
)
38+
)
39+
setattr(empty_device_cache, "has_warned", True)

0 commit comments

Comments
 (0)