code: def test_summary_restores_module_mode():
      """Test that the model summary puts the model in `eval()` mode, but restores the original mode once finished."""
  
      class Model(LightningModule):
          def __init__(self):
              super().__init__()
              self.layer1 = torch.nn.Linear(2, 2)
              self.layer2 = torch.nn.Linear(2, 2)
              self.example_input_array = torch.rand(2, 2)
  
          def forward(self, x):
              assert not self.training
              assert not self.layer1.training
              assert not self.layer2.training
              return self.layer2(self.layer1(x))
  
      model = Model()
      model.layer1.train()
      model.layer2.eval()
      summarize(model)
      assert model.training
      assert model.layer1.training
      assert not model.layer2.training
  
imports: from collections import OrderedDict
  from typing import Any
  import pytest
  import torch
  import torch.nn
  from lightning.fabric.utilities.imports import _TORCH_GREATER_EQUAL_2_0
  from lightning.pytorch import LightningModule, Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.utilities.model_summary.model_summary import LEFTOVER_PARAMS_NAME, NOT_APPLICABLE, UNKNOWN_SIZE, ModelSummary, summarize
  from tests_pytorch.helpers.advanced_models import ParityModuleRNN
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 20 for calling a global function with example usage: test_summary_restores_module_mode() and returns: self