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

feat: add broadcast_shape to paddle frontend #22977

Closed
wants to merge 19 commits into from
Closed

feat: add broadcast_shape to paddle frontend #22977

wants to merge 19 commits into from

Conversation

charlie572
Copy link

Related Issue

Close #22919

Checklist

  • Did you add a function?
  • Did you add the tests?
  • Did you follow the steps we provided?

@charlie572
Copy link
Author

The test doesn't pass, and I can't figure out why. It says this:

Expected :([1],)
Actual   :[1]

But when I run the function in the shell, I get the same result from both functions.

In [2]: from ivy.functional.frontends import paddle
In [3]: paddle.broadcast_shape((2, 1, 1), (1, 1, 2))
Out[3]: [2, 1, 2]
In [4]: paddle.broadcast_shape([2, 1, 1], [1, 1, 2])
Out[4]: [2, 1, 2]
In [5]: import paddle
In [6]: paddle.broadcast_shape((2, 1, 1), (1, 1, 2))
Out[6]: [2, 1, 2]
In [7]: paddle.broadcast_shape([2, 1, 1], [1, 1, 2])
Out[7]: [2, 1, 2]

Also, the function is supposed to allow you to input tuples or lists. I'm not sure how to test both of them in hypothesis. Do I have to sample from (list, tuple) with a strategy, and convert the shapes to that type?

@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2023

Thanks for contributing to Ivy! 😊👏
Here are some of the important points from our Contributing Guidelines 📝:
1. Feel free to ignore the run_tests (1), run_tests (2), … jobs, and only look at the display_test_results job. 👀 It contains the following two sections:
- Combined Test Results: This shows the results of all the ivy tests that ran on the PR. ✔️
- New Failures Introduced: This lists the tests that are passing on main, but fail on the PR Fork. Please try to make sure that there are no such tests. 💪
2. The lint / Check formatting / check-formatting tests check for the formatting of your code. 📜 If it fails, please check the exact error message in the logs and fix the same. ⚠️🔧
3. Finally, the test-docstrings / run-docstring-tests check for the changes made in docstrings of the functions. This may be skipped, as well. 📚
Happy coding! 🎉👨‍💻

@ivy-leaves ivy-leaves added the Paddle Frontend Developing the Paddle Frontend, checklist triggered by commenting add_frontend_checklist label Sep 3, 2023
One of the assert statements modified lists in-place, which
messed up the test. Also, the list was modified before being
returned if test_values=False.
@charlie572 charlie572 requested a review from CatB1t as a code owner September 9, 2023 13:48
@charlie572
Copy link
Author

test_frontend_function wasn't checking list return values properly. I've tried to fix it.

When using deepcopy, the type changes, which messes up the test.
You can set shallow=True, and then the array isn't modified.
@charlie572
Copy link
Author

There are some tests failing because of types e.g. test_paddle_is_complex says. "Cannot convert to Paddle dtype. uint16 is not supported by Paddle." But I checked out previous commits, including the commit from just before I started this branch, and they fail for the same reason. Were these tests failing before, or have I set up my environment incorrectly? Also, I looked at the history of the main branch, and none of the commits in the last few weeks pass CI. So I'm confused about which tests I have to fix.

@MahmoudAshraf97
Copy link
Contributor

can you please explain the changes you did in the testing files so @sherry30 can review them?

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

PR Compliance Checks Passed!

@charlie572
Copy link
Author

I've made some changes to test_frontend_function in function_testing.py. I've added shallow=False ton line 775. This is because if ret was a list, then that line would modify it in place, which we don't want. I've also moved a return statement on line 999. This is because the value was being modified before returned, which we don't want, so I moved it to before the part where it is modified.

Copy link
Contributor

@sherry30 sherry30 left a comment

Choose a reason for hiding this comment

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

lets not move the test_values if statement, what we should do instead is tuplify ret as well so both ret and frontend_ret are both in tuples. This will make it easy to loop over the returns in the test function (Since some functions can also return tuples, so its easier to always return a tuple).
The other change looks good

Thanks

@charlie572
Copy link
Author

lets not move the test_values if statement, what we should do instead is tuplify ret as well so both ret and frontend_ret are both in tuples. This will make it easy to loop over the returns in the test function (Since some functions can also return tuples, so its easier to always return a tuple). The other change looks good

Thanks

I've done it. I hope I've understood you correctly.

# Conflicts:
#	ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py
@charlie572
Copy link
Author

Ignore those last two commits. I was looking at the wrong function.

@charlie572
Copy link
Author

test_paddle_tensor_unsqueeze gives the error
AssertionError: returned dtype = bfloat16, ground-truth returned dtype = uint16

I noticed that paddle has a problem with setting the dtype as bfloat16. It doesn't work if you use the dtype argument to the Tensor constructor (it sets the dtype to int64 instead). But it does work if you use astype.

paddle.Tensor(np.arange(10), dtype="bfloat16")
Out[19]: 
Tensor(shape=[10], dtype=int64, place=Place(cpu), stop_gradient=True,
       [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
paddle.Tensor(np.arange(10), dtype="bfloat16").astype("bfloat16")
Out[20]: 
Tensor(shape=[10], dtype=bfloat16, place=Place(cpu), stop_gradient=True,
       [0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])

Maybe this has something to do with the error. Should I try to fix it, or should I open an issue in the original paddle repository? I don't know how ivy converts to backend tensors, so I don't know how to fix it in ivy.

@charlie572 charlie572 changed the title Add broadcast_shape to paddle frontend feat: add broadcast_shape to paddle frontend Sep 28, 2023
@Ivanseven Ivanseven mentioned this pull request Oct 2, 2023
5 tasks
@github-actions
Copy link
Contributor

Thank you for this PR, here is the CI results:


This pull request does not result in any additional test failures. Congratulations!

@MahmoudAshraf97
Copy link
Contributor

Hello, are you still working on this?

@charlie572
Copy link
Author

Yes. Is it ready to merge?

@MahmoudAshraf97
Copy link
Contributor

closing as duplicate of #23574 which was already merged

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.

broadcast_shape
6 participants