Repository: tensorflow/addons

Issue:
cyclical_learning_rate_test.py is not run by bazel


**Describe the bug**

Like the other ones, the 
```
if __name__ == "__main__":
    tf.test.main()
```

was missing. Since pytest doesn't need that, the tests failed with pytest.

**Other info / logs**

The error when actually running the tests:

```
proof_of_concept_pytest) /mnt/c/Users/gdemarmi/Desktop/projects/addons $ pytest -v tensorflow_addons/optimizers/cyclical_learning_rate_test.py

/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/pep8.py:110: FutureWarning: Possible nested set at position 1
  EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
============================================================= test session starts =============================================================
platform linux -- Python 3.7.5, pytest-5.0.1, py-1.8.0, pluggy-0.13.0 -- /home/gdemarmi/softwares/python/anaconda/bin/python
cachedir: .pytest_cache
rootdir: /mnt/c/Users/gdemarmi/Desktop/projects/addons
plugins: arraydiff-0.3, cov-2.7.1, doctestplus-0.2.0, flake8-1.0.4, forked-1.0.2, openfiles-0.4.0, pep8-1.0.6, remotedata-0.3.2, xdist-1.27.0, typeguard-2.7.1
collected 9 items

tensorflow_addons/optimizers/cyclical_learning_rate_test.py::CyclicalLearningRateTest::testCustomCyclicalLearningRateNotSerialized FAILED [ 11%]
tensorflow_addons/optimizers/cyclical_learning_rate_test.py::CyclicalLearningRateTest::testCustomCyclicalLearningRateSerialized FAILED  [ 22%]
tensorflow_addons/optimizers/cyclical_learning_rate_test.py::CyclicalLearningRateTest::testExponentialCyclicalLearningRateNotSerialized FAILED [ 33%]
tensorflow_addons/optimizers/cyclical_learning_rate_test.py::CyclicalLearningRateTest::testExponentialCyclicalLearningRateSerialized FAILED [ 44%]
tensorflow_addons/optimizers/cyclical_learning_rate_test.py::CyclicalLearningRateTest::testTriangular2CyclicalLearningRateNotSerialized FAILED [ 55%]
tensorflow_addons/optimizers/cyclical_learning_rate_test.py::CyclicalLearningRateTest::testTriangular2CyclicalLearningRateSerialized FAILED [ 66%]
tensorflow_addons/optimizers/cyclical_learning_rate_test.py::CyclicalLearningRateTest::testTriangularCyclicalLearningRateNotSerialized FAILED [ 77%]
tensorflow_addons/optimizers/cyclical_learning_rate_test.py::CyclicalLearningRateTest::testTriangularCyclicalLearningRateSerialized FAILED [ 88%]
tensorflow_addons/optimizers/cyclical_learning_rate_test.py::CyclicalLearningRateTest::test_session SKIPPED                             [100%]

================================================================== FAILURES ===================================================================
____________________________________ CyclicalLearningRateTest.testCustomCyclicalLearningRateNotSerialized _____________________________________

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testCustomCyclicalLearningRateNotSerialized>
args = (), kwargs = {}

    def decorated(self, *args, **kwargs):
      try:
        with context.graph_mode():
          with self.test_session(use_gpu=use_gpu, config=config):
>           f(self, *args, **kwargs)

/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/tensorflow_core/python/framework/test_util.py:1111:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/absl/testing/parameterized.py:264: in bound_param_test
    test_method(self, *testcase_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testCustomCyclicalLearningRateNotSerialized>
serialize = False

    def testCustomCyclicalLearningRate(self, serialize):
        initial_learning_rate = 0.1
        maximal_learning_rate = 1
        step_size = 4000

        def scale_fn(x):
            return 1 / (5 ** (x * 0.0001))

>       step = tf.resource_variable_ops.ResourceVariable(0)
E       AttributeError: module 'tensorflow' has no attribute 'resource_variable_ops'

tensorflow_addons/optimizers/cyclical_learning_rate_test.py:129: AttributeError
------------------------------------------------------------ Captured stderr call -------------------------------------------------------------
WARNING: Logging before flag parsing goes to stderr.
W0302 15:45:42.446717 139693714835264 deprecation.py:323] From /home/gdemarmi/softwares/python/anaconda/lib/python3.7/contextlib.py:82: TensorFlowTestCase.test_session (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `self.session()` or `self.cached_session()` instead.
2020-03-02 15:45:42.451354: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2020-03-02 15:45:42.451502: E tensorflow/stream_executor/cuda/cuda_driver.cc:351] failed call to cuInit: UNKNOWN ERROR (303)
2020-03-02 15:45:42.451576: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (CRE1-L11685): /proc/driver/nvidia/version does not exist
2020-03-02 15:45:42.453397: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-03-02 15:45:42.468495: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2712000000 Hz
2020-03-02 15:45:42.469841: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7ffff0301480 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-03-02 15:45:42.469978: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
-------------------------------------------------------------- Captured log call --------------------------------------------------------------
WARNING  tensorflow:deprecation.py:323 From /home/gdemarmi/softwares/python/anaconda/lib/python3.7/contextlib.py:82: TensorFlowTestCase.test_session (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
                                       Instructions for updating:
                                       Use `self.session()` or `self.cached_session()` instead.
______________________________________ CyclicalLearningRateTest.testCustomCyclicalLearningRateSerialized ______________________________________

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testCustomCyclicalLearningRateSerialized>
args = (), kwargs = {}

    def decorated(self, *args, **kwargs):
      try:
        with context.graph_mode():
          with self.test_session(use_gpu=use_gpu, config=config):
>           f(self, *args, **kwargs)

/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/tensorflow_core/python/framework/test_util.py:1111:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/absl/testing/parameterized.py:264: in bound_param_test
    test_method(self, *testcase_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testCustomCyclicalLearningRateSerialized>
serialize = True

    def testCustomCyclicalLearningRate(self, serialize):
        initial_learning_rate = 0.1
        maximal_learning_rate = 1
        step_size = 4000

        def scale_fn(x):
            return 1 / (5 ** (x * 0.0001))

>       step = tf.resource_variable_ops.ResourceVariable(0)
E       AttributeError: module 'tensorflow' has no attribute 'resource_variable_ops'

tensorflow_addons/optimizers/cyclical_learning_rate_test.py:129: AttributeError
__________________________________ CyclicalLearningRateTest.testExponentialCyclicalLearningRateNotSerialized __________________________________

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testExponentialCyclicalLearningRateNotSerialized>
args = (), kwargs = {}

    def decorated(self, *args, **kwargs):
      try:
        with context.graph_mode():
          with self.test_session(use_gpu=use_gpu, config=config):
>           f(self, *args, **kwargs)

/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/tensorflow_core/python/framework/test_util.py:1111:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/absl/testing/parameterized.py:264: in bound_param_test
    test_method(self, *testcase_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testExponentialCyclicalLearningRateNotSerialized>
serialize = False

    def testExponentialCyclicalLearningRate(self, serialize):
        initial_learning_rate = 0.1
        maximal_learning_rate = 1
        step_size = 4000
        gamma = 0.996

>       step = tf.resource_variable_ops.ResourceVariable(0)
E       AttributeError: module 'tensorflow' has no attribute 'resource_variable_ops'

tensorflow_addons/optimizers/cyclical_learning_rate_test.py:98: AttributeError
___________________________________ CyclicalLearningRateTest.testExponentialCyclicalLearningRateSerialized ____________________________________

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testExponentialCyclicalLearningRateSerialized>
args = (), kwargs = {}

    def decorated(self, *args, **kwargs):
      try:
        with context.graph_mode():
          with self.test_session(use_gpu=use_gpu, config=config):
>           f(self, *args, **kwargs)

/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/tensorflow_core/python/framework/test_util.py:1111:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/absl/testing/parameterized.py:264: in bound_param_test
    test_method(self, *testcase_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testExponentialCyclicalLearningRateSerialized>
serialize = True

    def testExponentialCyclicalLearningRate(self, serialize):
        initial_learning_rate = 0.1
        maximal_learning_rate = 1
        step_size = 4000
        gamma = 0.996

>       step = tf.resource_variable_ops.ResourceVariable(0)
E       AttributeError: module 'tensorflow' has no attribute 'resource_variable_ops'

tensorflow_addons/optimizers/cyclical_learning_rate_test.py:98: AttributeError
__________________________________ CyclicalLearningRateTest.testTriangular2CyclicalLearningRateNotSerialized __________________________________

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testTriangular2CyclicalLearningRateNotSerialized>
args = (), kwargs = {}

    def decorated(self, *args, **kwargs):
      try:
        with context.graph_mode():
          with self.test_session(use_gpu=use_gpu, config=config):
>           f(self, *args, **kwargs)

/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/tensorflow_core/python/framework/test_util.py:1111:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/absl/testing/parameterized.py:264: in bound_param_test
    test_method(self, *testcase_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testTriangular2CyclicalLearningRateNotSerialized>
serialize = False

    def testTriangular2CyclicalLearningRate(self, serialize):
        initial_learning_rate = 0.1
        maximal_learning_rate = 1
        step_size = 4000
>       step = tf.resource_variable_ops.ResourceVariable(0)
E       AttributeError: module 'tensorflow' has no attribute 'resource_variable_ops'

tensorflow_addons/optimizers/cyclical_learning_rate_test.py:67: AttributeError
___________________________________ CyclicalLearningRateTest.testTriangular2CyclicalLearningRateSerialized ____________________________________

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testTriangular2CyclicalLearningRateSerialized>
args = (), kwargs = {}

    def decorated(self, *args, **kwargs):
      try:
        with context.graph_mode():
          with self.test_session(use_gpu=use_gpu, config=config):
>           f(self, *args, **kwargs)

/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/tensorflow_core/python/framework/test_util.py:1111:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/absl/testing/parameterized.py:264: in bound_param_test
    test_method(self, *testcase_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testTriangular2CyclicalLearningRateSerialized>
serialize = True

    def testTriangular2CyclicalLearningRate(self, serialize):
        initial_learning_rate = 0.1
        maximal_learning_rate = 1
        step_size = 4000
>       step = tf.resource_variable_ops.ResourceVariable(0)
E       AttributeError: module 'tensorflow' has no attribute 'resource_variable_ops'

tensorflow_addons/optimizers/cyclical_learning_rate_test.py:67: AttributeError
__________________________________ CyclicalLearningRateTest.testTriangularCyclicalLearningRateNotSerialized ___________________________________

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testTriangularCyclicalLearningRateNotSerialized>
args = (), kwargs = {}

    def decorated(self, *args, **kwargs):
      try:
        with context.graph_mode():
          with self.test_session(use_gpu=use_gpu, config=config):
>           f(self, *args, **kwargs)

/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/tensorflow_core/python/framework/test_util.py:1111:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/absl/testing/parameterized.py:264: in bound_param_test
    test_method(self, *testcase_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testTriangularCyclicalLearningRateNotSerialized>
serialize = False

    def testTriangularCyclicalLearningRate(self, serialize):
        initial_learning_rate = 0.1
        maximal_learning_rate = 1
        step_size = 4000
>       step = tf.resource_variable_ops.ResourceVariable(0)
E       AttributeError: module 'tensorflow' has no attribute 'resource_variable_ops'

tensorflow_addons/optimizers/cyclical_learning_rate_test.py:41: AttributeError
____________________________________ CyclicalLearningRateTest.testTriangularCyclicalLearningRateSerialized ____________________________________

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testTriangularCyclicalLearningRateSerialized>
args = (), kwargs = {}

    def decorated(self, *args, **kwargs):
      try:
        with context.graph_mode():
          with self.test_session(use_gpu=use_gpu, config=config):
>           f(self, *args, **kwargs)

/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/tensorflow_core/python/framework/test_util.py:1111:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/absl/testing/parameterized.py:264: in bound_param_test
    test_method(self, *testcase_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tensorflow_addons.optimizers.cyclical_learning_rate_test.CyclicalLearningRateTest testMethod=testTriangularCyclicalLearningRateSerialized>
serialize = True

    def testTriangularCyclicalLearningRate(self, serialize):
        initial_learning_rate = 0.1
        maximal_learning_rate = 1
        step_size = 4000
>       step = tf.resource_variable_ops.ResourceVariable(0)
E       AttributeError: module 'tensorflow' has no attribute 'resource_variable_ops'

tensorflow_addons/optimizers/cyclical_learning_rate_test.py:41: AttributeError
============================================================== warnings summary ===============================================================
/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/google/protobuf/descriptor.py:47
  /home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/google/protobuf/descriptor.py:47: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
    from google.protobuf.pyext import _message

/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/_collections.py:1
/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/_collections.py:1
  /home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/_collections.py:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
    from collections import Mapping, MutableMapping

/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/absl/testing/parameterized.py:374
  /home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/absl/testing/parameterized.py:374: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
    if not isinstance(testcases, collections.Sequence):

/home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/absl/testing/parameterized.py:200
  /home/gdemarmi/softwares/python/anaconda/lib/python3.7/site-packages/absl/testing/parameterized.py:200: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
    return (isinstance(obj, collections.Iterable) and

-- Docs: https://docs.pytest.org/en/latest/warnings.html
============================================== 8 failed, 1 skipped, 5 warnings in 14.08 seconds ===============================================
```

@raphaelmeudec could you take a look? Thank you very much!



Discussion:

Resolving patch:
diff --git a/tensorflow_addons/optimizers/cyclical_learning_rate.py b/tensorflow_addons/optimizers/cyclical_learning_rate.py
--- a/tensorflow_addons/optimizers/cyclical_learning_rate.py
+++ b/tensorflow_addons/optimizers/cyclical_learning_rate.py
@@ -104,6 +104,7 @@ def get_config(self):
         return {
             "initial_learning_rate": self.initial_learning_rate,
             "maximal_learning_rate": self.maximal_learning_rate,
+            "scale_fn": self.scale_fn,
             "step_size": self.step_size,
             "scale_mode": self.scale_mode,
         }
@@ -169,6 +170,14 @@ def __init__(
             name=name,
         )
 
+    def get_config(self):
+        return {
+            "initial_learning_rate": self.initial_learning_rate,
+            "maximal_learning_rate": self.maximal_learning_rate,
+            "step_size": self.step_size,
+            "scale_mode": self.scale_mode,
+        }
+
 
 @tf.keras.utils.register_keras_serializable(package="Addons")
 class Triangular2CyclicalLearningRate(CyclicalLearningRate):
@@ -230,6 +239,14 @@ def __init__(
             name=name,
         )
 
+    def get_config(self):
+        return {
+            "initial_learning_rate": self.initial_learning_rate,
+            "maximal_learning_rate": self.maximal_learning_rate,
+            "step_size": self.step_size,
+            "scale_mode": self.scale_mode,
+        }
+
 
 @tf.keras.utils.register_keras_serializable(package="Addons")
 class ExponentialCyclicalLearningRate(CyclicalLearningRate):
@@ -297,4 +314,10 @@ def __init__(
         )
 
     def get_config(self):
-        return {"gamma": self.gamma, **super().get_config()}
+        return {
+            "initial_learning_rate": self.initial_learning_rate,
+            "maximal_learning_rate": self.maximal_learning_rate,
+            "step_size": self.step_size,
+            "scale_mode": self.scale_mode,
+            "gamma": self.gamma,
+        }


Test patch:
diff --git a/tensorflow_addons/optimizers/tests/cyclical_learning_rate_test.py b/tensorflow_addons/optimizers/tests/cyclical_learning_rate_test.py
--- a/tensorflow_addons/optimizers/tests/cyclical_learning_rate_test.py
+++ b/tensorflow_addons/optimizers/tests/cyclical_learning_rate_test.py
@@ -15,7 +15,6 @@
 """Tests for Cyclical Learning Rate."""
 
 import pytest
-import tensorflow as tf
 import numpy as np
 
 from tensorflow_addons.optimizers import cyclical_learning_rate
@@ -23,8 +22,8 @@
 
 def _maybe_serialized(lr_decay, serialize_and_deserialize):
     if serialize_and_deserialize:
-        serialized = tf.keras.optimizers.schedules.serialize(lr_decay)
-        return tf.keras.optimizers.schedules.deserialize(serialized)
+        serialized = lr_decay.get_config()
+        return lr_decay.from_config(serialized)
     else:
         return lr_decay
 
@@ -106,9 +105,6 @@ def test_exponential_cyclical_learning_rate(serialize):
         step += 1
 
 
-@pytest.mark.xfail(
-    reason="TODO: fixme https://github.com/tensorflow/addons/issues/1203", strict=True
-)
 @pytest.mark.parametrize("serialize", [True, False])
 def test_custom_cyclical_learning_rate(serialize):
     initial_learning_rate = 0.1
@@ -118,7 +114,6 @@ def test_custom_cyclical_learning_rate(serialize):
     def scale_fn(x):
         return 1 / (5 ** (x * 0.0001))
 
-    step = 0
     custom_cyclical_lr = cyclical_learning_rate.CyclicalLearningRate(
         initial_learning_rate=initial_learning_rate,
         maximal_learning_rate=maximal_learning_rate,
@@ -127,12 +122,42 @@ def scale_fn(x):
     )
     custom_cyclical_lr = _maybe_serialized(custom_cyclical_lr, serialize)
 
-    for i in range(1, 8001):
-        non_bounded_value = np.abs(i / 2000.0 - 2 * np.floor(1 + i / (2 * 2000)) + 1)
+    for step in range(1, 8001):
+        cycle = np.floor(1 + step / (2 * step_size))
+        non_bounded_value = np.abs(step / step_size - 2 * cycle + 1)
         expected = initial_learning_rate + (
             maximal_learning_rate - initial_learning_rate
-        ) * np.maximum(0, 1 - non_bounded_value) * scale_fn(i)
+        ) * np.maximum(0, 1 - non_bounded_value) * scale_fn(cycle)
+        np.testing.assert_allclose(
+            custom_cyclical_lr(step).numpy(), expected, 1e-6, 1e-6
+        )
+
+
+@pytest.mark.parametrize("serialize", [True, False])
+def test_custom_cyclical_learning_rate_with_scale_mode(serialize):
+    initial_learning_rate = 0.1
+    maximal_learning_rate = 1
+    step_size = 4000
+    scale_mode = "iterations"
+
+    def scale_fn(x):
+        return 1 / (5 ** (x * 0.0001))
+
+    custom_cyclical_lr = cyclical_learning_rate.CyclicalLearningRate(
+        initial_learning_rate=initial_learning_rate,
+        maximal_learning_rate=maximal_learning_rate,
+        step_size=step_size,
+        scale_fn=scale_fn,
+        scale_mode=scale_mode,
+    )
+    custom_cyclical_lr = _maybe_serialized(custom_cyclical_lr, serialize)
+
+    for step in range(1, 8001):
+        cycle = np.floor(1 + step / (2 * step_size))
+        non_bounded_value = np.abs(step / step_size - 2 * cycle + 1)
+        expected = initial_learning_rate + (
+            maximal_learning_rate - initial_learning_rate
+        ) * np.maximum(0, 1 - non_bounded_value) * scale_fn(step)
         np.testing.assert_allclose(
             custom_cyclical_lr(step).numpy(), expected, 1e-6, 1e-6
         )
-        step += 1