Skip to content

Commit 90a2825

Browse files
zeshengzongpytorchmergebot
authored andcommitted
Add inference_mode hint message to use eval with inference. (pytorch#163619)
Fixes pytorch#162923 ## Test Result ### Before <img width="985" height="889" alt="image" src="https://github.com/user-attachments/assets/41de5cfa-7b25-4ba4-ade8-a6df745dcb30" /> ### After <img width="913" height="977" alt="image" src="https://github.com/user-attachments/assets/b6c06860-8db3-4b5d-9d46-31ece01fb04d" /> Pull Request resolved: pytorch#163619 Approved by: https://github.com/jbschlosser
1 parent 0dce2af commit 90a2825

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

torch/autograd/grad_mode.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ class inference_mode(_DecoratorContextManager):
237237
Unlike some other mechanisms that locally enable or disable grad,
238238
entering inference_mode also disables :ref:`forward-mode AD <forward-mode-ad>`.
239239
240+
.. warning::
241+
`inference_mode` does NOT automatically set the model to evaluation mode.
242+
For proper inference behavior (e.g., disabling dropout, using running statistics
243+
in batch normalization), you must explicitly set your model to evaluation mode using
244+
`model.eval()` in addition to using this context manager.
245+
240246
Args:
241247
mode (bool or function): Either a boolean flag to enable or disable
242248
inference mode, or a Python function to decorate with inference

0 commit comments

Comments
 (0)