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

frontends.tensorflow.activations: add support for elu and selu #5400

Merged
merged 7 commits into from
Oct 16, 2022
Merged

frontends.tensorflow.activations: add support for elu and selu #5400

merged 7 commits into from
Oct 16, 2022

Conversation

hmahmood24
Copy link
Contributor

Close #5387
Close #5388

@ivy-leaves ivy-leaves added the TensorFlow Frontend Developing the TensorFlow Frontend, checklist triggered by commenting add_frontend_checklist label Oct 7, 2022
@YushaArif99
Copy link
Contributor

@hmahmood24, the tests for selu activation function seem to be failing. Kindly refer to the test-frontend-tensorflow tests to see the failing test cases and resolve them accordingly.

@hmahmood24
Copy link
Contributor Author

Hi @YushaArif99,

Thanks for the response. I have looked into the points you made and here is what I think:

  • The support for adding a dictionary to define supported or unsupported dtypes for a particular function has been removed from Ivy. The link you shared also has no information whatsoever regarding adding dictionaries, but only regarding adding tuples. You can verify that yourself. Yes, one can add version-specific supported and unsupported dtypes but not for the following scenario.

  • For my implementation (and hopefully many others), adding supported or unsupported dtypes in the form of a dictionary seems a lot more usable. Here is why: tensorflow supports float16, float32, float64 in selu method which internally calls the elu method which again calls the ivy.exp method which however is not defined for a float16 dtype when using a torch backend.

  • Now, even though this has been flagged for in the backend exp method for torch, during my testing, Hypothesis still keeps generating a float16 dtype, thereby causing the tests to fail (I have verified this myself). Intuitively, it makes a lot more sense that this could be tagged in the frontend function selu.supported_dtypes like so: { ... "tensorflow": ( "float16", "float32", "float64", ), "torch": ( "float32", "float64", ), ... }

  • However, when I try to go and define a dictionary like above, I get the following error thrown at the time of testing: ivy.exceptions.IvyBackendException: numpy: function_unsupported_dtypes: type of x: <class 'dict'> must be one of the allowed types: <class 'tuple'>. Seems like only tuples are supported when flagging supported or unsupported dtypes for a function as seen from this block of code in the master branch.

  • Thus, there is a need to add support for defining dictionaries (along with tuples as previously) to flag the supported or unsupported dtypes of a function accordingly. I have committed the solution to the same in the latest commits to this forked branch. I have also verified that this does not break any of the tests where tuples are used to flag the supported or unsupported dtypes. This commit, thus, only adds the support of flagging using dicts along with tuples.

  • I have verified that with this definition of supported or unsupported dtypes, all the tests for the selu method pass without any errors against all the backends.

Looking forward to a review from you. Thanks! 😊

@ivy-leaves ivy-leaves added Ivy Functional API Function Reformatting Reformat all Ivy functions in accordance with the latest coding style in the contributor guide labels Oct 10, 2022
@YushaArif99
Copy link
Contributor

Hi @hmahmood24

Thanks a lot for the detailed response! Although the points you've highlighted make complete sense, It is odd that you had to modify the data_type.py file to define the supported_dtype attribute in the form of a dictionary. From my understanding, this should be allowed by default as is the case here:
https://github.com/unifyai/ivy/blob/6089953297b438c58caa71c058ed1599f40a270c/ivy/functional/frontends/tensorflow/math.py#L161

Perhaps it was caused by the latest commit that was made which changed the implementation of the supported_dtype and unsupported_dtype helper functions (6c5975a).

Although your change does seem logical, It might cause some unwanted bugs elsewhere which is why I'll request someone else in the team to review the changes as well just to be safe.

Other than that, everything seems fine and the PR is ready to be merged.

@YushaArif99
Copy link
Contributor

@sherry30 could you kindly take a look at this PR and ensure that everything is ready to be merged?

@hmahmood24
Copy link
Contributor Author

Thanks for the apt response @YushaArif99!
The function you quoted seems to have changed in the current master branch and the dictionary has now been removed from that

Copy link
Contributor

@YushaArif99 YushaArif99 left a comment

Choose a reason for hiding this comment

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

Hi @hmahmood24
Sorry for the late-than-usual reply. Was swamped with work so reviewing this PR completely slipped under my radar.
Given that I still haven't gotten a review from @sherry30, It's better to approve your changes and merge the PR rather than keep you waiting. The removal of the einops condition from the data_type.py seems logical to me and I'm honestly not sure why that condition was there in the first place 😅.
Could you kindly resolve the merge conflicts so that the PR is ready to be merged?

@YushaArif99 YushaArif99 removed the request for review from sherry30 October 14, 2022 06:05
@hmahmood24
Copy link
Contributor Author

Hi @YushaArif99,

It's alright. I can understand. Thanks for responding to my commits. I have made the changes you requested and additionally merged the conflicts with the master branch so that the PR can be merged accordingly. Let me know if there is anything else from my end. Thanks! 😊

@YushaArif99
Copy link
Contributor

@hmahmood24 Thanks for making the changes. I will now merge the PR.
Thanks a lot for your contribution to the Ivy codebase😊

@YushaArif99 YushaArif99 merged commit df4a916 into ivy-llc:master Oct 16, 2022
Aarsh2001 added a commit that referenced this pull request Oct 20, 2022
* ivy.Container namedtuple repr

* adding in the requested changes

* Added TruncateDiv to raw_ops (#5415)

Co-authored-by: Saeed Ashraf <[email protected]>

* adding in the requested changes

* added tan to torch frontend and tested (#5640)

Co-authored-by: jkeane508 <[email protected]>

* fix concat + tensorflow out type hints

* condition 2 satisfied'

* fixed firstlayersiren overflow with safety factor

* fixed FirstLayerSiren test (safety factor)

* firstLayerSiren safety factor log mode

* Adding Container Tests

* frontends.tensorflow.activations: add support for elu and selu (#5400)

* frontends.tensorflow.activations: add support for elu and selu

* frontends.tf.activations: fix dtypes for elu and selu

* frontends.tf.activations: cast to dtypes

* frontends: add support for flagging dict-based dtypes

* update test_activations to reflect namespace changes

Co-authored-by: Yusha Arif <[email protected]>
                            Haris Mahmood <[email protected]>

* add backticks to docstrings

* adding in the requested changes

* adding in the requested changes

* shape refactor

Co-authored-by: Kareem Morsy <[email protected]>
Co-authored-by: Saeed Ashraf <[email protected]>
Co-authored-by: PaoloCatti <[email protected]>
Co-authored-by: jkeane508 <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Oliver Toh <[email protected]>
Co-authored-by: Haris Mahmood <[email protected]>
Co-authored-by: Yusha Arif <[email protected]> Haris Mahmood <[email protected]>
@hmahmood24 hmahmood24 deleted the hmahmood-5387-5388 branch February 9, 2023 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Function Reformatting Reformat all Ivy functions in accordance with the latest coding style in the contributor guide Ivy Functional API TensorFlow Frontend Developing the TensorFlow Frontend, checklist triggered by commenting add_frontend_checklist
Projects
None yet
Development

Successfully merging this pull request may close these issues.

selu elu
3 participants