code: def test_eval_inference_mode(tmp_path, trainer_fn):
      class BoringModelNoGrad(BoringModel):
          def assert_not_enabled(self):
              assert not torch.is_grad_enabled()
              assert not torch.is_inference_mode_enabled()
  
          on_test_start = assert_not_enabled
          on_validation_start = assert_not_enabled
          on_predict_start = assert_not_enabled
  
      class BoringModelForInferenceMode(BoringModel):
          def assert_enabled(self):
              assert not torch.is_grad_enabled()
              assert torch.is_inference_mode_enabled()
  
          on_test_start = assert_enabled
          on_validation_start = assert_enabled
          on_predict_start = assert_enabled
  
      trainer = Trainer(
          default_root_dir=tmp_path,
          logger=False,
          inference_mode=False,
          fast_dev_run=True,
      )
      getattr(trainer, trainer_fn)(BoringModelNoGrad())
      trainer = Trainer(
          logger=False, inference_mode=True, fast_dev_run=True
      )
      getattr(trainer, trainer_fn)(BoringModelForInferenceMode())
  
file_path: pytorch-lightning/tests/tests_pytorch/trainer/flags/test_inference_mode.py
imports: from unittest import mock
  from unittest.mock import Mock
  import pytest
  import torch
  from lightning.fabric.utilities.imports import _TORCH_EQUAL_2_0
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.loops import _Loop
  from lightning.pytorch.loops.utilities import _no_grad_context
label_desc: Use image node_id 1 for calling a global function with example usage: test_eval_inference_mode(tmp_path, trainer_fn) without return types