code: def test_fit_layer_optimizer(device, serialize, tmpdir):
      model = tf.keras.Sequential(
          [
              tf.keras.Input(shape=[1]),
              tf.keras.layers.Dense(1),
              tf.keras.layers.Dense(1),
          ]
      )
  
      x = np.array(np.ones([100]))
      y = np.array(np.ones([100]))
  
      dense1_weights_before_train = [
          weight.numpy() for weight in model.layers[0].weights
      ]
      dense2_weights_before_train = [
          weight.numpy() for weight in model.layers[1].weights
      ]
  
      opt1 = tf.keras.optimizers.Adam(learning_rate=1e-3)
      opt2 = tf.keras.optimizers.SGD(learning_rate=0)
  
      opt_layer_pairs = [
          (opt1, model.layers[0]),
          (opt2, model.layers[1]),
      ]
  
      loss = tf.keras.losses.MSE
      optimizer = MultiOptimizer(opt_layer_pairs)
  
      model.compile(optimizer=optimizer, loss=loss)
  
      # serialize whole model including optimizer, clear the session, then reload the whole model.
      if serialize:
          model.save(str(tmpdir), save_format="tf")
          tf.keras.backend.clear_session()
          model = tf.keras.models.load_model(str(tmpdir))
  
      model.fit(x, y, batch_size=8, epochs=10)
  
      dense1_weights_after_train = [
          weight.numpy() for weight in model.layers[0].weights
      ]
      dense2_weights_after_train = [
          weight.numpy() for weight in model.layers[1].weights
      ]
  
      assert_list_not_allclose(
          dense1_weights_before_train, dense1_weights_after_train
      )
      assert_list_allclose(
          dense2_weights_before_train, dense2_weights_after_train
      )
      assert_sync_iterations(
          model.optimizer, desired=ceil(100 / 8) * 10
      )
  
file_path: addons/tensorflow_addons/optimizers/tests/discriminative_layer_training_test.py
imports: from math import ceil
  from packaging.version import Version
  import pytest
  import numpy
  import tensorflow
  from tensorflow_addons.optimizers.discriminative_layer_training import MultiOptimizer
  from tensorflow_addons.utils import test_utils
label_desc: Use image node_id 4 for calling a global function with example usage: test_fit_layer_optimizer(device, serialize, tmpdir) without return types