Skip to content

Commit ab5db83

Browse files
authored
Merge pull request #415 from jonasrauber/pytorch_warn_always
always warn if pytorch model is in train mode, not just once
2 parents 9b055ad + 97af490 commit ab5db83

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

foolbox/models/pytorch.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ def __init__(
6565
self._model = model.to(self.device)
6666

6767
if model.training:
68-
warnings.warn(
69-
"The PyTorch model is in training mode and therefore might"
70-
" not be deterministic. Call the eval() method to set it in"
71-
" evaluation mode if this is not intended."
72-
)
68+
with warnings.catch_warnings():
69+
warnings.simplefilter("always")
70+
warnings.warn(
71+
"The PyTorch model is in training mode and therefore might"
72+
" not be deterministic. Call the eval() method to set it in"
73+
" evaluation mode if this is not intended."
74+
)
7375

7476
def forward(self, inputs):
7577
# lazy import

0 commit comments

Comments
 (0)