Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug when loading horovod #490

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions mala/common/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import pickle
from time import sleep

horovod_available = False
try:
import horovod.torch as hvd
horovod_available = True
except ModuleNotFoundError:
pass
import numpy as np
Expand Down Expand Up @@ -1257,19 +1259,25 @@ def use_horovod(self):

@use_horovod.setter
def use_horovod(self, value):
if value:
hvd.init()
if value is False:
self._use_horovod = False
else:
if horovod_available:
hvd.init()
# Invalidate, will be updated in setter.
set_horovod_status(value)
self.device = None
self._use_horovod = value
self.network._update_horovod(self.use_horovod)
self.descriptors._update_horovod(self.use_horovod)
self.targets._update_horovod(self.use_horovod)
self.data._update_horovod(self.use_horovod)
self.running._update_horovod(self.use_horovod)
self.hyperparameters._update_horovod(self.use_horovod)
else:
parallel_warn("Horovod requested, but not installed found. "
"MALA will operate without horovod only.")

# Invalidate, will be updated in setter.
set_horovod_status(value)
self.device = None
self._use_horovod = value
self.network._update_horovod(self.use_horovod)
self.descriptors._update_horovod(self.use_horovod)
self.targets._update_horovod(self.use_horovod)
self.data._update_horovod(self.use_horovod)
self.running._update_horovod(self.use_horovod)
self.hyperparameters._update_horovod(self.use_horovod)

@property
def device(self):
Expand Down