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 mixed precision in TF models #9163

Merged
merged 10 commits into from Jan 21, 2021
Merged

Conversation

jplu
Copy link
Contributor

@jplu jplu commented Dec 17, 2020

What does this PR do?

This PR aims to fix the mixed precision issues when tf.keras.mixed_precision.experimental.set_policy() is set to something else than tf.float32. In the same page, this PR aims to fix some TFLite quantization issues.

Before to further continue this PR, the PR #9418 has to be merged.

Fixes # (issue)

#7052

@@ -56,14 +57,20 @@ def mish(x):

def gelu_fast(x):
x = tf.convert_to_tensor(x)
coeff1 = tf.cast(7978845608, x.dtype)
coeff1 = tf.cast(0.7978845608, x.dtype)
Copy link
Contributor

Choose a reason for hiding this comment

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

wow was that wrong the whole time before?

Copy link
Contributor Author

@jplu jplu Jan 20, 2021

Choose a reason for hiding this comment

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

Yep! I was as surprised as you 😄

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for fixing this!

Comment on lines 66 to 74
if version.parse(tf.version.VERSION) >= version.parse("2.4"):
gelu = tf.keras.activations.gelu
else:
gelu = tf.keras.layers.Activation(_gelu)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice to be able to use the TF version now!

@LysandreJik LysandreJik merged commit 3f290e6 into huggingface:master Jan 21, 2021
@jplu jplu deleted the fix-activations branch January 21, 2021 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants