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 apply() API change in TF 2.9 for unit tests #3427
Conversation
TF 2.9 removed apply() API, use __call__() instead. Signed-off-by: Chongxiao Cao <chongxiaoc@uber.com>
be8e22a
to
72572ce
Compare
Unit Test Results (with flaky tests) 877 files + 10 877 suites +10 9h 41m 8s ⏱️ - 17m 0s For more details on these failures, see this check. Results for commit 72572ce. ± Comparison against base commit 642a6b3. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code could be simplified. I think this improves readability.
bn_func = bn.apply(x, training=True) if LooseVersion( | ||
tf.__version__) < LooseVersion('2.9.0') else bn(x, training=True) | ||
sync_bn_func = sync_bn.apply(tf.expand_dims(x[hvd.rank()], 0), training=True) if LooseVersion( | ||
tf.__version__) < LooseVersion('2.9.0') else sync_bn(tf.expand_dims(x[hvd.rank()], 0), training=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code could be simplified as follows:
bn_func = bn.apply(x, training=True) if LooseVersion( | |
tf.__version__) < LooseVersion('2.9.0') else bn(x, training=True) | |
sync_bn_func = sync_bn.apply(tf.expand_dims(x[hvd.rank()], 0), training=True) if LooseVersion( | |
tf.__version__) < LooseVersion('2.9.0') else sync_bn(tf.expand_dims(x[hvd.rank()], 0), training=True) | |
if LooseVersion(tf.__version__) < LooseVersion('2.9.0'): | |
bn = bn.apply | |
sync_bn = sync_bn.apply | |
bn_func = bn(x, training=True) | |
sync_bn_func = sync_bn(tf.expand_dims(x[hvd.rank()], 0), training=True) |
sync_bn_func = sync_bn.apply(tf.expand_dims(x[hvd.rank()], 0), training=True) | ||
# apply() API is removed in TF 2.9.0 | ||
bn_func = bn.apply(x, training=True) if LooseVersion( | ||
tf.__version__) < LooseVersion('2.9.0') else bn(x, training=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need the version check since __ call __ is by default always there in keras.layers.
Didn't realize you were working on the same failure. I also opened one to fix all head failures. But feel free to merge this in after addressing the comments. |
@chongxiaoc in that case, I would prefer the call approach for any tensorflow version as in #3431. You can do this here and we merge #3431 afterwards. |
close due to duplication with #3431 |
TF 2.9 removed apply() API, use call() instead.
Signed-off-by: Chongxiao Cao chongxiaoc@uber.com
Checklist before submitting
Description
Fixes #3422 .
Review process to land