-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
TF_Deberta supporting mixed precision #32618
TF_Deberta supporting mixed precision #32618
Conversation
Corrected some codes which do not support mixed precision
Corrected some codes which do not support mixed precision
Hi @pinesnow72, this looks good! Feel free to ping me whenever it's ready for review. The issues with code quality can be fixed by doing |
Hi @Rocketknight1, As your comment, the style was corrected and uploaded. Thanks. |
LGTM now! cc @amyeroberts for core maintainer review, and thanks for the PR! |
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.
Thanks for opening a PR to handle this!
Just a small question
@@ -701,9 +701,9 @@ def linear(w, b, x): | |||
ws = tf.split( | |||
tf.transpose(self.in_proj.weight[0]), num_or_size_splits=self.num_attention_heads * 3, axis=0 | |||
) | |||
qkvw = tf.TensorArray(dtype=tf.float32, size=3) | |||
qkvw = tf.TensorArray(dtype=self.dtype, size=3) |
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.
What's the difference between self.dtype
and self.compute_dtype
?
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.
self.dtype
is the dtype the layer's weights are stored in, self.compute_dtype
is the dtype used for computation. By default these are the same, but in mixed-precision it's common for self.dtype
to be float32
while self.compute_dtype
is (b)float16
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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.
Thanks for making mixed precision possible for this model!
Thanks for accepting this PR |
What does this PR do?
This PR fixes some codes of TF DeBERTa (version 1 and 2) that do not support Mixed Precision.
With TF and Keras, mixed precision is configured with the following settings:
However, the existing TFDebertaModel and TFDebertaV2Model throws TypeError with this mixed precision setting.
With mixed precision, TF and Keras requires to use Layer.dtype for model or layer's weights and Layer.compute_dtype for internal tensor computation. But the current TFDebertaModel and TFDebertaV2Model codes do not seem to reflect this requirement and definitely assume the dtype would be tf.float32.
I searched and corrected some error-prone code snippets in modeling_tf_deberta.py and modeling_tf_deberta_v2.py.
This correction worked correctly with mixed precision in my local machine.
This PR fixes #31989
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@Rocketknight1, @ArthurZucker