-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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: XLA stable softmax #16892
TF: XLA stable softmax #16892
Conversation
The documentation is not available anymore as the PR was closed or merged. |
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.
Great find for the bug and thanks a lot for fixing all models!
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
xla_out = xla_masked_softmax(x, boolean_mask) | ||
out = masked_softmax(x, boolean_mask) | ||
assert tf.experimental.numpy.allclose(xla_out, out) | ||
|
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.
Could we have a test for bacth_size > 1 ?
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.
Added batch size > 1 👍
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.
Good for me, just left 2 nits.
(didn't check the changes in TFGPT2, TFT5 tests though. Let me know if you prefer me to check those too.)
Thank you, @gante 💯
This looks good to me! Do you think it would be better to change |
Good point! Hope this won't affect tests on GPU (at least not for PT/TF equivalence which use |
@Rocketknight1 @ydshieh if you run the test and print the difference between |
@gante With this, do we still have issues regarding sampling in |
@ydshieh after this fix, the errors related to |
(I might be completely wrong below) I could imagine that we (will) have tests like:
Thanks 🙏 |
OK, I saw your previous comment
|
Based on the testing results, I'm happy for this to be merged now! If this is an XLA bug, though, we should make sure to revert our changes once none of the TF versions we support are affected by it anymore. Should we add a TODO to the |
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.
Great - the solution is clean!
@Rocketknight1 added a TODO with instructions related to when to deprecate 👍 |
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
What does this PR do?
As discussed in the thread about XLA problems (#16838), this PR adds a stable wrapper for the softmax operation, and replaces
tf.nn.softmax
by the wrapped function.This PR:
stable_softmax
, intf_utils.py
. Its docstring includes why it is needed and why the new operation is valid;tf.nn.softmax
bystable_softmax
everywhere except in the doctests (I think it overcomplicates the examples, and no XLA should be needed there);skipIf
for XLA tests, as they can now be successfully executed in a CPU.Closes #16838