Skip to content

Commit

Permalink
improve deterministic engine (pytorch#2756)
Browse files Browse the repository at this point in the history
* improve deterministic engine

* warning if non-deterministic method been called in deterministic mode

* remove unused import
  • Loading branch information
louis-she committed Oct 30, 2022
1 parent ed8622c commit 117529e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 4 additions & 1 deletion ignite/engine/deterministic.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ def state_dict(self) -> OrderedDict:
def _init_run(self) -> None:
self.state.seed = int(torch.randint(0, int(1e9), (1,)).item())
if torch.cuda.is_available():
torch.backends.cudnn.deterministic = True
if hasattr(torch, "use_deterministic_algorithms"):
torch.use_deterministic_algorithms(True, warn_only=True)
else:
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

def _setup_engine(self) -> None:
Expand Down
3 changes: 0 additions & 3 deletions ignite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ def manual_seed(seed: int) -> None:
random.seed(seed)
torch.manual_seed(seed)

if torch.cuda.is_available():
torch.cuda.manual_seed_all(seed)

try:
import torch_xla.core.xla_model as xm

Expand Down

0 comments on commit 117529e

Please sign in to comment.