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
Simplify tf.keras.activations.softmax codepath #47012
Simplify tf.keras.activations.softmax codepath #47012
Conversation
@@ -31,10 +31,10 @@ | |||
from tensorflow.python.platform import test | |||
|
|||
|
|||
def _ref_softmax(values): | |||
m = np.max(values) | |||
def _ref_softmax(values, axis=-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.
I think you can skip axis since its never changed by the caller.
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.
Sure let me modify it real quick.
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.
Done 😃
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 the fix and sorry for the late reply. Just a nit about the test.
Hum, it seems that this PR gets rolled back since it breaks one of the internal test. Let me take a look and fix forward. |
Fixes #35199 although TFLite has already optimized that pattern into single softmax op. Since
tf.nn.softmax
supports input of any rank, there is no reason to have other implementations. For common 3D input withaxis=-1
,tf.nn.softmax
is also faster than original implementation.https://colab.research.google.com/drive/1E1rS69LJ7e-pH4bcyfxEJ_wC6IiRISvS?usp=sharing