Skip to content

Commit

Permalink
Docs on sanity_checking property (#17579)
Browse files Browse the repository at this point in the history
(cherry picked from commit ba14069)
  • Loading branch information
SkafteNicki authored and Borda committed Jun 1, 2023
1 parent 8bebff9 commit 877769a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/source-pytorch/common/trainer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,18 @@ both conditions are met. If any of these arguments is not set, it won't be consi
model = LitModel()
trainer.fit(model)
sanity_checking
***************

Indicates if the trainer is currently running sanity checking. This property can be useful to disable some hooks,
logging or callbacks during the sanity checking.

.. code-block:: python
def validation_step(self, batch, batch_idx):
...
if not self.trainer.sanity_checking:
self.log("value", value)
num_training_batches
********************
Expand Down
4 changes: 4 additions & 0 deletions src/lightning/pytorch/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,10 @@ def evaluating(self) -> bool:

@property
def sanity_checking(self) -> bool:
"""Whether sanity checking is running.
Useful to disable some hooks, logging or callbacks during the sanity checking.
"""
return self.state.stage == RunningStage.SANITY_CHECKING

@sanity_checking.setter
Expand Down

0 comments on commit 877769a

Please sign in to comment.