code: def test_fine_tune_nograd_regex(self):
      original_model = load_archive(self.model_archive).model
      name_parameters_original = dict(original_model.named_parameters())
      regex_lists = [
          [],
          [".*attend_feedforward.*", ".*token_embedder.*"],
          [".*compare_feedforward.*"],
      ]
      for regex_list in regex_lists:
          params = Params.from_file(self.config_file)
          params["trainer"]["no_grad"] = regex_list
          shutil.rmtree(self.serialization_dir, ignore_errors=True)
          tuned_model = fine_tune_model(
              model=original_model,
              params=params,
              serialization_dir=self.serialization_dir,
          )
          # If regex is matched, parameter name should have requires_grad False
          # If regex is matched, parameter name should have same requires_grad
          # as the originally loaded model
          for name, parameter in tuned_model.named_parameters():
              if any(re.search(regex, name) for regex in regex_list):
                  assert not parameter.requires_grad
              else:
                  assert (
                      parameter.requires_grad
                      == name_parameters_original[name].requires_grad
                  )
      # If all parameters have requires_grad=False, then error.
      with pytest.raises(Exception) as _:
          params = Params.from_file(self.config_file)
          params["trainer"]["no_grad"] = ["*"]
          shutil.rmtree(self.serialization_dir, ignore_errors=True)
          tuned_model = fine_tune_model(
              model=original_model,
              params=params,
              serialization_dir=self.serialization_dir,
          )
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/commands/fine_tune_test.py
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  import argparse
  import re
  import shutil
  import pytest
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.commands.fine_tune import FineTune, fine_tune_model_from_file_paths, fine_tune_model_from_args, fine_tune_model
  from allennlp.common.params import Params
  from allennlp.models import load_archive
label_desc: Use image node_id 7 for calling the TestFineTune obj's underlying member method code with example usage: obj.test_fine_tune_nograd_regex() without return types