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

Simplify tf.keras.activations.softmax codepath #47012

Conversation

WindQAQ
Copy link
Member

@WindQAQ WindQAQ commented Feb 8, 2021

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 with axis=-1, tf.nn.softmax is also faster than original implementation.

https://colab.research.google.com/drive/1E1rS69LJ7e-pH4bcyfxEJ_wC6IiRISvS?usp=sharing

@google-ml-butler google-ml-butler bot added the size:M CL Change Size: Medium label Feb 8, 2021
@google-cla google-cla bot added the cla: yes label Feb 8, 2021
@gbaned gbaned self-assigned this Feb 9, 2021
@gbaned gbaned added comp:keras Keras related issues prtype:bugfix PR to fix a bug labels Feb 9, 2021
@gbaned gbaned added this to Assigned Reviewer in PR Queue via automation Feb 9, 2021
@gbaned gbaned self-requested a review February 9, 2021 04:35
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Feb 12, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Feb 12, 2021
@gbaned gbaned removed the ready to pull PR ready for merge process label Feb 12, 2021
@gbaned gbaned added the awaiting review Pull request awaiting review label Feb 16, 2021
@@ -31,10 +31,10 @@
from tensorflow.python.platform import test


def _ref_softmax(values):
m = np.max(values)
def _ref_softmax(values, axis=-1):
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done 😃

Copy link
Member

@qlzh727 qlzh727 left a 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.

PR Queue automation moved this from Assigned Reviewer to Approved by Reviewer Mar 1, 2021
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Mar 1, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 1, 2021
@google-ml-butler google-ml-butler bot removed the ready to pull PR ready for merge process label Mar 1, 2021
@WindQAQ WindQAQ requested a review from qlzh727 March 1, 2021 22:29
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Mar 3, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 3, 2021
@gbaned gbaned removed the awaiting review Pull request awaiting review label Mar 4, 2021
@gbaned gbaned removed the ready to pull PR ready for merge process label Mar 5, 2021
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Mar 5, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 5, 2021
@copybara-service copybara-service bot merged commit ed1b641 into tensorflow:master Mar 5, 2021
PR Queue automation moved this from Approved by Reviewer to Merged Mar 5, 2021
@qlzh727
Copy link
Member

qlzh727 commented Mar 5, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes comp:keras Keras related issues prtype:bugfix PR to fix a bug ready to pull PR ready for merge process size:M CL Change Size: Medium
Projects
PR Queue
  
Merged
Development

Successfully merging this pull request may close these issues.

Softmax activations don't get converted to Softmax TFLite operator if ndim > 2
5 participants