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

Migrate gelu to core #550

Closed
WindQAQ opened this issue Sep 30, 2019 · 20 comments
Closed

Migrate gelu to core #550

WindQAQ opened this issue Sep 30, 2019 · 20 comments
Assignees

Comments

@WindQAQ
Copy link
Member

WindQAQ commented Sep 30, 2019

Describe the feature and the current behavior/state.

tfa.activations.gelu would be moved to tf.keras.activations.gelu, as well as the CC kernels.

Relevant information

  • Are you willing to contribute it (yes/no): yes
  • Are you willing to maintain it going forward? (yes/no): yes
  • Is there a relevant academic paper? (if so, where): yes
  • Is there already an implementation in another framework? (if so, where): yes, addons
  • Was it part of tf.contrib? (if so, where): no

Which API type would this fall under (layer, metric, optimizer, etc.)
activations

Who will benefit with this feature?
Whole community

Any other info.
As per tensorflow/tensorflow#32783, seems that keras is seeking for gelu activation, and accepts PR.

@WindQAQ
Copy link
Member Author

WindQAQ commented Sep 30, 2019

cc @seanpmorgan and @facaiy.

@facaiy
Copy link
Member

facaiy commented Sep 30, 2019

+@karmel for visibility

@karmel
Copy link
Contributor

karmel commented Oct 1, 2019

Metacomment: @ewilderj / @seanpmorgan -- I wonder if we should start tracking these moves? Seems like it's one interesting metric indicating the utility of Addons.

@ewilderj
Copy link
Contributor

ewilderj commented Oct 1, 2019

+1 I'd be strongly in favor of at least something like a GRADUATED.md doc that kept a list of these with the date they moved. You're right, it's great bragging rights, and also a good piece of documentation for users.

@AakashKumarNain
Copy link
Member

I am happy that finally GeLU is moving to core. @WindQAQ let me know if you need any help in any way

@WindQAQ
Copy link
Member Author

WindQAQ commented Oct 6, 2019

Hi all, my minor concern of this migration is that tfa's gelu is based on C++/CUDA kernel rather than a python function. So I am afraid the PR will not only affect tf.keras.* but also some cc files in tensorflow/core/* as well as tf.nn.*. Is it still okay for us to issue a single PR to cover core and keras part? Thank you all in advance!

@facaiy
Copy link
Member

facaiy commented Oct 8, 2019

Is it still okay for us to issue a single PR to cover core and keras part?

We usually add both c++ and python codes when implementing a new OP. So I think the answer is yes. But I'm a little curious why we write c++ kernel implementation for the activation ops. Those ops looks quite simple, and it seems that they could be composed by tf python ops easily if I'm not wrong.

@WindQAQ
Copy link
Member Author

WindQAQ commented Oct 8, 2019

Is it still okay for us to issue a single PR to cover core and keras part?

We usually add both c++ and python codes when implementing a new OP. So I think the answer is yes. But I'm a little curious why we write c++ kernel implementation for the activation ops. Those ops looks quite simple, and it seems that they could be composed by tf python ops easily if I'm not wrong.

The speed. On my local machine, the C++ kernel speed up 3 times and 10 times in forward and backward pass respectively compared with tf python ops. I know that XLA optimization could somewhat fuse multiple operations into a single kernel, but not all of the users can enjoy XLA on their own machine.

A related talk presented by NVIDIA. gelu's performance test on Colab. Similar issue requesting for prelu's C++ kernel in core TF tensorflow/tensorflow#31883.

@WindQAQ WindQAQ self-assigned this Oct 11, 2019
@facaiy
Copy link
Member

facaiy commented Oct 18, 2019

I agree that C++ implementation should run faster than python implementation, Tzu-Wei. But as the op is so small, I'm not sure whether it is worthy at the cost of maintaining a chunk of code. Moreover, the new op we add might not work well with graph optimization toolkit(say op fusion as you mentained, or TensorRT ect) because those tools might only focus on tf-core. I'm not against c++ implementation, just a little reminder: perhaps we could write c++ implementation or create a fused op later when performance sucks in the mainstream models 😄

@WindQAQ
Copy link
Member Author

WindQAQ commented Oct 18, 2019

Thanks for pointing out! So what should we migrate for this time; a tf python operation implementation only or kernel version? Both are fine with me, but want to have your ideas 😄

@hendrycks
Copy link

hendrycks commented Oct 18, 2019 via email

@WindQAQ
Copy link
Member Author

WindQAQ commented Nov 4, 2019

Hi all, the PR has been created tensorflow/tensorflow#33945.

@AakashKumarNain
Copy link
Member

Hi all, the PR has been created tensorflow/tensorflow#33945.

@WindQAQ Are we going with the Python implementation or with the C++ one?

@WindQAQ
Copy link
Member Author

WindQAQ commented Nov 5, 2019

Hi all, the PR has been created tensorflow/tensorflow#33945.

@WindQAQ Are we going with the Python implementation or with the C++ one?

I use C++ implementation :D

@bhack
Copy link
Contributor

bhack commented Nov 8, 2019

+1 I'd be strongly in favor of at least something like a GRADUATED.md doc that kept a list of these with the date they moved. You're right, it's great bragging rights, and also a good piece of documentation for users.

Yes but the main issue Is the we always need to check in multiple places:
keras-team/keras#11834
keras-team/keras#12020
keras-team/keras#11835
keras-team/keras#11839

We need to find a solution for Keras repo other then contrib vs addon:
keras-team/keras-contrib#519

@seanpmorgan
Copy link
Member

During the monthly call it was determined that the best way to move this forward is to create a Keras RFC per our new procedure:
https://github.com/tensorflow/addons/blob/master/MIGRATION_TO_CORE.md

The goal is to propose the custom op along with the accompanying performance tests. In the "alternatives considered" we can propose the python composite op for discussion.

@WindQAQ When time allows would you be able to author this RFC? I can help out as well.

@WindQAQ
Copy link
Member Author

WindQAQ commented Jan 14, 2020

The goal is to propose the custom op along with the accompanying performance tests. In the "alternatives considered" we can propose the python composite op for discussion.

@WindQAQ When time allows would you be able to author this RFC? I can help out as well.

Of course!

@AakashKumarNain
Copy link
Member

Lemme know if you guys need any help. I would be more than happy to help

@bhack
Copy link
Contributor

bhack commented Mar 7, 2020

@seanpmorgan

The goal is to propose the custom op along with the accompanying performance tests. In the "alternatives considered" we can propose the python composite op for discussion.
Also probably there is an impact with evolving MLIR compiler stack ecosystem about the codegen path vs c++ implemented in custom ops.

@seanpmorgan
Copy link
Member

Closing as this will be finished up in #2005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants