Skip to content

Add tanhshrink #493

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

Merged
merged 9 commits into from
Sep 19, 2019
Merged

Add tanhshrink #493

merged 9 commits into from
Sep 19, 2019

Conversation

fsx950223
Copy link
Member

Related #437


@keras_utils.register_keras_custom_object
@tf.function
def tanhshrink(features, name="Tanhshrink"):
Copy link
Member

Choose a reason for hiding this comment

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

Seems that I missed the name argument in my previous PRs. @facaiy @seanpmorgan Should we strictly follow this? Like activations in tf.keras.activations.*, they do not expose name argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe the name argument is important for debugging.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the delay, I have no objection, however I prefer to keep consistency with keras module. name often conflicts with arguments backward compatibility, and it won't hurt to add it in the future. What do you think, @fsx950223 , @WindQAQ Tzu-Wei?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for the delay, I have no objection, however I prefer to keep consistency with keras module. name often conflicts with arguments backward compatibility, and it won't hurt to add it in the future. What do you think, @fsx950223 , @WindQAQ Tzu-Wei?

I opened an issue #505. We can discuss in the issue

Copy link
Member

@WindQAQ WindQAQ left a comment

Choose a reason for hiding this comment

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

@fsx950223 Hello, I drop some comments here. Feel free to ping me if you have further problem.

@fsx950223
Copy link
Member Author

@fsx950223 Hello, I drop some comments here. Feel free to ping me if you have further problem.

Keras api is based on tensorflow.nn api. Maybe we should define keras api and custom op api separately.

@WindQAQ
Copy link
Member

WindQAQ commented Sep 13, 2019

Keras api is based on tensorflow.nn api. Maybe we should define keras api and custom op api separately.

We have discussed this previously #426. But you could still open a new issue or re-use the old one for further discussion.

@fsx950223
Copy link
Member Author

fsx950223 commented Sep 13, 2019

Keras api is based on tensorflow.nn api. Maybe we should define keras api and custom op api separately.

We have discussed this previously #426. But you could still open a new issue or re-use the old one for further discussion.

I agree with the final discussion result. But we should follow tensorflow.nn.* apis' style.
Official example just use tensorflow.nn.* for now.

@fsx950223 fsx950223 mentioned this pull request Sep 13, 2019
@WindQAQ
Copy link
Member

WindQAQ commented Sep 18, 2019

Hi @fsx950223, as a side note, don't forget to follow the namespace change as per #516.

@fsx950223
Copy link
Member Author

fsx950223 commented Sep 18, 2019

tensorflow.python.framework.errors_impl.InvalidArgumentError: Invalid name: Addons>Tanhshrink (Did you use CamelCase?); in OpDef: name: "Addons>Tanhshrink" input_arg { name: "features" type_attr: "T" } output_arg { name: "activations" type_attr: "T" } attr { name: "T" type: "type" allowed_values { list { type: DT_HALF type: DT_FLOAT type: DT_DOUBLE } } }

Why? Any other changes?

Copy link
Member

@WindQAQ WindQAQ left a comment

Choose a reason for hiding this comment

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

The error you mentioned above is probably because you do not use the latest nightly tensorflow. Try to install tf-nightly-gpu-2.0-preview. Also, I drop some comments below, please check it out. Thanks for the contribution.


Args:
features: A `Tensor`. Must be one of the following types:
`float16`, `float32`, `float64`, `int32`, `int64`.
Copy link
Member

Choose a reason for hiding this comment

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

Remove int32 and int64.


#undef EIGEN_USE_THREADS

#endif
Copy link
Member

Choose a reason for hiding this comment

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

#endif // TENSORFLOW_ADDONS_ACTIVATIONS_KERNELS_TANHSHRINK_OP_H_

// INPUTS:
// g (gradients): backpropagated gradients
// a (inputs): either the inputs that were passed to TanhshrinkOp(), or its
// outputs (using either one yields the same result here).
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 in your implementation a (inputs) should be the inputs that were passed to TanhshrinkOp() instead of its outputs, which will not yield the same result.

@facaiy
Copy link
Member

facaiy commented Sep 18, 2019

Try to install tf-nightly-gpu-2.0-preview.

+1, please try to upgrade tf

@fsx950223
Copy link
Member Author

Fixed. @WindQAQ

Copy link
Member

@WindQAQ WindQAQ left a comment

Choose a reason for hiding this comment

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

Want to check the last thing :-) Thanks.

@fsx950223
Copy link
Member Author

Want to check the last thing :-) Thanks.

Please review again.

Copy link
Member

@WindQAQ WindQAQ left a comment

Choose a reason for hiding this comment

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

Thanks!

@WindQAQ WindQAQ merged commit 33baec0 into tensorflow:master Sep 19, 2019
@WindQAQ WindQAQ mentioned this pull request Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants