docstr: Check that the parameters of the transformer DO change when using bert_finetune
docstr_tok: ["Check","that","the","parameters","of","the","transformer","DO","change","when","using","bert_finetune"]
code: def finetune_transformer_test(
      self, wordvec_pretrain_file, transformer_name
  ):
      """
      Check that the parameters of the transformer DO change when using bert_finetune
      """
      with tempfile.TemporaryDirectory(
          dir=TEST_WORKING_DIR
      ) as tmpdirname:
          args = [
              "--bert_model",
              transformer_name,
              "--bert_finetune",
              "--optim",
              "adamw",
          ]
          args, trained_model = self.run_train_test(
              wordvec_pretrain_file, tmpdirname, extra_args=args
          )
  
          # check that the weights are different
          foundation_cache = FoundationCache()
          bert_model, bert_tokenizer = foundation_cache.load_bert(
              transformer_name
          )
          assert not self.bert_weights_allclose(
              bert_model, trained_model
          )
  
          # double check that a new bert is created instead of using the FoundationCache when the bert has been trained
          no_finetune_args = self.training_args(
              wordvec_pretrain_file,
              tmpdirname,
              None,
              None,
              "--no_bert_finetune",
              "--no_stage1_bert_finetune",
              "--bert_model",
              transformer_name,
          )
          trained_model = trainer.Trainer.load(
              args["save_name"],
              args=no_finetune_args,
              foundation_cache=foundation_cache,
          )
          assert not trained_model.model.args["bert_finetune"]
          assert not trained_model.model.args["stage1_bert_finetune"]
          assert trained_model.model.bert_model is not bert_model
  
imports: from collections import defaultdict
  import logging
  import pathlib
  import tempfile
  import pytest
  import torch
  from torch import optim
  from stanza import Pipeline
  from stanza.models import constituency_parser
  from stanza.models.common import pretrain
  from stanza.models.common.bert_embedding import load_bert, load_tokenizer
  from stanza.models.common.foundation_cache import FoundationCache
  from stanza.models.common.utils import set_random_seed
  from stanza.models.constituency import lstm_model
  from stanza.models.constituency import trainer
  from stanza.models.constituency import tree_reader
  from stanza.tests import *
label_desc: Use image node_id 25 for calling the TestTrainer obj's underlying member method code with example usage: obj.finetune_transformer_test(wordvec_pretrain_file, transformer_name) without return types