code: def test_train_model_eval_model(self):
      class TestModel(nn.Module):
          def __init__(self):
              super().__init__()
              self.linear = nn.Linear(1, 2)
              self.dropout = nn.Dropout()
              self.seq = nn.Sequential(
                  nn.ReLU(), nn.Conv2d(1, 2, 3), nn.BatchNorm2d(1, 2)
              )
  
      test_model = TestModel()
      for train in [True, False]:
          test_model.train(train)
  
          # flip some of the modes
          test_model.dropout.train(not train)
          test_model.seq[1].train(not train)
  
          orig_model = copy.deepcopy(test_model)
  
          with util.train_model(test_model):
              self._check_model_train_mode(test_model, True)
              # the modes should be different inside the context manager
              self.assertFalse(
                  self._compare_model_train_mode(orig_model, test_model)
              )
          self.assertTrue(
              self._compare_model_train_mode(orig_model, test_model)
          )
  
          with util.eval_model(test_model):
              self._check_model_train_mode(test_model, False)
              # the modes should be different inside the context manager
              self.assertFalse(
                  self._compare_model_train_mode(orig_model, test_model)
              )
          self.assertTrue(
              self._compare_model_train_mode(orig_model, test_model)
          )
  
imports: import copy
  import shutil
  import tempfile
  import unittest
  import unittest.mock
  from pathlib import Path
  import classy_vision.generic.util
  import torch
  import torch.nn
  from classy_vision.generic.util import CHECKPOINT_FILE, get_torch_version, load_checkpoint, save_checkpoint, split_batchnorm_params, Timer, update_classy_model, update_classy_state
  from classy_vision.models import build_model
  from classy_vision.tasks import build_task
  from classy_vision.trainer import LocalTrainer
  from test.generic.config_utils import get_fast_test_task_config, get_test_model_configs
  from test.generic.utils import compare_model_state, compare_states
label_desc: Use image node_id 9 for calling the TestUtilMethods obj's underlying member method code with example usage: obj.test_train_model_eval_model() without return types