code: def testFrozenWeightsUnchangedByTraining(self):
      # Arrange.
      hparams = transformer.transformer_tiny()
      hparams.add_hparam("num_trainable_top_decoder_layers", 1)
      model, features = get_model(hparams, num_decoder_layers=3)
      out_logits, _ = model(features)
      out_logits = tf.squeeze(out_logits, axis=[2, 3])
      loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
          logits=tf.reshape(out_logits, [-1, VOCAB_SIZE]),
          labels=tf.reshape(features["targets"], [-1]),
      )
      loss = tf.reduce_mean(loss)
      apply_grad = tf.train.AdamOptimizer(0.001).minimize(loss)
      frozen_names = [
          "evolved_transformer/symbol_modality_10_4/shared/weights_0:0",
          "evolved_transformer/symbol_modality_10_4/shared/weights_1:0",
          "evolved_transformer/symbol_modality_10_4/shared/weights_2:0",
          "evolved_transformer/symbol_modality_10_4/shared/weights_3:0",
          "evolved_transformer/symbol_modality_10_4/shared/weights_4:0",
          "evolved_transformer/symbol_modality_10_4/shared/weights_5:0",
          "evolved_transformer/symbol_modality_10_4/shared/weights_6:0",
          "evolved_transformer/symbol_modality_10_4/shared/weights_7:0",
          "evolved_transformer/symbol_modality_10_4/shared/weights_8:0",
          "evolved_transformer/symbol_modality_10_4/shared/weights_9:0",
          "evolved_transformer/body/target_space_embedding/kernel:0",
          "evolved_transformer/body/encoder/layer_0/gated_linear_unit/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/encoder/layer_0/gated_linear_unit/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/encoder/layer_0/gated_linear_unit/dense/kernel:0",
          "evolved_transformer/body/encoder/layer_0/gated_linear_unit/dense/bias:0",
          "evolved_transformer/body/encoder/layer_0/gated_linear_unit/dense_1/kernel:0",
          "evolved_transformer/body/encoder/layer_0/gated_linear_unit/dense_1/bias:0",
          "evolved_transformer/body/encoder/layer_0/conv_branches/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/encoder/layer_0/conv_branches/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/encoder/layer_0/conv_branches/dense/kernel:0",
          "evolved_transformer/body/encoder/layer_0/conv_branches/dense/bias:0",
          "evolved_transformer/body/encoder/layer_0/conv_branches/standard_conv_3x1/kernel:0",
          "evolved_transformer/body/encoder/layer_0/conv_branches/standard_conv_3x1/bias:0",
          "evolved_transformer/body/encoder/layer_0/conv_branches/layer_prepostprocess_1/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/encoder/layer_0/conv_branches/layer_prepostprocess_1/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/encoder/layer_0/conv_branches/separable_conv_9x1/depthwise_kernel:0",
          "evolved_transformer/body/encoder/layer_0/conv_branches/separable_conv_9x1/pointwise_kernel:0",
          "evolved_transformer/body/encoder/layer_0/conv_branches/separable_conv_9x1/bias:0",
          "evolved_transformer/body/encoder/layer_0/self_attention/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/encoder/layer_0/self_attention/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/encoder/layer_0/self_attention/multihead_attention/q/kernel:0",
          "evolved_transformer/body/encoder/layer_0/self_attention/multihead_attention/k/kernel:0",
          "evolved_transformer/body/encoder/layer_0/self_attention/multihead_attention/v/kernel:0",
          "evolved_transformer/body/encoder/layer_0/self_attention/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/encoder/layer_0/dense_layers/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/encoder/layer_0/dense_layers/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/encoder/layer_0/dense_layers/dense/kernel:0",
          "evolved_transformer/body/encoder/layer_0/dense_layers/dense/bias:0",
          "evolved_transformer/body/encoder/layer_0/dense_layers/dense_1/kernel:0",
          "evolved_transformer/body/encoder/layer_0/dense_layers/dense_1/bias:0",
          "evolved_transformer/body/encoder/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/encoder/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_0/16_head_self_attention/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_0/16_head_self_attention/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_0/16_head_self_attention/multihead_attention/q/kernel:0",
          "evolved_transformer/body/decoder/layer_0/16_head_self_attention/multihead_attention/k/kernel:0",
          "evolved_transformer/body/decoder/layer_0/16_head_self_attention/multihead_attention/v/kernel:0",
          "evolved_transformer/body/decoder/layer_0/16_head_self_attention/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/decoder/layer_0/first_attend_to_encoder/multihead_attention/q/kernel:0",
          "evolved_transformer/body/decoder/layer_0/first_attend_to_encoder/multihead_attention/k/kernel:0",
          "evolved_transformer/body/decoder/layer_0/first_attend_to_encoder/multihead_attention/v/kernel:0",
          "evolved_transformer/body/decoder/layer_0/first_attend_to_encoder/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/separable_conv11x1/depthwise_kernel:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/separable_conv11x1/pointwise_kernel:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/separable_conv11x1/bias:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/separable_conv_7x1_1/depthwise_kernel:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/separable_conv_7x1_1/pointwise_kernel:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/separable_conv_7x1_1/bias:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/layer_prepostprocess_1/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/layer_prepostprocess_1/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/separable_conv_7x1_2/depthwise_kernel:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/separable_conv_7x1_2/pointwise_kernel:0",
          "evolved_transformer/body/decoder/layer_0/conv_branches/separable_conv_7x1_2/bias:0",
          "evolved_transformer/body/decoder/layer_0/self_attention/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_0/self_attention/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_0/self_attention/multihead_attention/q/kernel:0",
          "evolved_transformer/body/decoder/layer_0/self_attention/multihead_attention/k/kernel:0",
          "evolved_transformer/body/decoder/layer_0/self_attention/multihead_attention/v/kernel:0",
          "evolved_transformer/body/decoder/layer_0/self_attention/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/decoder/layer_0/second_attend_to_encoder/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_0/second_attend_to_encoder/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_0/second_attend_to_encoder/multihead_attention/q/kernel:0",
          "evolved_transformer/body/decoder/layer_0/second_attend_to_encoder/multihead_attention/k/kernel:0",
          "evolved_transformer/body/decoder/layer_0/second_attend_to_encoder/multihead_attention/v/kernel:0",
          "evolved_transformer/body/decoder/layer_0/second_attend_to_encoder/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/decoder/layer_0/dense_layers/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_0/dense_layers/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_0/dense_layers/dense/kernel:0",
          "evolved_transformer/body/decoder/layer_0/dense_layers/dense/bias:0",
          "evolved_transformer/body/decoder/layer_0/dense_layers/layer_prepostprocess_1/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_0/dense_layers/layer_prepostprocess_1/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_0/dense_layers/dense_1/kernel:0",
          "evolved_transformer/body/decoder/layer_0/dense_layers/dense_1/bias:0",
          "evolved_transformer/body/decoder/layer_1/16_head_self_attention/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_1/16_head_self_attention/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_1/16_head_self_attention/multihead_attention/q/kernel:0",
          "evolved_transformer/body/decoder/layer_1/16_head_self_attention/multihead_attention/k/kernel:0",
          "evolved_transformer/body/decoder/layer_1/16_head_self_attention/multihead_attention/v/kernel:0",
          "evolved_transformer/body/decoder/layer_1/16_head_self_attention/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/decoder/layer_1/first_attend_to_encoder/multihead_attention/q/kernel:0",
          "evolved_transformer/body/decoder/layer_1/first_attend_to_encoder/multihead_attention/k/kernel:0",
          "evolved_transformer/body/decoder/layer_1/first_attend_to_encoder/multihead_attention/v/kernel:0",
          "evolved_transformer/body/decoder/layer_1/first_attend_to_encoder/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/separable_conv11x1/depthwise_kernel:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/separable_conv11x1/pointwise_kernel:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/separable_conv11x1/bias:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/separable_conv_7x1_1/depthwise_kernel:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/separable_conv_7x1_1/pointwise_kernel:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/separable_conv_7x1_1/bias:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/layer_prepostprocess_1/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/layer_prepostprocess_1/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/separable_conv_7x1_2/depthwise_kernel:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/separable_conv_7x1_2/pointwise_kernel:0",
          "evolved_transformer/body/decoder/layer_1/conv_branches/separable_conv_7x1_2/bias:0",
          "evolved_transformer/body/decoder/layer_1/self_attention/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_1/self_attention/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_1/self_attention/multihead_attention/q/kernel:0",
          "evolved_transformer/body/decoder/layer_1/self_attention/multihead_attention/k/kernel:0",
          "evolved_transformer/body/decoder/layer_1/self_attention/multihead_attention/v/kernel:0",
          "evolved_transformer/body/decoder/layer_1/self_attention/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/decoder/layer_1/second_attend_to_encoder/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_1/second_attend_to_encoder/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_1/second_attend_to_encoder/multihead_attention/q/kernel:0",
          "evolved_transformer/body/decoder/layer_1/second_attend_to_encoder/multihead_attention/k/kernel:0",
          "evolved_transformer/body/decoder/layer_1/second_attend_to_encoder/multihead_attention/v/kernel:0",
          "evolved_transformer/body/decoder/layer_1/second_attend_to_encoder/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/decoder/layer_1/dense_layers/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_1/dense_layers/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_1/dense_layers/dense/kernel:0",
          "evolved_transformer/body/decoder/layer_1/dense_layers/dense/bias:0",
          "evolved_transformer/body/decoder/layer_1/dense_layers/layer_prepostprocess_1/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_1/dense_layers/layer_prepostprocess_1/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_1/dense_layers/dense_1/kernel:0",
          "evolved_transformer/body/decoder/layer_1/dense_layers/dense_1/bias:0",
      ]
      train_names = [
          "evolved_transformer/body/decoder/layer_2/16_head_self_attention/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_2/16_head_self_attention/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_2/16_head_self_attention/multihead_attention/q/kernel:0",
          "evolved_transformer/body/decoder/layer_2/16_head_self_attention/multihead_attention/k/kernel:0",
          "evolved_transformer/body/decoder/layer_2/16_head_self_attention/multihead_attention/v/kernel:0",
          "evolved_transformer/body/decoder/layer_2/16_head_self_attention/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/decoder/layer_2/first_attend_to_encoder/multihead_attention/q/kernel:0",
          "evolved_transformer/body/decoder/layer_2/first_attend_to_encoder/multihead_attention/k/kernel:0",
          "evolved_transformer/body/decoder/layer_2/first_attend_to_encoder/multihead_attention/v/kernel:0",
          "evolved_transformer/body/decoder/layer_2/first_attend_to_encoder/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/separable_conv11x1/depthwise_kernel:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/separable_conv11x1/pointwise_kernel:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/separable_conv11x1/bias:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/separable_conv_7x1_1/depthwise_kernel:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/separable_conv_7x1_1/pointwise_kernel:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/separable_conv_7x1_1/bias:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/layer_prepostprocess_1/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/layer_prepostprocess_1/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/separable_conv_7x1_2/depthwise_kernel:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/separable_conv_7x1_2/pointwise_kernel:0",
          "evolved_transformer/body/decoder/layer_2/conv_branches/separable_conv_7x1_2/bias:0",
          "evolved_transformer/body/decoder/layer_2/self_attention/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_2/self_attention/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_2/self_attention/multihead_attention/q/kernel:0",
          "evolved_transformer/body/decoder/layer_2/self_attention/multihead_attention/k/kernel:0",
          "evolved_transformer/body/decoder/layer_2/self_attention/multihead_attention/v/kernel:0",
          "evolved_transformer/body/decoder/layer_2/self_attention/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/decoder/layer_2/second_attend_to_encoder/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_2/second_attend_to_encoder/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_2/second_attend_to_encoder/multihead_attention/q/kernel:0",
          "evolved_transformer/body/decoder/layer_2/second_attend_to_encoder/multihead_attention/k/kernel:0",
          "evolved_transformer/body/decoder/layer_2/second_attend_to_encoder/multihead_attention/v/kernel:0",
          "evolved_transformer/body/decoder/layer_2/second_attend_to_encoder/multihead_attention/output_transform/kernel:0",
          "evolved_transformer/body/decoder/layer_2/dense_layers/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_2/dense_layers/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_2/dense_layers/dense/kernel:0",
          "evolved_transformer/body/decoder/layer_2/dense_layers/dense/bias:0",
          "evolved_transformer/body/decoder/layer_2/dense_layers/layer_prepostprocess_1/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_2/dense_layers/layer_prepostprocess_1/layer_norm/layer_norm_bias:0",
          "evolved_transformer/body/decoder/layer_2/dense_layers/dense_1/kernel:0",
          "evolved_transformer/body/decoder/layer_2/dense_layers/dense_1/bias:0",
          "evolved_transformer/body/decoder/layer_prepostprocess/layer_norm/layer_norm_scale:0",
          "evolved_transformer/body/decoder/layer_prepostprocess/layer_norm/layer_norm_bias:0",
          "evolved_transformer/symbol_modality_10_4/softmax/weights_1:0",
          "evolved_transformer/symbol_modality_10_4/softmax/weights_2:0",
          "evolved_transformer/symbol_modality_10_4/softmax/weights_3:0",
          "evolved_transformer/symbol_modality_10_4/softmax/weights_4:0",
          "evolved_transformer/symbol_modality_10_4/softmax/weights_5:0",
          "evolved_transformer/symbol_modality_10_4/softmax/weights_6:0",
          "evolved_transformer/symbol_modality_10_4/softmax/weights_7:0",
          "evolved_transformer/symbol_modality_10_4/softmax/weights_8:0",
          "evolved_transformer/symbol_modality_10_4/softmax/weights_9:0",
      ]
      frozen_vars = get_vars(frozen_names)
      train_vars = get_vars(train_names)
      print_vars()
  
      # Act.
      with self.test_session() as session:
          tf.global_variables_initializer().run()
          frozen_values_before = session.run(frozen_vars)
          train_values_before = session.run(train_vars)
          for _ in range(10):  # Arbitrary number of training steps.
              apply_grad.run()
          frozen_values_after = session.run(frozen_vars)
          train_values_after = session.run(train_vars)
  
      # Assert.
      self.assertTrue(
          model._original_hparams.shared_embedding_and_softmax_weights
      )
      self.assertFalse(
          model.hparams.shared_embedding_and_softmax_weights
      )
      self.assertTrue(model.hparams.shared_embedding)
      for name, before, after in zip(
          frozen_names, frozen_values_before, frozen_values_after
      ):
          assert_with_message(
              self.assertAllClose,
              before,
              after,
              "%s should be frozen, but changed after training." % name,
          )
      for name, before, after in zip(
          train_names, train_values_before, train_values_after
      ):
          assert_with_message(
              self.assertNotAllClose,
              before,
              after,
              "%s should be trainable, but did not change after training."
              % name,
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  from tensor2tensor.data_generators import problem_hparams
  from tensor2tensor.models import evolved_transformer
  from tensor2tensor.models import transformer
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 9 for calling the EvolvedTransformerTest obj's underlying member method code with example usage: obj.testFrozenWeightsUnchangedByTraining() without return types