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

fix UT when np >= 1.23 #51466

Merged

Conversation

zoooo0820
Copy link
Contributor

@zoooo0820 zoooo0820 commented Mar 10, 2023

PR types

Others

PR changes

Others

Describe

Pcard-66985

Motivation

In Numpy, the behavior of non-tuple sequence for multidimensional indexing has been changed since 1.23. This incompatible upgrade caused our unittests of indexing to fail, which preventing our CI environment from upgrading to new numpy versions. (see PR #49556)

In a word, currently, the numpy versions are different between CI and user's environment.
This PR makes indexing unit test works well at numpy version >=1.23 and < 1.23, both.

What Numpy changed

In fact, numpy already gave warnings in version <1.23:

__main__:1: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.

For List case, the outermost [] will be treated as tuple () in version less than 1.23, which is used to wrap index elements for multiple axes. And from 1.23, this will be treat as a whole and only works on one axis.

For future Paddle

Whether the paddle behavior in this case will change is still up for debate. Currently, we still keep the same behavior.

@paddle-bot
Copy link

paddle-bot bot commented Mar 10, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@zoooo0820 zoooo0820 changed the title fix UT when np >= 1.24 fix UT when np >= 1.23 Mar 10, 2023
@zoooo0820 zoooo0820 changed the title fix UT when np >= 1.23 fix UT when np >= 1.24 Mar 10, 2023
Comment on lines 962 to 963
# e.g. x[[[0],[1]]] = x[([0],[1])] = x[[0],[1]] (in version < 1.24)
# x[[[0],[1]]] = x[array([[0],[1]])] (in version >= 1.24)
Copy link
Contributor

Choose a reason for hiding this comment

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

it is better to understand that using == instead of =

Copy link
Contributor

Choose a reason for hiding this comment

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

in numpy version >= 1.24, adding the description of behavior of x[tuple([[0],[1]])]), It is easier to see that such modification is working.

@zoooo0820 zoooo0820 changed the title fix UT when np >= 1.24 fix UT when np >= 1.23 Mar 13, 2023
Copy link
Contributor

@jeff41404 jeff41404 left a comment

Choose a reason for hiding this comment

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

LGTM

@jeff41404 jeff41404 merged commit 9658f49 into PaddlePaddle:develop Mar 14, 2023
@zoooo0820 zoooo0820 deleted the fix_UT_with_np_new_listindexing branch March 14, 2023 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants