Skip to content

Commit 88f1f22

Browse files
author
Liu
committed
add a check to determine if horovod.torch import succeeds
1 parent 6b13f09 commit 88f1f22

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

smdebug/core/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,27 @@ class FRAMEWORK(Enum):
6464
except (ImportError, ModuleNotFoundError):
6565
_torch_dist_imported = None
6666

67-
6867
try:
6968
import horovod.torch as hvd
7069

7170
# This redundant import is necessary because horovod does not raise an ImportError if the library is not present
7271
import torch # noqa
72+
#make sure the library is correctly imported
73+
hvd.init()
7374

7475
_hvd_imported = hvd
76+
except AttributeError:
77+
_hvd_imported = None
78+
print("horovod.torch is not correctly imported.")
79+
raise
7580
except (ModuleNotFoundError, ImportError):
7681
try:
7782
import horovod.tensorflow as hvd
7883

7984
_hvd_imported = hvd
8085
except (ModuleNotFoundError, ImportError):
8186
_hvd_imported = None
82-
87+
raise
8388

8489
logger = get_logger()
8590
error_handling_agent = (

0 commit comments

Comments
 (0)