Skip to content

[TF-TRT] Add LogSoftmax Support for TF-TRT - #57013

Closed
pavanimajety wants to merge 1 commit into
tensorflow:masterfrom
pavanimajety:logsoftmax
Closed

pavanimajety wants to merge 1 commit into
tensorflow:masterfrom
pavanimajety:logsoftmax

Conversation

@pavanimajety

@pavanimajety pavanimajety commented Aug 4, 2022 •

Copy link
Copy Markdown
Contributor

This PR adds TF-TRT support to tf.nn.log_softmax operation. This is performed using the formula logsoftmax = logits - log(reduce_sum(exp(logits), axis=-1)) . The implemented TRT layers are fused into a single op.

@DEKHTIARJonathan @tfeher : Please review the changes.

@google-ml-butler google-ml-butler Bot added the size:M CL Change Size: Medium label Aug 4, 2022
@google-ml-butler
google-ml-butler Bot requested a review from bixia1 August 4, 2022 21:27
@google-ml-butler google-ml-butler Bot added the awaiting review Pull request awaiting review label Aug 4, 2022

@tfeher tfeher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi Pavani, thank you for the PR, it looks great overall! But for new converters we prefer to derive them from OpConverterBase, I have left instructions on how to update.

if (params->validation_only) return Status::OK();

// Perform LogSoftmax operation -
// logsoftmax = logits - log(reduce_sum(exp(logits), axis))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason to prefer this formulation over log(softmax(logits))?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I chose this way because tensorflow implements in Python using logsoftmax = logits - log(reduce_sum(exp(logits), axis)) .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As clarified offline, TRT shall fuse both formulations, therefore it looks fine.

@gbaned gbaned removed the awaiting review Pull request awaiting review label Aug 8, 2022

@tfeher tfeher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @pavanimajety for refactoring the converter, the PR looks good to me!

@google-ml-butler google-ml-butler Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Aug 9, 2022
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Aug 9, 2022
@bixia1

bixia1 commented Aug 9, 2022

Copy link
Copy Markdown
Contributor

@pavanimajety Please add a PR description.

@bixia1 bixia1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me, just request fix to comment style and a PR description.

// Perform LogSoftmax operation -
// logsoftmax = logits - log(reduce_sum(exp(logits), axis))

// get the logits tensor

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A comment usually starts with a capital letter and ends with a period, see the examples here.

Can you fix here and other place in this file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed the comments.

@google-ml-butler google-ml-butler Bot removed the ready to pull PR ready for merge process label Aug 10, 2022
@pavanimajety
pavanimajety marked this pull request as ready for review August 10, 2022 02:31

@bixia1 bixia1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me now. Would you please squash the commits?

Fix Softmax comments


[TF-TRT] Move LogSoftmax to use OpConverterBase


Fix compiler errors


clang-format

Undo changes to convert_nodes.cc


Fix comments
@pavanimajety

Copy link
Copy Markdown
Contributor Author

Looks good to me now. Would you please squash the commits?

Done. Thanks for reviewing

@google-ml-butler google-ml-butler Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Aug 10, 2022
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Aug 10, 2022
@google-ml-butler google-ml-butler Bot removed the ready to pull PR ready for merge process label Aug 10, 2022
@gbaned gbaned added the ready to pull PR ready for merge process label Aug 11, 2022
@pavanimajety
pavanimajety requested a review from penpornk as a code owner August 12, 2022 18:06
@google-ml-butler google-ml-butler Bot added awaiting review Pull request awaiting review and removed ready to pull PR ready for merge process labels Aug 12, 2022
@pavanimajety

Copy link
Copy Markdown
Contributor Author

Sorry, rebased for further work by mistake.

@bixia1

bixia1 commented Aug 12, 2022

Copy link
Copy Markdown
Contributor

This is merged, wonder why it doesn't show as merged here.

@pavanimajety

Copy link
Copy Markdown
Contributor Author

This is merged, wonder why it doesn't show as merged here.

Would you mind checking again? I don't see in tensorflow:master : https://github.com/tensorflow/tensorflow/tree/master/tensorflow/compiler/tf2tensorrt/convert/ops

@google-ml-butler google-ml-butler Bot removed the awaiting review Pull request awaiting review label Aug 13, 2022
@mihaimaruseac

Copy link
Copy Markdown
Contributor

It did not show as merged here because copybara sync was broken. Fixed in big squash commit 49f97f1

@pavanimajety
pavanimajety deleted the logsoftmax branch September 22, 2022 15:51
trevor-m pushed a commit to trevor-m/tensorflow that referenced this pull request Oct 20, 2022
Fix Softmax comments


[TF-TRT] Move LogSoftmax to use OpConverterBase


Fix compiler errors


clang-format

Undo changes to convert_nodes.cc


Fix comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M CL Change Size: Medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants