class_docstr: Captures the ``nn.Module.training`` (bool) mode of every submodule, and allows it to be restored later on.
class_docstr_tok: ["Captures","the","``","nn.Module.training","``","(","bool",")","mode","of","every","submodule",",","and","allows","it","to","be","restored","later","on","."]
code: def restore(self, module: nn.Module) -> None:
      for name, mod in module.named_modules():
          if name not in self.mode:
              _log.debug(
                  f"Restoring training mode on module '{name}' not possible, it was never captured."
                  f" Is your module structure changing?"
              )
              continue
          mod.training = self.mode[name]
  
file_path: pytorch-lightning/src/lightning/pytorch/utilities/model_helpers.py
imports: import inspect
  import logging
  import os
  from types import MethodType
  from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, Optional, Type, TypeVar
  from lightning_utilities.core.imports import RequirementCache
  from torch import nn
  from typing_extensions import Concatenate, ParamSpec
  import lightning.pytorch
label_desc: Use image node_id 3 for calling the _ModuleMode obj's underlying member method code with example usage: obj.restore(module) without return types