code: def test_nested_model():
      def get_model():
          inputs = tf.keras.Input(shape=(4,))
          outputs = tf.keras.layers.Dense(1)(inputs)
          return tf.keras.Model(inputs, outputs)
  
      model1 = get_model()
      model2 = get_model()
      model3 = get_model()
  
      inputs = tf.keras.Input(shape=(4,))
      y1 = model1(inputs)
      y2 = model2(inputs)
      y3 = model3(inputs)
      outputs = tf.keras.layers.Average()([y1, y2, y3])
      model = tf.keras.Model(inputs, outputs)
  
      optimizers_and_layers = [
          (tf.keras.optimizers.SGD(), model1),
          (tf.keras.optimizers.SGD(learning_rate=0.0), model2),
          (tf.keras.optimizers.SGD(), model3),
      ]
  
      model1_weights_before_train = [
          weight.numpy() for weight in model1.weights
      ]
      model2_weights_before_train = [
          weight.numpy() for weight in model2.weights
      ]
      model3_weights_before_train = [
          weight.numpy() for weight in model3.weights
      ]
  
      multi_optimizer = MultiOptimizer(optimizers_and_layers)
  
      model.compile(multi_optimizer, loss="mse")
  
      x = np.ones((128, 4)).astype(np.float32)
      y = np.ones((128, 32)).astype(np.float32)
      model.fit(x, y)
  
      model1_weights_after_train = [
          weight.numpy() for weight in model1.weights
      ]
      model2_weights_after_train = [
          weight.numpy() for weight in model2.weights
      ]
      model3_weights_after_train = [
          weight.numpy() for weight in model3.weights
      ]
  
      assert_list_not_allclose(
          model1_weights_before_train, model1_weights_after_train
      )
      assert_list_allclose(
          model2_weights_before_train, model2_weights_after_train
      )
      assert_list_not_allclose(
          model3_weights_before_train, model3_weights_after_train
      )
      assert_sync_iterations(model.optimizer, desired=ceil(128 / 32))
  
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 9 for calling a global function with example usage: test_nested_model() and returns: tf