Skip to content

Commit 9ead94e

Browse files
authored
fix: torch_npu import error (#3764)
1 parent a0bc36e commit 9ead94e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/accelerate/utils/imports.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,12 @@ def is_npu_available(check_device=False):
414414
if importlib.util.find_spec("torch_npu") is None:
415415
return False
416416

417-
import torch_npu # noqa: F401
417+
# NOTE: importing torch_npu may raise error in some envs
418+
# e.g. inside cpu-only container with torch_npu installed
419+
try:
420+
import torch_npu # noqa: F401
421+
except Exception:
422+
return False
418423

419424
if check_device:
420425
try:

0 commit comments

Comments
 (0)