[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in CLR optimizer callback #2172

Merged
merged 2 commits into from
Sep 25, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Attempt to fix unit test failure
  • Loading branch information
DavidWAbrahams committed Sep 22, 2020
commit 646b97f65cc2e103982e2461cd6c4a5ea617d50e
6 changes: 3 additions & 3 deletions tensorflow_addons/optimizers/cyclical_learning_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def __call__(self, step):
dtype = initial_learning_rate.dtype
maximal_learning_rate = tf.cast(self.maximal_learning_rate, dtype)
step_size = tf.cast(self.step_size, dtype)
step = tf.cast(step, dtype)
cycle = tf.floor(1 + step / (2 * step_size))
x = tf.abs(step / step_size - 2 * cycle + 1)
step_as_dtype = tf.cast(step, dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

step = tf.cast(step, dtype)

This should conform to the naming convention in this script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was also my instinct, but it causes a unit test failure. ("step" is accessed later in the method and is expected to still have the original dtype)

I could do this without a local variable, just using "tf.cast(step, dtype)" where needed. Would that be better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavidWAbrahams Thanks for clarification. Your approach is better.

Can you also share the minimal runnable code snippet to reproduce original issue? Thank you!

Copy link
Contributor Author
@DavidWAbrahams DavidWAbrahams Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's my minimal repro. It only triggers when I have added a TensorBoard callback. I guess that callback is somehow clobbering the dtype of "step".

https://pastebin.com/Ni2dgDgh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For more detail, my versions are
tf-nightly-gpu 2.4.0.dev20200917
tfa-nightly 0.12.0.dev20200918223509
tb-nightly 2.4.0a20200921

cycle = tf.floor(1 + step_as_dtype / (2 * step_size))
x = tf.abs(step_as_dtype / step_size - 2 * cycle + 1)

mode_step = cycle if self.scale_mode == "cycle" else step

Expand Down