class_docstr: Base class for continual learning skeletons.
  
  **Training loop**
  The training loop is organized as follows::
  
      train
          train_exp  # for each experience
  
  **Evaluation loop**
  The evaluation loop is organized as follows::
  
      eval
          eval_exp  # for each experience
class_docstr_tok: ["Base","class","for","continual","learning","skeletons",".","*","*","Training","loop","*","*","The","training","loop","is","organized","as","follows",":",":","train","train_exp","#","for","each","experience","*","*","Evaluation","loop","*","*","The","evaluation","loop","is","organized","as","follows",":",":","eval","eval_exp","#","for","each","experience"]
docstr: Save the training state, which may be modified by the eval loop.
  
  TODO: we probably need a better way to do this.
docstr_tok: ["Save","the","training","state",",","which","may","be","modified","by","the","eval","loop",".","TODO",":","we","probably","need","a","better","way","to","do","this","."]
code: def _save_train_state(self):
      """Save the training state, which may be modified by the eval loop.
  
      TODO: we probably need a better way to do this.
      """
      # save each layer's training mode, to restore it later
      _prev_model_training_modes = {}
      for name, layer in self.model.named_modules():
          _prev_model_training_modes[name] = layer.training
  
      _prev_state = {
          "experience": self.experience,
          "is_training": self.is_training,
          "model_training_mode": _prev_model_training_modes,
      }
      return _prev_state
  
imports: import sys
  import warnings
  from collections import defaultdict
  from typing import Iterable, Sequence, Optional, TypeVar, Union, List
  import torch
  from torch.nn import Module
  from avalanche.benchmarks import CLExperience, CLStream
  from avalanche.core import BasePlugin
  from avalanche.distributed.distributed_helper import DistributedHelper
  from avalanche.training.templates.strategy_mixin_protocol import BaseStrategyProtocol
  from avalanche.training.utils import trigger_plugins
label_desc: Use image node_id 9 for calling the BaseTemplate obj's underlying member method code with example usage: obj._save_train_state() and returns: _prev_state