From 7b2ded24ace6f771a62c93134bc7b58325e6867e Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Thu, 31 Jan 2019 15:37:14 -0800 Subject: [PATCH] Exposes some experimental learning rate schedules added to TF 2.0 in TF 1.x. PiperOrigin-RevId: 231867881 --- .../optimizer_v2/learning_rate_schedule.py | 9 +++------ ...s.experimental.-cosine-decay-restarts.pbtxt | 18 ++++++++++++++++++ ...ras.experimental.-linear-cosine-decay.pbtxt | 18 ++++++++++++++++++ ...perimental.-noisy-linear-cosine-decay.pbtxt | 18 ++++++++++++++++++ .../v1/tensorflow.keras.experimental.pbtxt | 12 ++++++++++++ .../tools/compatibility/tf_upgrade_v2.py | 8 ++------ .../tools/compatibility/tf_upgrade_v2_test.py | 3 ++- 7 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.-cosine-decay-restarts.pbtxt create mode 100644 tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.-linear-cosine-decay.pbtxt create mode 100644 tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.-noisy-linear-cosine-decay.pbtxt diff --git a/tensorflow/python/keras/optimizer_v2/learning_rate_schedule.py b/tensorflow/python/keras/optimizer_v2/learning_rate_schedule.py index a182d74e56e..c44263bdcf2 100644 --- a/tensorflow/python/keras/optimizer_v2/learning_rate_schedule.py +++ b/tensorflow/python/keras/optimizer_v2/learning_rate_schedule.py @@ -631,8 +631,7 @@ class CosineDecay(LearningRateSchedule): } -@keras_export("keras.experimental.CosineDecayRestarts", - v1=[]) +@keras_export("keras.experimental.CosineDecayRestarts") class CosineDecayRestarts(LearningRateSchedule): """A LearningRateSchedule that uses a cosine decay schedule with restarts.""" @@ -761,8 +760,7 @@ class CosineDecayRestarts(LearningRateSchedule): } -@keras_export("keras.experimental.LinearCosineDecay", - v1=[]) +@keras_export("keras.experimental.LinearCosineDecay") class LinearCosineDecay(LearningRateSchedule): """A LearningRateSchedule that uses a linear cosine decay schedule.""" @@ -879,8 +877,7 @@ class LinearCosineDecay(LearningRateSchedule): } -@keras_export("keras.experimental.NoisyLinearCosineDecay", - v1=[]) +@keras_export("keras.experimental.NoisyLinearCosineDecay") class NoisyLinearCosineDecay(LearningRateSchedule): """A LearningRateSchedule that uses a noisy linear cosine decay schedule.""" diff --git a/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.-cosine-decay-restarts.pbtxt b/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.-cosine-decay-restarts.pbtxt new file mode 100644 index 00000000000..58bede556df --- /dev/null +++ b/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.-cosine-decay-restarts.pbtxt @@ -0,0 +1,18 @@ +path: "tensorflow.keras.experimental.CosineDecayRestarts" +tf_class { + is_instance: "" + is_instance: "" + is_instance: "" + member_method { + name: "__init__" + argspec: "args=[\'self\', \'initial_learning_rate\', \'first_decay_steps\', \'t_mul\', \'m_mul\', \'alpha\', \'name\'], varargs=None, keywords=None, defaults=[\'2.0\', \'1.0\', \'0.0\', \'None\'], " + } + member_method { + name: "from_config" + argspec: "args=[\'cls\', \'config\'], varargs=None, keywords=None, defaults=None" + } + member_method { + name: "get_config" + argspec: "args=[\'self\'], varargs=None, keywords=None, defaults=None" + } +} diff --git a/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.-linear-cosine-decay.pbtxt b/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.-linear-cosine-decay.pbtxt new file mode 100644 index 00000000000..f083120b52c --- /dev/null +++ b/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.-linear-cosine-decay.pbtxt @@ -0,0 +1,18 @@ +path: "tensorflow.keras.experimental.LinearCosineDecay" +tf_class { + is_instance: "" + is_instance: "" + is_instance: "" + member_method { + name: "__init__" + argspec: "args=[\'self\', \'initial_learning_rate\', \'decay_steps\', \'num_periods\', \'alpha\', \'beta\', \'name\'], varargs=None, keywords=None, defaults=[\'0.5\', \'0.0\', \'0.001\', \'None\'], " + } + member_method { + name: "from_config" + argspec: "args=[\'cls\', \'config\'], varargs=None, keywords=None, defaults=None" + } + member_method { + name: "get_config" + argspec: "args=[\'self\'], varargs=None, keywords=None, defaults=None" + } +} diff --git a/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.-noisy-linear-cosine-decay.pbtxt b/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.-noisy-linear-cosine-decay.pbtxt new file mode 100644 index 00000000000..8ea3c6beb1c --- /dev/null +++ b/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.-noisy-linear-cosine-decay.pbtxt @@ -0,0 +1,18 @@ +path: "tensorflow.keras.experimental.NoisyLinearCosineDecay" +tf_class { + is_instance: "" + is_instance: "" + is_instance: "" + member_method { + name: "__init__" + argspec: "args=[\'self\', \'initial_learning_rate\', \'decay_steps\', \'initial_variance\', \'variance_decay\', \'num_periods\', \'alpha\', \'beta\', \'name\'], varargs=None, keywords=None, defaults=[\'1.0\', \'0.55\', \'0.5\', \'0.0\', \'0.001\', \'None\'], " + } + member_method { + name: "from_config" + argspec: "args=[\'cls\', \'config\'], varargs=None, keywords=None, defaults=None" + } + member_method { + name: "get_config" + argspec: "args=[\'self\'], varargs=None, keywords=None, defaults=None" + } +} diff --git a/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.pbtxt b/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.pbtxt index 24684b9f4d4..721c18890ac 100644 --- a/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.pbtxt +++ b/tensorflow/tools/api/golden/v1/tensorflow.keras.experimental.pbtxt @@ -4,6 +4,18 @@ tf_module { name: "CosineDecay" mtype: "" } + member { + name: "CosineDecayRestarts" + mtype: "" + } + member { + name: "LinearCosineDecay" + mtype: "" + } + member { + name: "NoisyLinearCosineDecay" + mtype: "" + } member { name: "PeepholeLSTMCell" mtype: "" diff --git a/tensorflow/tools/compatibility/tf_upgrade_v2.py b/tensorflow/tools/compatibility/tf_upgrade_v2.py index 11ac70df0ad..85ece0313f0 100644 --- a/tensorflow/tools/compatibility/tf_upgrade_v2.py +++ b/tensorflow/tools/compatibility/tf_upgrade_v2.py @@ -827,12 +827,8 @@ class TFAPIChangeSpec(ast_edits.APIChangeSpec): decay_function_comment = ( ast_edits.INFO, - " has been changed to return a callable instead " - "of a tensor when graph building, but its functionality remains " - "unchanged during eager execution (returns a callable like " - "before). The converter cannot detect and fix this reliably, so " - "this usage has been converted to compat.v1 (even though it may already" - " be correct).\n" + "To use learning rate decay schedules with TensorFlow 2.0, switch to " + "the schedules in `tf.keras.optimizers.schedules`.\n" ) assert_return_type_comment = ( diff --git a/tensorflow/tools/compatibility/tf_upgrade_v2_test.py b/tensorflow/tools/compatibility/tf_upgrade_v2_test.py index bbe074e242b..11ed634ed42 100644 --- a/tensorflow/tools/compatibility/tf_upgrade_v2_test.py +++ b/tensorflow/tools/compatibility/tf_upgrade_v2_test.py @@ -409,7 +409,8 @@ bazel-bin/tensorflow/tools/compatibility/update/generate_v2_reorders_map text = "%s(a, b)\n" % decay _, report, unused_errors, _ = self._upgrade(text) - self.assertIn("%s has been changed to return a callable" % decay, report) + self.assertIn("switch to the schedules in " + "`tf.keras.optimizers.schedules`", report) def testMetrics(self): metrics = [