Skip to content

Commit

Permalink
add a check to determine if horovod.torch import succeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Liu committed Jun 28, 2022
1 parent 6b13f09 commit 88f1f22
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions smdebug/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,27 @@ class FRAMEWORK(Enum):
except (ImportError, ModuleNotFoundError):
_torch_dist_imported = None


try:
import horovod.torch as hvd

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

_hvd_imported = hvd
except AttributeError:
_hvd_imported = None
print("horovod.torch is not correctly imported.")
raise
except (ModuleNotFoundError, ImportError):
try:
import horovod.tensorflow as hvd

_hvd_imported = hvd
except (ModuleNotFoundError, ImportError):
_hvd_imported = None

raise

logger = get_logger()
error_handling_agent = (
Expand Down

0 comments on commit 88f1f22

Please sign in to comment.