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

EHN: adding bitwise funtion in paddle tensor.py #17416

Merged
merged 8 commits into from
Jun 23, 2023
Merged

EHN: adding bitwise funtion in paddle tensor.py #17416

merged 8 commits into from
Jun 23, 2023

Conversation

MuhammadNizamani
Copy link
Contributor

@MuhammadNizamani MuhammadNizamani commented Jun 20, 2023

Adding bitwise_xor, Closes #17414

@ivy-leaves ivy-leaves added the Paddle Frontend Developing the Paddle Frontend, checklist triggered by commenting add_frontend_checklist label Jun 20, 2023
@ivy-llc ivy-llc deleted a comment from ivy-leaves Jun 20, 2023
@KareemMAX
Copy link
Contributor

KareemMAX commented Jun 20, 2023

Frontend Task Checklist

IMPORTANT NOTICE 🚨:

The Ivy Docs represent the ground truth for the task descriptions and this checklist should only be used as a supplementary item to aid with the review process.

LEGEND 🗺:

  • ❌ : Check item is not completed.
  • ✅ : Check item is ready for review.
  • 🆘 : Stuck/Doubting implementation (PR author should add comments explaining why).
  • ⏩ : Check is not applicable to function (skip).
  • 🆗 : Check item is implemented and does not require any edits.

CHECKS 📑:

    • 🆗: The function/method definition is not missing any of the original arguments.
    • ⏩: In case the function/method to be implemented is an alias of an existing function/method:
        • ⏩: It is being declared as such by setting fun1 = fun2, rather than being re-implemented from scratch.
        • ⏩: The alias is added to the existing function/method's test in the aliases parameter of handle_frontend_test/handle_frontend_method.
    • 🆗: The naming of the function/method and its arguments exactly matches the original.
    • 🆗: No defined argument is being ignored in the function/method's implementation.
    • ⏩: In special cases where an argument's implementation should be pending due to an incomplete superset of an ivy function:
        • ⏩: A ToDo comment has been added prompting to pass the frontend argument to the ivy function whose behavior is to be extended.
    • ⏩: In case a frontend function is being added:
        • ⏩: It is a composition of ivy functions.
        • ⏩: In case the needed composition is long (using numerous ivy functions), a Missing Function Suggestion issue has been opened to suggest a new ivy function should be added to shorten the frontend implementation.
        • ⏩: @to_ivy_arrays_and_back has been added to the function.
    • 🆗: In case a frontend method is being added:
        • 🆗: It is composed of existing frontend functions or methods.
        • 🆗: If a required frontend function has not yet been added, the method may be implemented as a composition of ivy functions, making sure that:
          • 🆗: @to_ivy_arrays_and_back has been added to the method.
          • 🆗: A ToDo comment has been made prompting to remove the decorator and update the implementation as soon as the missing function has been added.
    • 🆗: The function/method's test has been added (except in the alias case mentioned in <2>):
        • 🆗: All supported arguments are being generated in handle_frontend_test/handle_frontend_method and passed to test_frontend_function/test_frontend_method.
        • 🆗: The argument generation covers all possible supported values. Array sizes, dimensions, and axes adhere to the full supported set of the original function/method.
        • 🆗: The available_dtypes parameter passed to the helper generating the function/method's input array is set to helpers.get_dtypes("valid"). If there are unsupported dtypes that cause the test to fail, they should be handled by adding @with_supported_dtypes/@with_unsupported_dtype to the function/method.
    • 🆗: The PR is not introducing any test failures.
        • 🆗: The lint checks are passing.
        • 🆗: The implemented test is passing for all backends.
    • 🆗: The PR closes a Sub Task issue linked to one of the open frontend ToDo lists.
    • 🆗: The function/method and its test have been added to the correct .py files corresponding to the addressed ToDo list.
    • 🆗: The PR only contains changes relevant to the addressed subtask.

Copy link
Contributor

@KareemMAX KareemMAX left a comment

Choose a reason for hiding this comment

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

Great job @MuhammadNizamani 🚀🚀

I've made a small comment, maybe I might be mistaken about the to_ivy_and_back thing so I'm also asking if there is any internal changes that I'm not aware about. Please look at my comment I'd like to hear your thoughts

"paddle",
)
def bitwise_xor(self, y, out=None, name=None):
y_ivy = _to_ivy_array(y)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there is a specific reason why we use _to_ivy_array? I remember that we used @to_ivy_arrays_and_back() for this conversion but I can't find it in the rest of the file so I'm checking why it isn't there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KareemMAX we are implementing method in Tensor class here and we take our first input using self and by using self where can convert our input into ivy array so no need of @to_ivy_arrays_and_back().
I am using _to_ivy_array because if i use @to_ivy_arrays_and_back() then it will became redundant with this self._ivy_array

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, I got mixed up here

But I'm still curious that in other functions it's calling paddle_frontend like in tensor.multiply() https://github.com/unifyai/ivy/pull/17416/files#diff-4b9f6f2107068e5624a6f5d66bae5dae58c467a34f8c5aad65df3478ce4a5abbR187

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@with_unsupported_dtypes({"2.4.2 and below": ("float16", "bfloat16")}, "paddle")
    def multiply(self, y, name=None):
        return paddle_frontend.multiply(self, y)

The implementation appears to be incorrect based on my understanding. According to my understanding, paddle.tensor.Tensor should receive functions from the backend, rather than the frontend. However, the above function is using paddle.tensor.tensor.math.py to access the backend.

Copy link
Contributor

Choose a reason for hiding this comment

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

paddle_frontend is the ivy implementation of paddle frontend. We are not calling any paddle functions if that is what do you mean.

I've asked @hmahmood24 and he said the following:

since instance methods operate on the instance of the frontend class (paddle.Tensor in this case) which have a _ivy_array attribute that holds the ivy.Array already) and there are only 2 ways we go about writing these instance methods:

Calling ivy.<func> directly
Calling a frontend function of the same functionality paddle_frontend.<func>

That's why I think this implementation is wrong and multiply() is have the correct implementation

Copy link
Contributor Author

@MuhammadNizamani MuhammadNizamani Jun 22, 2023

Choose a reason for hiding this comment

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

@KareemMAX he mentioned that you can also implement like ivy.func so I used that implemention .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KareemMAX done

"paddle",
)
def bitwise_xor(self, y, out=None, name=None):
y_ivy = _to_ivy_array(y)
Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, I got mixed up here

But I'm still curious that in other functions it's calling paddle_frontend like in tensor.multiply() https://github.com/unifyai/ivy/pull/17416/files#diff-4b9f6f2107068e5624a6f5d66bae5dae58c467a34f8c5aad65df3478ce4a5abbR187

@MuhammadNizamani
Copy link
Contributor Author

@KareemMAX sir, when you are going to merge this PR ?

@KareemMAX
Copy link
Contributor

@MuhammadNizamani once we fix the current issue your PR will be good to merge after running tests. Please refer to the latest comment I made on the unresolved conversation

@KareemMAX
Copy link
Contributor

LGTM! merging now

Thanks for your work @MuhammadNizamani 🚀🚀🚀

@KareemMAX KareemMAX merged commit c1906ec into ivy-llc:master Jun 23, 2023
@MuhammadNizamani MuhammadNizamani deleted the bitwise_xor branch June 24, 2023 10:46
Mghrabi pushed a commit to Mghrabi/ivy that referenced this pull request Jun 24, 2023
Co-authored-by: KareemMAX <kreem.morsy@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Paddle Frontend Developing the Paddle Frontend, checklist triggered by commenting add_frontend_checklist
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bitwise_xor
3 participants