code: def test_dynamic_decay():
      var0 = tf.Variable([1.0, 2.0])
      grads0 = tf.constant([0.1, 0.1])
      grads_and_vars = [(grads0, var0)]
  
      if hasattr(tf.keras.optimizers, "legacy"):
          opt = MovingAverage(
              tf.keras.optimizers.legacy.SGD(lr=2.0),
              average_decay=0.5,
              dynamic_decay=True,
          )
      else:
          opt = MovingAverage(
              tf.keras.optimizers.SGD(lr=2.0),
              average_decay=0.5,
              dynamic_decay=True,
          )
  
      opt.apply_gradients(grads_and_vars)
      opt.apply_gradients(grads_and_vars)
  
      np.testing.assert_allclose(var0.read_value(), [0.6, 1.6])
  
      ema_var0 = opt.get_slot(var0, "average")
      np.testing.assert_allclose(ema_var0.read_value(), [0.64, 1.64])
  
imports: import numpy
  import pytest
  import tensorflow
  from packaging.version import Version
  from tensorflow_addons.optimizers import MovingAverage
label_desc: Use image node_id 12 for calling a global function with example usage: test_dynamic_decay() without return types